Skip to content

Commit

Permalink
sysfs: cosmetic clean up on node creation failure paths
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Tejun Heo authored and Greg Kroah-Hartman committed Jul 18, 2007
1 parent a1da4df commit 967e35d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
12 changes: 7 additions & 5 deletions fs/sysfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions fs/sysfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
10 changes: 6 additions & 4 deletions fs/sysfs/symlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 967e35d

Please sign in to comment.