Linux driver-core infrastructure
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: driver-core@lists.linux.dev
Cc: linux-kernel@vger.kernel.org,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	Rajat Jain <rajatja@google.com>, stable <stable@kernel.org>
Subject: Re: [PATCH] sysfs: don't remove existing directory on update failure
Date: Wed, 20 May 2026 15:12:28 +0200	[thread overview]
Message-ID: <2026052018-caption-abdomen-b541@gregkh> (raw)
In-Reply-To: <2026052002-overexert-control-f130@gregkh>

On Wed, May 20, 2026 at 03:06:03PM +0200, Greg Kroah-Hartman wrote:
> When sysfs_update_group() is called for a named group and create_files()
> fails (e.g. -ENOMEM), internal_create_group() calls kernfs_remove(kn) on
> the group directory.  In the update path, kn was obtained via
> kernfs_find_and_get() and refers to a directory that already existed
> before this call.  Removing it silently destroys a sysfs group that the
> caller did not create.
> 
> Only remove the directory if we created it ourselves.  On update failure
> the directory remains as it is left empty by remove_files() inside
> create_files(), but can be repopulated by a retry.
> 
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Danilo Krummrich <dakr@kernel.org>
> Cc: Rajat Jain <rajatja@google.com>
> Fixes: c855cf2759d2 ("sysfs: Fix internal_create_group() for named group updates")
> Cc: stable <stable@kernel.org>
> Assisted-by: gkh_clanker_t1000
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  fs/sysfs/group.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
> index 182e54e575ee..4e1e4f18a166 100644
> --- a/fs/sysfs/group.c
> +++ b/fs/sysfs/group.c
> @@ -188,7 +188,7 @@ static int internal_create_group(struct kobject *kobj, int update,
>  	kernfs_get(kn);
>  	error = create_files(kn, kobj, uid, gid, grp, update);
>  	if (error) {
> -		if (grp->name)
> +		if (grp->name && !update)
>  			kernfs_remove(kn);
>  	}
>  	kernfs_put(kn);
> -- 
> 2.54.0
> 

Ugh, sent this twice, sorry for the noise, only one matters :)

  reply	other threads:[~2026-05-20 13:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-20 13:06 [PATCH] sysfs: don't remove existing directory on update failure Greg Kroah-Hartman
2026-05-20 13:12 ` Greg Kroah-Hartman [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-05-20 13:05 Greg Kroah-Hartman
2026-05-20 13:34 ` Rafael J. Wysocki
2026-05-20 14:45 ` Danilo Krummrich

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=2026052018-caption-abdomen-b541@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=rajatja@google.com \
    --cc=stable@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox