From: Greg KH <greg@kroah.com>
To: Axel Lin <axel.lin@gmail.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
Greg Kroah-Hartman <gregkh@suse.de>,
Matthew Garrett <mjg@redhat.com>,
Anssi Hannula <anssi.hannula@gmail.com>,
Bernhard Rosenkraenzer <bero@arklinux.org>,
linux-usb@vger.kernel.org
Subject: Re: [PATCH] qcserial: fix a memory leak in qcprobe error path
Date: Mon, 14 Jun 2010 15:33:04 -0700 [thread overview]
Message-ID: <20100614223304.GB31069@kroah.com> (raw)
In-Reply-To: <1275982163.17060.3.camel@mola>
On Tue, Jun 08, 2010 at 03:29:23PM +0800, Axel Lin wrote:
> In current implemtation, the "data" is not kfreed in qcprobe error path.
> This patch moves the memory allocation a little bit latter and only
> allocate memory when no error is detected in previous checking.
Yeah, but it's now pretty messy.
> --- a/drivers/usb/serial/qcserial.c
> +++ b/drivers/usb/serial/qcserial.c
> @@ -109,13 +109,6 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
> ifnum = intf->desc.bInterfaceNumber;
> dbg("This Interface = %d", ifnum);
>
> - data = serial->private = kzalloc(sizeof(struct usb_wwan_intf_private),
> - GFP_KERNEL);
> - if (!data)
> - return -ENOMEM;
> -
> - spin_lock_init(&data->susp_lock);
> -
Moving this to the end is fine.
> @@ -140,7 +135,7 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
> retval);
> retval = -ENODEV;
> }
> - return retval;
> + goto out;
But this doesn't need to be changed, right?
Or this.
> }
> break;
>
> @@ -156,17 +151,26 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
> retval);
> retval = -ENODEV;
> }
> - return retval;
> + goto out;
Or this?
> }
> break;
>
> default:
> dev_err(&serial->dev->dev,
> "unknown number of interfaces: %d\n", nintf);
> - return -ENODEV;
Hm. maybe.
> }
>
> - return retval;
> +out:
> + if (retval)
> + return retval;
> +
> + data = serial->private = kzalloc(sizeof(struct usb_wwan_intf_private),
> + GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + spin_lock_init(&data->susp_lock);
> + return 0;
I guess it's ok, I just don't like doing data initialization on the
"out" path, it's messy.
Care to neaten this up a bit more and resend it? Perhaps just free the
memory on the error path instead of moving it later on?
thanks,
greg k-h
next prev parent reply other threads:[~2010-06-14 22:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-08 7:29 Axel Lin
2010-06-14 22:33 ` Greg KH [this message]
2010-06-16 15:07 ` Axel Lin
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=20100614223304.GB31069@kroah.com \
--to=greg@kroah.com \
--cc=anssi.hannula@gmail.com \
--cc=axel.lin@gmail.com \
--cc=bero@arklinux.org \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mjg@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome