From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Ma Ke <make24@iscas.ac.cn>
Cc: mchehab@kernel.org, hverkuil@xs4all.nl, viro@zeniv.linux.org.uk,
bartosz.golaszewski@linaro.org, benjamin.gaignard@collabora.com,
hljunggr@cisco.com, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] media: v4l2-dev: fix error handling in __video_register_device()
Date: Thu, 13 Mar 2025 10:10:46 +0000 [thread overview]
Message-ID: <Z9KvJteBVuPE8Hrs@kekkonen.localdomain> (raw)
In-Reply-To: <20250313074318.305556-1-make24@iscas.ac.cn>
Hi Ma,
Thanks for the patch.
On Thu, Mar 13, 2025 at 03:43:18PM +0800, Ma Ke wrote:
> Once device_register() failed, we should call put_device() to
> decrement reference count for cleanup. Or it could cause memory leak.
>
> As comment of device_register() says, 'NOTE: _Never_ directly free
> @dev after calling this function, even if it returned an error! Always
> use put_device() to give up the reference initialized in this function
> instead.'
>
> Found by code review.
>
> Cc: stable@vger.kernel.org
> Fixes: baa057e29b58 ("media: v4l2-dev: use pr_foo() for printing messages")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
> drivers/media/v4l2-core/v4l2-dev.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
> index 5bcaeeba4d09..1619614e96bf 100644
> --- a/drivers/media/v4l2-core/v4l2-dev.c
> +++ b/drivers/media/v4l2-core/v4l2-dev.c
> @@ -1060,6 +1060,7 @@ int __video_register_device(struct video_device *vdev,
> if (ret < 0) {
> mutex_unlock(&videodev_lock);
> pr_err("%s: device_register failed\n", __func__);
> + put_device(&vdev->dev);
Fixing this isn't quite as simple. The release callback is actually set
below so there's no release callback set for this device yet.
> goto cleanup;
> }
> /* Register the release callback that will be called when the last
--
Kind regards,
Sakari Ailus
prev parent reply other threads:[~2025-03-13 10:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-13 7:43 Ma Ke
2025-03-13 10:10 ` Sakari Ailus [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=Z9KvJteBVuPE8Hrs@kekkonen.localdomain \
--to=sakari.ailus@linux.intel.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=benjamin.gaignard@collabora.com \
--cc=hljunggr@cisco.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=make24@iscas.ac.cn \
--cc=mchehab@kernel.org \
--cc=stable@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®