From: Davidlohr Bueso Date: Wed, 11 Jul 2012 12:53:00 +0000 (+0100) Subject: All: Replace malloc+memset with calloc X-Git-Tag: upstream/1.0.21~614 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1572419e943e80883da9341ca65703124938c3d8;p=platform%2Fupstream%2Flibusb.git All: Replace malloc+memset with calloc --- diff --git a/libusb/core.c b/libusb/core.c index e10d808..eccc216 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -1628,12 +1628,11 @@ int API_EXPORTED libusb_init(libusb_context **context) return 0; } - ctx = malloc(sizeof(*ctx)); + ctx = calloc(1, sizeof(*ctx)); if (!ctx) { r = LIBUSB_ERROR_NO_MEM; goto err_unlock; } - memset(ctx, 0, sizeof(*ctx)); #ifdef ENABLE_DEBUG_LOGGING ctx->debug = LIBUSB_LOG_LEVEL_DEBUG; diff --git a/libusb/io.c b/libusb/io.c index d06d375..b8d445c 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -1232,11 +1232,10 @@ struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer( + sizeof(struct libusb_transfer) + (sizeof(struct libusb_iso_packet_descriptor) * iso_packets) + os_alloc_size; - struct usbi_transfer *itransfer = malloc(alloc_size); + struct usbi_transfer *itransfer = calloc(1, alloc_size); if (!itransfer) return NULL; - memset(itransfer, 0, alloc_size); itransfer->num_iso_packets = iso_packets; usbi_mutex_init(&itransfer->lock, NULL); return USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer); diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index a01fff8..dad7536 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -1679,10 +1679,9 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer, usbi_dbg("need %d urbs for new transfer with length %d", num_urbs, transfer->length); alloc_size = num_urbs * sizeof(struct usbfs_urb); - urbs = malloc(alloc_size); + urbs = calloc(1, alloc_size); if (!urbs) return LIBUSB_ERROR_NO_MEM; - memset(urbs, 0, alloc_size); tpriv->urbs = urbs; tpriv->num_urbs = num_urbs; tpriv->num_retired = 0; @@ -1808,10 +1807,9 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer) usbi_dbg("need %d 32k URBs for transfer", num_urbs); alloc_size = num_urbs * sizeof(*urbs); - urbs = malloc(alloc_size); + urbs = calloc(1, alloc_size); if (!urbs) return LIBUSB_ERROR_NO_MEM; - memset(urbs, 0, alloc_size); tpriv->iso_urbs = urbs; tpriv->num_urbs = num_urbs; @@ -1845,12 +1843,11 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer) alloc_size = sizeof(*urb) + (urb_packet_offset * sizeof(struct usbfs_iso_packet_desc)); - urb = malloc(alloc_size); + urb = calloc(1, alloc_size); if (!urb) { free_iso_urbs(tpriv); return LIBUSB_ERROR_NO_MEM; } - memset(urb, 0, alloc_size); urbs[i] = urb; /* populate packet lengths */ @@ -1934,10 +1931,9 @@ static int submit_control_transfer(struct usbi_transfer *itransfer) if (transfer->length - LIBUSB_CONTROL_SETUP_SIZE > MAX_CTRL_BUFFER_LENGTH) return LIBUSB_ERROR_INVALID_PARAM; - urb = malloc(sizeof(struct usbfs_urb)); + urb = calloc(1, sizeof(struct usbfs_urb)); if (!urb) return LIBUSB_ERROR_NO_MEM; - memset(urb, 0, sizeof(struct usbfs_urb)); tpriv->urbs = urb; tpriv->num_urbs = 1; tpriv->reap_action = NORMAL; diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 6fc6748..e6ad1ad 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10537 +#define LIBUSB_NANO 10538