aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLin Yi <teroincn@163.com>2019-03-20 07:04:56 -0400
committerJohan Hovold <johan@kernel.org>2019-03-20 08:58:42 -0400
commit2908b076f5198d231de62713cb2b633a3a4b95ac (patch)
treea4b033d46b7951c04eafd98b4ebe2caa3a37b406
parentf8df5c2c3e2df5ffaf9fb5503da93d477a8c7db4 (diff)
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: b69578df7e98 ("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>
-rw-r--r--drivers/usb/serial/mos7720.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index fc52ac75fbf6..18110225d506 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -366,8 +366,6 @@ static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport,
366 if (!urbtrack) 366 if (!urbtrack)
367 return -ENOMEM; 367 return -ENOMEM;
368 368
369 kref_get(&mos_parport->ref_count);
370 urbtrack->mos_parport = mos_parport;
371 urbtrack->urb = usb_alloc_urb(0, GFP_ATOMIC); 369 urbtrack->urb = usb_alloc_urb(0, GFP_ATOMIC);
372 if (!urbtrack->urb) { 370 if (!urbtrack->urb) {
373 kfree(urbtrack); 371 kfree(urbtrack);
@@ -388,6 +386,8 @@ static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport,
388 usb_sndctrlpipe(usbdev, 0), 386 usb_sndctrlpipe(usbdev, 0),
389 (unsigned char *)urbtrack->setup, 387 (unsigned char *)urbtrack->setup,
390 NULL, 0, async_complete, urbtrack); 388 NULL, 0, async_complete, urbtrack);
389 kref_get(&mos_parport->ref_count);
390 urbtrack->mos_parport = mos_parport;
391 kref_init(&urbtrack->ref_count); 391 kref_init(&urbtrack->ref_count);
392 INIT_LIST_HEAD(&urbtrack->urblist_entry); 392 INIT_LIST_HEAD(&urbtrack->urblist_entry);
393 393