diff options
Diffstat (limited to 'fs/sysfs/dir.c')
-rw-r--r-- | fs/sysfs/dir.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index aee966c44aac..048e6054c2fd 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c | |||
@@ -361,20 +361,20 @@ static struct dentry_operations sysfs_dentry_ops = { | |||
361 | struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type) | 361 | struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type) |
362 | { | 362 | { |
363 | char *dup_name = NULL; | 363 | char *dup_name = NULL; |
364 | struct sysfs_dirent *sd = NULL; | 364 | struct sysfs_dirent *sd; |
365 | 365 | ||
366 | if (type & SYSFS_COPY_NAME) { | 366 | if (type & SYSFS_COPY_NAME) { |
367 | name = dup_name = kstrdup(name, GFP_KERNEL); | 367 | name = dup_name = kstrdup(name, GFP_KERNEL); |
368 | if (!name) | 368 | if (!name) |
369 | goto err_out; | 369 | return NULL; |
370 | } | 370 | } |
371 | 371 | ||
372 | sd = kmem_cache_zalloc(sysfs_dir_cachep, GFP_KERNEL); | 372 | sd = kmem_cache_zalloc(sysfs_dir_cachep, GFP_KERNEL); |
373 | if (!sd) | 373 | if (!sd) |
374 | goto err_out; | 374 | goto err_out1; |
375 | 375 | ||
376 | if (sysfs_alloc_ino(&sd->s_ino)) | 376 | if (sysfs_alloc_ino(&sd->s_ino)) |
377 | goto err_out; | 377 | goto err_out2; |
378 | 378 | ||
379 | atomic_set(&sd->s_count, 1); | 379 | atomic_set(&sd->s_count, 1); |
380 | atomic_set(&sd->s_active, 0); | 380 | atomic_set(&sd->s_active, 0); |
@@ -386,9 +386,10 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type) | |||
386 | 386 | ||
387 | return sd; | 387 | return sd; |
388 | 388 | ||
389 | err_out: | 389 | err_out2: |
390 | kfree(dup_name); | ||
391 | kmem_cache_free(sysfs_dir_cachep, sd); | 390 | kmem_cache_free(sysfs_dir_cachep, sd); |
391 | err_out1: | ||
392 | kfree(dup_name); | ||
392 | return NULL; | 393 | return NULL; |
393 | } | 394 | } |
394 | 395 | ||
@@ -698,17 +699,19 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd, | |||
698 | 699 | ||
699 | /* link in */ | 700 | /* link in */ |
700 | sysfs_addrm_start(&acxt, parent_sd); | 701 | sysfs_addrm_start(&acxt, parent_sd); |
702 | |||
701 | if (!sysfs_find_dirent(parent_sd, name)) { | 703 | if (!sysfs_find_dirent(parent_sd, name)) { |
702 | sysfs_add_one(&acxt, sd); | 704 | sysfs_add_one(&acxt, sd); |
703 | sysfs_link_sibling(sd); | 705 | sysfs_link_sibling(sd); |
704 | } | 706 | } |
705 | if (sysfs_addrm_finish(&acxt)) { | 707 | |
706 | *p_sd = sd; | 708 | if (!sysfs_addrm_finish(&acxt)) { |
707 | return 0; | 709 | sysfs_put(sd); |
710 | return -EEXIST; | ||
708 | } | 711 | } |
709 | 712 | ||
710 | sysfs_put(sd); | 713 | *p_sd = sd; |
711 | return -EEXIST; | 714 | return 0; |
712 | } | 715 | } |
713 | 716 | ||
714 | int sysfs_create_subdir(struct kobject *kobj, const char *name, | 717 | int sysfs_create_subdir(struct kobject *kobj, const char *name, |