diff options
Diffstat (limited to 'fs/sysfs/dir.c')
-rw-r--r-- | fs/sysfs/dir.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index cfd290d3d6b1..bea1f4c02b9b 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c | |||
@@ -50,6 +50,32 @@ static struct sysfs_dirent * sysfs_new_dirent(struct sysfs_dirent * parent_sd, | |||
50 | return sd; | 50 | return sd; |
51 | } | 51 | } |
52 | 52 | ||
53 | /** | ||
54 | * | ||
55 | * Return -EEXIST if there is already a sysfs element with the same name for | ||
56 | * the same parent. | ||
57 | * | ||
58 | * called with parent inode's i_mutex held | ||
59 | */ | ||
60 | int sysfs_dirent_exist(struct sysfs_dirent *parent_sd, | ||
61 | const unsigned char *new) | ||
62 | { | ||
63 | struct sysfs_dirent * sd; | ||
64 | |||
65 | list_for_each_entry(sd, &parent_sd->s_children, s_sibling) { | ||
66 | if (sd->s_element) { | ||
67 | const unsigned char *existing = sysfs_get_name(sd); | ||
68 | if (strcmp(existing, new)) | ||
69 | continue; | ||
70 | else | ||
71 | return -EEXIST; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | |||
53 | int sysfs_make_dirent(struct sysfs_dirent * parent_sd, struct dentry * dentry, | 79 | int sysfs_make_dirent(struct sysfs_dirent * parent_sd, struct dentry * dentry, |
54 | void * element, umode_t mode, int type) | 80 | void * element, umode_t mode, int type) |
55 | { | 81 | { |
@@ -102,7 +128,11 @@ static int create_dir(struct kobject * k, struct dentry * p, | |||
102 | mutex_lock(&p->d_inode->i_mutex); | 128 | mutex_lock(&p->d_inode->i_mutex); |
103 | *d = lookup_one_len(n, p, strlen(n)); | 129 | *d = lookup_one_len(n, p, strlen(n)); |
104 | if (!IS_ERR(*d)) { | 130 | if (!IS_ERR(*d)) { |
105 | error = sysfs_make_dirent(p->d_fsdata, *d, k, mode, SYSFS_DIR); | 131 | if (sysfs_dirent_exist(p->d_fsdata, n)) |
132 | error = -EEXIST; | ||
133 | else | ||
134 | error = sysfs_make_dirent(p->d_fsdata, *d, k, mode, | ||
135 | SYSFS_DIR); | ||
106 | if (!error) { | 136 | if (!error) { |
107 | error = sysfs_create(*d, mode, init_dir); | 137 | error = sysfs_create(*d, mode, init_dir); |
108 | if (!error) { | 138 | if (!error) { |