All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bryan O'Donoghue <bod@kernel.org>
To: Jiawen Liu <1298662399@qq.com>, mchehab@kernel.org
Cc: hverkuil+cisco@kernel.org, kees@kernel.org,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v3] media: as102: drop device reference on probe failure
Date: Tue, 23 Jun 2026 09:59:49 +0100	[thread overview]
Message-ID: <3377aaa2-2f9e-4e01-9f2d-a39cee71a465@kernel.org> (raw)
In-Reply-To: <tencent_82A872B4FEBAE805125BB7D18918D0E25705@qq.com>

On 23/06/2026 09:56, Jiawen Liu wrote:
> as102_usb_probe() initializes the kref and takes a USB device reference
> before registering the USB minor.
> 
> The change named in the Fixes tag avoided freeing as102_dev directly
> after usb_register_dev() succeeds, because userspace can open the minor
> before a later probe failure and hold an extra kref until release.
> 
> However, the stream-allocation and DVB-registration failure paths now
> deregister the USB minor and return without dropping the probe path
> initial kref. That leaves the USB device reference held by as102_dev
> leaked.
> 
> Drop the initial reference with kref_put() after usb_deregister_dev(). If
> no userspace file is open, as102_usb_release() releases the USB device
> and frees as102_dev immediately. If a file is open, the final free is
> deferred until the last file release drops the remaining kref.
> 
> Fixes: 8bd29dbe03fc ("media: as102: fix to not free memory after the device is registered in as102_usb_probe()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jiawen Liu <1298662399@qq.com>
> ---
> Changes in v3:
> - Collapse the error labels so failed_stream falls through to the common
>    kref_put() return path, as suggested by Bryan O'Donoghue.
> 
> Changes in v2:
> - Add Fixes and Cc stable tags.
> - Clarify why the probe failure path must drop the initial kref rather
>    than free as102_dev directly.
> 
>   drivers/media/usb/as102/as102_usb_drv.c | 5 +----
>   1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/media/usb/as102/as102_usb_drv.c b/drivers/media/usb/as102/as102_usb_drv.c
> index a11024451ceb..2e6c9b50ee5f 100644
> --- a/drivers/media/usb/as102/as102_usb_drv.c
> +++ b/drivers/media/usb/as102/as102_usb_drv.c
> @@ -403,13 +403,10 @@ static int as102_usb_probe(struct usb_interface *intf,
>   failed_dvb:
>   	as102_free_usb_stream_buffer(as102_dev);
>   failed_stream:
> -	usb_set_intfdata(intf, NULL);
>   	usb_deregister_dev(intf, &as102_usb_class_driver);
> -	return ret;
>   failed:
> -	usb_put_dev(as102_dev->bus_adap.usb_dev);
>   	usb_set_intfdata(intf, NULL);
> -	kfree(as102_dev);
> +	kref_put(&as102_dev->kref, as102_usb_release);
>   	return ret;
>   }
> 
> 
> base-commit: 9e7e6633458362db72427b48effad8d759131c35
> --
> 2.34.1
> 

Reviewed-by: Bryan O'Donoghue <bod@kernel.org>

---
bod

      reply	other threads:[~2026-06-23  9:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <vQaKSTkXJRhk3WSQgTuoKGXJ4g3L1p3JxzdvdE5MqQdJqJrUwJiY7XpUOlLkqsKQOBBrC1jvbrxbkGMkmhZJQQ==@protonmail.internalid>
2026-06-23  8:56 ` [PATCH v3] media: as102: drop device reference on probe failure Jiawen Liu
2026-06-23  8:59   ` Bryan O'Donoghue [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3377aaa2-2f9e-4e01-9f2d-a39cee71a465@kernel.org \
    --to=bod@kernel.org \
    --cc=1298662399@qq.com \
    --cc=hverkuil+cisco@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.