diff options
Diffstat (limited to 'fs/sysfs/symlink.c')
-rw-r--r-- | fs/sysfs/symlink.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c index 7b9c5bfde920..b463f17f6638 100644 --- a/fs/sysfs/symlink.c +++ b/fs/sysfs/symlink.c | |||
@@ -49,30 +49,33 @@ static int sysfs_add_link(struct dentry * parent, const char * name, struct kobj | |||
49 | { | 49 | { |
50 | struct sysfs_dirent * parent_sd = parent->d_fsdata; | 50 | struct sysfs_dirent * parent_sd = parent->d_fsdata; |
51 | struct sysfs_symlink * sl; | 51 | struct sysfs_symlink * sl; |
52 | int error = 0; | 52 | int error; |
53 | 53 | ||
54 | error = -ENOMEM; | 54 | error = -ENOMEM; |
55 | sl = kmalloc(sizeof(*sl), GFP_KERNEL); | 55 | sl = kzalloc(sizeof(*sl), GFP_KERNEL); |
56 | if (!sl) | 56 | if (!sl) |
57 | goto exit1; | 57 | goto err_out; |
58 | 58 | ||
59 | sl->link_name = kmalloc(strlen(name) + 1, GFP_KERNEL); | 59 | sl->link_name = kmalloc(strlen(name) + 1, GFP_KERNEL); |
60 | if (!sl->link_name) | 60 | if (!sl->link_name) |
61 | goto exit2; | 61 | goto err_out; |
62 | 62 | ||
63 | strcpy(sl->link_name, name); | 63 | strcpy(sl->link_name, name); |
64 | sl->target_kobj = kobject_get(target); | 64 | sl->target_kobj = kobject_get(target); |
65 | 65 | ||
66 | error = sysfs_make_dirent(parent_sd, NULL, sl, S_IFLNK|S_IRWXUGO, | 66 | error = sysfs_make_dirent(parent_sd, NULL, sl, S_IFLNK|S_IRWXUGO, |
67 | SYSFS_KOBJ_LINK); | 67 | SYSFS_KOBJ_LINK); |
68 | if (!error) | 68 | if (error) |
69 | return 0; | 69 | goto err_out; |
70 | 70 | ||
71 | kobject_put(target); | 71 | return 0; |
72 | kfree(sl->link_name); | 72 | |
73 | exit2: | 73 | err_out: |
74 | kfree(sl); | 74 | if (sl) { |
75 | exit1: | 75 | kobject_put(sl->target_kobj); |
76 | kfree(sl->link_name); | ||
77 | kfree(sl); | ||
78 | } | ||
76 | return error; | 79 | return error; |
77 | } | 80 | } |
78 | 81 | ||