Looks good to me, and I also think it makes sense.

Will wait a little while to see if anybody has any objection, and if 
not, I'll try to apply it in the next few days.

Thanks for the patch.

/Pete

On 2012.07.11 13:53, Davidlohr Bueso wrote:
> From: Davidlohr Bueso <d...@gnu.org>
>
> ---
>   libusb/core.c           |    3 +--
>   libusb/io.c             |    3 +--
>   libusb/os/linux_usbfs.c |   12 ++++--------
>   3 files changed, 6 insertions(+), 12 deletions(-)
>
> 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;
>



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to