Re: [PATCH] usb-serial: fix mos_parport refcount imbalance on error path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx>
> ---
>  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



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux