From 23dc279950a056c33a14d09cf759f5173d41abd9 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Thu, 2 Aug 2007 21:38:03 +0900 Subject: sysfs: make sysfs_add_one() automatically check for duplicate entry Make sysfs_add_one() check for duplicate entry and return -EEXIST if such entry exists. This simplifies node addition code a bit. This patch doesn't introduce any noticeable behavior change. Signed-off-by: Tejun Heo Acked-by: Cornelia Huck Signed-off-by: Greg Kroah-Hartman --- fs/sysfs/file.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'fs/sysfs/file.c') diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index ea0e494d7d5..33bb3406dc4 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -397,6 +397,7 @@ int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG; struct sysfs_addrm_cxt acxt; struct sysfs_dirent *sd; + int rc; sd = sysfs_new_dirent(attr->name, mode, type); if (!sd) @@ -404,16 +405,13 @@ int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, sd->s_elem.attr.attr = (void *)attr; sysfs_addrm_start(&acxt, dir_sd); + rc = sysfs_add_one(&acxt, sd); + sysfs_addrm_finish(&acxt); - if (!sysfs_find_dirent(dir_sd, attr->name)) - sysfs_add_one(&acxt, sd); - - if (!sysfs_addrm_finish(&acxt)) { + if (rc) sysfs_put(sd); - return -EEXIST; - } - return 0; + return rc; } -- cgit v1.2.3