diff options
author | Akinobu Mita <akinobu.mita@gmail.com> | 2007-07-13 22:03:35 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-07-18 18:49:49 -0400 |
commit | 01da2425f327d7ac673e594bee5655523115970b (patch) | |
tree | 44a33a3fa5e088dfe63e9485823400d12aab3b0b /fs/sysfs | |
parent | 3f8df781fc5f9ee5253a54ba669e1c8872844b86 (diff) |
sysfs: avoid kmem_cache_free(NULL)
kmem_cache_free() with NULL is not allowed. But it may happen
if out of memory error is triggered in sysfs_new_dirent().
This patch fixes that error handling.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs/sysfs')
-rw-r--r-- | fs/sysfs/dir.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index aee966c44aa..2e6775a836f 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 | ||