diff options
author | Tejun Heo <htejun@gmail.com> | 2007-08-02 08:38:03 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-10-12 17:51:04 -0400 |
commit | 23dc279950a056c33a14d09cf759f5173d41abd9 (patch) | |
tree | 852f8cc24c24988717dbae8f98da999ff27755fa /fs/sysfs/file.c | |
parent | 41fc1c27452e041a18e5141b8203ee0ea72bc483 (diff) |
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 <htejun@gmail.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs/sysfs/file.c')
-rw-r--r-- | fs/sysfs/file.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index ea0e494d7d58..33bb3406dc49 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, | |||
397 | umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG; | 397 | umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG; |
398 | struct sysfs_addrm_cxt acxt; | 398 | struct sysfs_addrm_cxt acxt; |
399 | struct sysfs_dirent *sd; | 399 | struct sysfs_dirent *sd; |
400 | int rc; | ||
400 | 401 | ||
401 | sd = sysfs_new_dirent(attr->name, mode, type); | 402 | sd = sysfs_new_dirent(attr->name, mode, type); |
402 | if (!sd) | 403 | if (!sd) |
@@ -404,16 +405,13 @@ int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, | |||
404 | sd->s_elem.attr.attr = (void *)attr; | 405 | sd->s_elem.attr.attr = (void *)attr; |
405 | 406 | ||
406 | sysfs_addrm_start(&acxt, dir_sd); | 407 | sysfs_addrm_start(&acxt, dir_sd); |
408 | rc = sysfs_add_one(&acxt, sd); | ||
409 | sysfs_addrm_finish(&acxt); | ||
407 | 410 | ||
408 | if (!sysfs_find_dirent(dir_sd, attr->name)) | 411 | if (rc) |
409 | sysfs_add_one(&acxt, sd); | ||
410 | |||
411 | if (!sysfs_addrm_finish(&acxt)) { | ||
412 | sysfs_put(sd); | 412 | sysfs_put(sd); |
413 | return -EEXIST; | ||
414 | } | ||
415 | 413 | ||
416 | return 0; | 414 | return rc; |
417 | } | 415 | } |
418 | 416 | ||
419 | 417 | ||