From: Johan Hovold <johan@kernel.org>
To: Lin Yi <teroincn@163.com>
Cc: linux-usb@vger.kernel.org, gregkh@linuxfoundation.org,
zhiyunq@cs.ucr.edu, csong@cs.ucr.edu, ljian236@gmail.com,
yiqiuping@gmail.com
Subject: usb-serial: fix mos_parport refcount imbalance on error path
Date: Wed, 20 Mar 2019 10:04:58 +0100 [thread overview]
Message-ID: <20190320090458.GD15782@localhost> (raw)
On Wed, Mar 20, 2019 at 10:29:16AM +0800, Lin Yi wrote:
> write_parport_ref_nonblock increase mos_parport refcount without
> decrease it when return -ENOMEM code, so need a decrement before function
> return -ENOMEM.
Good catch!
Your patch looks good, but wouldn't it be better to move the kref_get()
(and mos_parport assignment) to the end of the urbtrack initialisation
instead?
That way you wouldn't have to add any kref_puts() at all.
> Signed-off-by: Lin Yi <teroincn@163.com>
> ---
> drivers/usb/serial/mos7720.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
> index fc52ac7..6abb335 100644
> --- a/drivers/usb/serial/mos7720.c
> +++ b/drivers/usb/serial/mos7720.c
> @@ -371,12 +371,14 @@ static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport,
> urbtrack->urb = usb_alloc_urb(0, GFP_ATOMIC);
> if (!urbtrack->urb) {
> kfree(urbtrack);
> + kref_put(&mos_parport->ref_count, destroy_mos_parport);
> return -ENOMEM;
> }
> urbtrack->setup = kmalloc(sizeof(*urbtrack->setup), GFP_ATOMIC);
> if (!urbtrack->setup) {
> usb_free_urb(urbtrack->urb);
> kfree(urbtrack);
> + kref_put(&mos_parport->ref_count, destroy_mos_parport);
> return -ENOMEM;
> }
> urbtrack->setup->bRequestType = (__u8)0x40;
Thanks,
Johan
next reply other threads:[~2019-03-20 9:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-20 9:04 Johan Hovold [this message]
-- strict thread matches above, loose matches on Subject: below --
2019-03-20 9:05 usb-serial: fix mos_parport refcount imbalance on error path Greg Kroah-Hartman
2019-03-20 8:59 Jian Liu/Gmail
2019-03-20 2:29 Lin Yi
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=20190320090458.GD15782@localhost \
--to=johan@kernel.org \
--cc=csong@cs.ucr.edu \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=ljian236@gmail.com \
--cc=teroincn@163.com \
--cc=yiqiuping@gmail.com \
--cc=zhiyunq@cs.ucr.edu \
/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.