Skip to content

Commit 2908b07

Browse files
WannaTenjhovold
authored andcommitted
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: Lin Yi <teroincn@163.com> Fixes: b69578d ("USB: usbserial: mos7720: add support for parallel port on moschip 7715") Cc: stable <stable@vger.kernel.org> # 2.6.35 Signed-off-by: Johan Hovold <johan@kernel.org>
1 parent f8df5c2 commit 2908b07

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/usb/serial/mos7720.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,6 @@ static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport,
366366
if (!urbtrack)
367367
return -ENOMEM;
368368

369-
kref_get(&mos_parport->ref_count);
370-
urbtrack->mos_parport = mos_parport;
371369
urbtrack->urb = usb_alloc_urb(0, GFP_ATOMIC);
372370
if (!urbtrack->urb) {
373371
kfree(urbtrack);
@@ -388,6 +386,8 @@ static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport,
388386
usb_sndctrlpipe(usbdev, 0),
389387
(unsigned char *)urbtrack->setup,
390388
NULL, 0, async_complete, urbtrack);
389+
kref_get(&mos_parport->ref_count);
390+
urbtrack->mos_parport = mos_parport;
391391
kref_init(&urbtrack->ref_count);
392392
INIT_LIST_HEAD(&urbtrack->urblist_entry);
393393

0 commit comments

Comments
 (0)