All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@suse.de>
To: linux-kernel@vger.kernel.org
Cc: Tejun Heo <htejun@gmail.com>,
	Gabriel C <nix.or.die@googlemail.com>,
	Miles Lane <miles.lane@gmail.com>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH 14/14] sysfs: cosmetic clean up on node creation failure paths
Date: Wed, 18 Jul 2007 16:25:50 -0700	[thread overview]
Message-ID: <11848012062759-git-send-email-gregkh@suse.de> (raw)
In-Reply-To: <11848012023373-git-send-email-gregkh@suse.de>

From: Tejun Heo <htejun@gmail.com>

Node addition failure is detected by testing return value of
sysfs_addfm_finish() which returns the number of added and removed
nodes.  As the function is called as the last step of addition right
on top of error handling block, the if blocks looked like the
following.

	if (sysfs_addrm_finish(&acxt))
		success handling, usually return;
	/* fall through to error handling */

This is the opposite of usual convention in sysfs and makes the code
difficult to understand.  This patch inverts the test and makes those
blocks look more like others.

Signed-off-by: Tejun Heo <htejun@gmail.com>
Cc: Gabriel C <nix.or.die@googlemail.com>
Cc: Miles Lane <miles.lane@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 fs/sysfs/dir.c     |   12 +++++++-----
 fs/sysfs/file.c    |    9 +++++----
 fs/sysfs/symlink.c |   10 ++++++----
 3 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 2e6775a..048e605 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -699,17 +699,19 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
 
 	/* link in */
 	sysfs_addrm_start(&acxt, parent_sd);
+
 	if (!sysfs_find_dirent(parent_sd, name)) {
 		sysfs_add_one(&acxt, sd);
 		sysfs_link_sibling(sd);
 	}
-	if (sysfs_addrm_finish(&acxt)) {
-		*p_sd = sd;
-		return 0;
+
+	if (!sysfs_addrm_finish(&acxt)) {
+		sysfs_put(sd);
+		return -EEXIST;
 	}
 
-	sysfs_put(sd);
-	return -EEXIST;
+	*p_sd = sd;
+	return 0;
 }
 
 int sysfs_create_subdir(struct kobject *kobj, const char *name,
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index cc49799..3e1cc06 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -410,11 +410,12 @@ int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,
 		sysfs_link_sibling(sd);
 	}
 
-	if (sysfs_addrm_finish(&acxt))
-		return 0;
+	if (!sysfs_addrm_finish(&acxt)) {
+		sysfs_put(sd);
+		return -EEXIST;
+	}
 
-	sysfs_put(sd);
-	return -EEXIST;
+	return 0;
 }
 
 
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index d056e96..4ce687f 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -97,11 +97,13 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char
 		sysfs_link_sibling(sd);
 	}
 
-	if (sysfs_addrm_finish(&acxt))
-		return 0;
+	if (!sysfs_addrm_finish(&acxt)) {
+		error = -EEXIST;
+		goto out_put;
+	}
+
+	return 0;
 
-	error = -EEXIST;
-	/* fall through */
  out_put:
 	sysfs_put(target_sd);
 	sysfs_put(sd);
-- 
1.5.2.2


      reply	other threads:[~2007-07-18 23:33 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-18 23:24 [GIT PATCH] more sysfs and driver core patches for 2.6.22 Greg KH
2007-07-18 23:25 ` [PATCH 01/14] debugfs: remove rmdir() non-empty complaint Greg Kroah-Hartman
2007-07-18 23:25   ` [PATCH 02/14] Driver core: accept all valid action-strings in uevent-trigger Greg Kroah-Hartman
2007-07-18 23:25     ` [PATCH 03/14] PM: Remove deprecated sysfs files Greg Kroah-Hartman
2007-07-18 23:25       ` [PATCH 04/14] PM: remove deprecated dpm_runtime_* routines Greg Kroah-Hartman
2007-07-18 23:25         ` [PATCH 05/14] sysfs: avoid kmem_cache_free(NULL) Greg Kroah-Hartman
2007-07-18 23:25           ` [PATCH 06/14] Documentation fix devres.txt: lib/iomap.c -> lib/devres.c Greg Kroah-Hartman
2007-07-18 23:25             ` [PATCH 07/14] sysfs: fix sysfs root inode nlink accounting Greg Kroah-Hartman
2007-07-18 23:25               ` [PATCH 08/14] sysfs: make sysfs_init_inode() static Greg Kroah-Hartman
2007-07-18 23:25                 ` [PATCH 09/14] dev_vdbg(), available with -DVERBOSE_DEBUG Greg Kroah-Hartman
2007-07-18 23:25                   ` [PATCH 10/14] dev_vdbg() documentation Greg Kroah-Hartman
2007-07-18 23:25                     ` [PATCH 11/14] HOWTO: Add the knwon_regression URI to the documentation Greg Kroah-Hartman
2007-07-18 23:25                       ` [PATCH 12/14] Driver core: check return code of sysfs_create_link() Greg Kroah-Hartman
2007-07-18 23:25                         ` [PATCH 13/14] sysfs: kill an extra put in sysfs_create_link() failure path Greg Kroah-Hartman
2007-07-18 23:25                           ` Greg Kroah-Hartman [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=11848012062759-git-send-email-gregkh@suse.de \
    --to=gregkh@suse.de \
    --cc=htejun@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miles.lane@gmail.com \
    --cc=nix.or.die@googlemail.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 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.