Commit 2908b076 authored by Lin Yi's avatar Lin Yi Committed by Johan Hovold

USB: serial: mos7720: fix mos_parport refcount imbalance on error path

The write_parport_reg_nonblock() helper takes a reference to the struct
mos_parport, but failed to release it in a couple of error paths after
allocation failures, leading to a memory leak.

Johan said that move the kref_get() and mos_parport assignment to the
end of urbtrack initialisation is a better way, so move it. and
mos_parport do not used until urbtrack initialisation.
Signed-off-by: default avatarLin Yi <teroincn@163.com>
Fixes: b69578df ("USB: usbserial: mos7720: add support for parallel port on moschip 7715")
Cc: stable <stable@vger.kernel.org>     # 2.6.35
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
parent f8df5c2c
...@@ -366,8 +366,6 @@ static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport, ...@@ -366,8 +366,6 @@ static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport,
if (!urbtrack) if (!urbtrack)
return -ENOMEM; return -ENOMEM;
kref_get(&mos_parport->ref_count);
urbtrack->mos_parport = mos_parport;
urbtrack->urb = usb_alloc_urb(0, GFP_ATOMIC); urbtrack->urb = usb_alloc_urb(0, GFP_ATOMIC);
if (!urbtrack->urb) { if (!urbtrack->urb) {
kfree(urbtrack); kfree(urbtrack);
...@@ -388,6 +386,8 @@ static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport, ...@@ -388,6 +386,8 @@ static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport,
usb_sndctrlpipe(usbdev, 0), usb_sndctrlpipe(usbdev, 0),
(unsigned char *)urbtrack->setup, (unsigned char *)urbtrack->setup,
NULL, 0, async_complete, urbtrack); NULL, 0, async_complete, urbtrack);
kref_get(&mos_parport->ref_count);
urbtrack->mos_parport = mos_parport;
kref_init(&urbtrack->ref_count); kref_init(&urbtrack->ref_count);
INIT_LIST_HEAD(&urbtrack->urblist_entry); INIT_LIST_HEAD(&urbtrack->urblist_entry);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment