Commit 01da2425 authored by Akinobu Mita's avatar Akinobu Mita Committed by Greg Kroah-Hartman

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: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 3f8df781
...@@ -361,20 +361,20 @@ static struct dentry_operations sysfs_dentry_ops = { ...@@ -361,20 +361,20 @@ static struct dentry_operations sysfs_dentry_ops = {
struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type) struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type)
{ {
char *dup_name = NULL; char *dup_name = NULL;
struct sysfs_dirent *sd = NULL; struct sysfs_dirent *sd;
if (type & SYSFS_COPY_NAME) { if (type & SYSFS_COPY_NAME) {
name = dup_name = kstrdup(name, GFP_KERNEL); name = dup_name = kstrdup(name, GFP_KERNEL);
if (!name) if (!name)
goto err_out; return NULL;
} }
sd = kmem_cache_zalloc(sysfs_dir_cachep, GFP_KERNEL); sd = kmem_cache_zalloc(sysfs_dir_cachep, GFP_KERNEL);
if (!sd) if (!sd)
goto err_out; goto err_out1;
if (sysfs_alloc_ino(&sd->s_ino)) if (sysfs_alloc_ino(&sd->s_ino))
goto err_out; goto err_out2;
atomic_set(&sd->s_count, 1); atomic_set(&sd->s_count, 1);
atomic_set(&sd->s_active, 0); 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,9 +386,10 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type)
return sd; return sd;
err_out: err_out2:
kfree(dup_name);
kmem_cache_free(sysfs_dir_cachep, sd); kmem_cache_free(sysfs_dir_cachep, sd);
err_out1:
kfree(dup_name);
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment