All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Muhammad Falak R Wani <falakreyaz@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: core: driver: Use kmalloc_array
Date: Sun, 23 Aug 2015 11:58:58 -0700	[thread overview]
Message-ID: <1440356338.2670.9.camel@perches.com> (raw)
In-Reply-To: <1440355729-20536-1-git-send-email-falakreyaz@gmail.com>

On Mon, 2015-08-24 at 00:18 +0530, Muhammad Falak R Wani wrote:
> This patch introduces the use of function kmalloc_array(), instead
> of using kmalloc(), for allocating memory for an array and removes
> the corresponding call to kmalloc().
[]
> diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
[]
> @@ -416,7 +416,7 @@ static int usb_unbind_interface(struct device *dev)
>  		if (ep->streams == 0)
>  			continue;
>  		if (j == 0) {
> -			eps = kmalloc(USB_MAXENDPOINTS * sizeof(void *),
> +			eps = kmalloc_array(USB_MAXENDPOINTS, sizeof(void *),
>  				      GFP_KERNEL);
>  			if (!eps) {
>  				dev_warn(dev, "oom, leaking streams\n");

Allocations like this really don't need to use
kmalloc_array as it's unlikely that USB_MAXENDPOINTS
is very large.

If you are going to do this, it'd be nicer to keep
the parenthesis alignment and likely also better to
remove the dev_warn for a memory leak.



      reply	other threads:[~2015-08-23 18:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-23 18:48 [PATCH] usb: core: driver: Use kmalloc_array Muhammad Falak R Wani
2015-08-23 18:58 ` Joe Perches [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1440356338.2670.9.camel@perches.com \
    --to=joe@perches.com \
    --cc=falakreyaz@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.