usb-serial: fix mos_parport refcount imbalance on error path
Quoted 3 lines · Lin Yi
write_parport_ref_nonblockincreasemos_parportrefcount without decrease it when return-ENOMEMcode, 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.
Quoted 14 lines
Signed-off-by Lin Yi <[email protected]>--- drivers/usb/serial/mos7720.c | 2 ++ 1 file changed, 2 insertions(+)drivers/usb/serial/mos7720.c +1
-0@@ -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);
drivers/usb/serial/mos7720.c static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport, · line 384
Quoted 10 lines
drivers/usb/serial/mos7720.c +1
-0return -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