From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Zijun Hu <zijun_hu@icloud.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
Benjamin Thery <benjamin.thery@bull.net>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Greg Kroah-Hartman <gregkh@suse.de>,
linux-kernel@vger.kernel.org, Zijun Hu <quic_zijuhu@quicinc.com>
Subject: Re: [PATCH] driver core: Fix error handling in driver API device_rename()
Date: Wed, 17 Jul 2024 17:03:37 +0200 [thread overview]
Message-ID: <2024071756-uproot-relieve-6e27@gregkh> (raw)
In-Reply-To: <20240717-device_rename_fix-v1-1-54d85024518f@quicinc.com>
On Wed, Jul 17, 2024 at 10:50:05PM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
>
> Call failure of device_rename(@dev, @new_name) maybe unexpectedly change
> link name within @dev's class directory to @new_name, fixed by correcting
> error handling for the API.
I'm sorry, but I don't understand the text here, what exactly are you
doing?
> Fixes: f349cf34731c ("driver core: Implement ns directory support for device classes.")
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
> drivers/base/core.c | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 2b4c0624b704..a05b7186cf33 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -4512,9 +4512,11 @@ EXPORT_SYMBOL_GPL(device_destroy);
> */
> int device_rename(struct device *dev, const char *new_name)
> {
> + struct subsys_private *sp = NULL;
> struct kobject *kobj = &dev->kobj;
> char *old_device_name = NULL;
> int error;
> + bool is_link_renamed = false;
>
> dev = get_device(dev);
> if (!dev)
> @@ -4529,7 +4531,7 @@ int device_rename(struct device *dev, const char *new_name)
> }
>
> if (dev->class) {
> - struct subsys_private *sp = class_to_subsys(dev->class);
> + sp = class_to_subsys(dev->class);
>
> if (!sp) {
> error = -EINVAL;
> @@ -4537,17 +4539,20 @@ int device_rename(struct device *dev, const char *new_name)
> }
>
> error = sysfs_rename_link_ns(&sp->subsys.kobj, kobj, old_device_name,
> - new_name, kobject_namespace(kobj));
> - subsys_put(sp);
> + new_name, kobject_namespace(kobj));
Why did you change the indentation here?
> if (error)
> goto out;
> +
> + is_link_renamed = true;
> }
>
> error = kobject_rename(kobj, new_name);
> - if (error)
> - goto out;
> -
> out:
> + if (error && is_link_renamed)
> + sysfs_rename_link_ns(&sp->subsys.kobj, kobj, new_name,
> + old_device_name, kobject_namespace(kobj));
> + subsys_put(sp);
How was this found? What in-kernel code causes this problem? And how
was this tested?
thanks,
greg k-h
next prev parent reply other threads:[~2024-07-17 15:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-17 14:50 [PATCH] driver core: Fix error handling in driver API device_rename() Zijun Hu
2024-07-17 15:03 ` Greg Kroah-Hartman [this message]
2024-07-19 12:42 ` Zijun Hu
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=2024071756-uproot-relieve-6e27@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=benjamin.thery@bull.net \
--cc=ebiederm@xmission.com \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=quic_zijuhu@quicinc.com \
--cc=rafael@kernel.org \
--cc=zijun_hu@icloud.com \
/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