mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 "Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	 Johan Hovold <johan@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	 Fernando Fernandez Mancera <fmancera@suse.de>
Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH 4/4] sysfs: simplify error handling in create_files()
Date: Mon, 16 Nov 2026 01:42:56 -0800	[thread overview]
Message-ID: <20261116-sysfs-group-invisible-v1-4-94cd173a7d9a@gmail.com> (raw)
In-Reply-To: <20261116-sysfs-group-invisible-v1-0-94cd173a7d9a@gmail.com>

Both attribute creation loops in create_files() duplicate the same error
cleanup pattern by breaking out of the loop and checking the error
status afterward to remove created files.

Consolidate error cleanup into a single exit path that removes the
group's files and returns the error, returning 0 directly on success.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 fs/sysfs/group.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 699c2f9e8926..b90ba546dcda 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -51,10 +51,10 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj,
 {
 	struct attribute *const *attr;
 	const struct bin_attribute *const *bin_attr;
-	int error = 0, i;
+	int error, i;
 
 	if (grp->attrs) {
-		for (i = 0, attr = grp->attrs; *attr && !error; i++, attr++) {
+		for (i = 0, attr = grp->attrs; *attr; i++, attr++) {
 			umode_t mode = (*attr)->mode;
 
 			/*
@@ -81,11 +81,7 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj,
 			error = sysfs_add_file_mode_ns(parent, *attr, mode, uid,
 						       gid, NULL);
 			if (unlikely(error))
-				break;
-		}
-		if (error) {
-			remove_files(parent, grp);
-			goto exit;
+				goto err_remove_files;
 		}
 	}
 
@@ -113,13 +109,15 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj,
 			error = sysfs_add_bin_file_mode_ns(parent, *bin_attr,
 							   mode, size, uid, gid,
 							   NULL);
-			if (error)
-				break;
+			if (unlikely(error))
+				goto err_remove_files;
 		}
-		if (error)
-			remove_files(parent, grp);
 	}
-exit:
+
+	return 0;
+
+err_remove_files:
+	remove_files(parent, grp);
 	return error;
 }
 

-- 
2.56.0.679.gc527c65306-goog


      parent reply	other threads:[~2026-11-16  9:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  9:42 [PATCH 0/4] sysfs: support SYSFS_GROUP_INVISIBLE for unnamed groups and ownership updates Dmitry Torokhov
2026-11-16  9:42 ` [PATCH 1/4] sysfs: check for SYSFS_GROUP_INVISIBLE using equality comparison Dmitry Torokhov
2026-11-16  9:42 ` [PATCH 2/4] sysfs: check group visibility upfront in sysfs_group_change_owner() Dmitry Torokhov
2026-11-16  9:42 ` [PATCH 3/4] sysfs: support SYSFS_GROUP_INVISIBLE for unnamed attribute groups Dmitry Torokhov
2026-11-16  9:42 ` Dmitry Torokhov [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=20261116-sysfs-group-invisible-v1-4-94cd173a7d9a@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=fmancera@suse.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@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

all inboxes | Powered by JetHome®