Commit be718b52 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'configfs-for-4.19' of git://git.infradead.org/users/hch/configfs

Pull configfs updates from Christoph Hellwig:

 - simplify the cide by using kvasprintf (Bart Van Assche)

 - fix a gcc 8 string truncation warning by making the code simpler
   (Guenter Roeck)

 - fix a bug in rmdir() handling (Mike Christie)

* tag 'configfs-for-4.19' of git://git.infradead.org/users/hch/configfs:
  configfs: fix registered group removal
  configfs: replace strncpy with memcpy
  configfs: use kvasprintf() instead of open-coding it
parents f66dc723 cc57c073
...@@ -1777,6 +1777,16 @@ void configfs_unregister_group(struct config_group *group) ...@@ -1777,6 +1777,16 @@ void configfs_unregister_group(struct config_group *group)
struct dentry *dentry = group->cg_item.ci_dentry; struct dentry *dentry = group->cg_item.ci_dentry;
struct dentry *parent = group->cg_item.ci_parent->ci_dentry; struct dentry *parent = group->cg_item.ci_parent->ci_dentry;
mutex_lock(&subsys->su_mutex);
if (!group->cg_item.ci_parent->ci_group) {
/*
* The parent has already been unlinked and detached
* due to a rmdir.
*/
goto unlink_group;
}
mutex_unlock(&subsys->su_mutex);
inode_lock_nested(d_inode(parent), I_MUTEX_PARENT); inode_lock_nested(d_inode(parent), I_MUTEX_PARENT);
spin_lock(&configfs_dirent_lock); spin_lock(&configfs_dirent_lock);
configfs_detach_prep(dentry, NULL); configfs_detach_prep(dentry, NULL);
...@@ -1791,6 +1801,7 @@ void configfs_unregister_group(struct config_group *group) ...@@ -1791,6 +1801,7 @@ void configfs_unregister_group(struct config_group *group)
dput(dentry); dput(dentry);
mutex_lock(&subsys->su_mutex); mutex_lock(&subsys->su_mutex);
unlink_group:
unlink_group(group); unlink_group(group);
mutex_unlock(&subsys->su_mutex); mutex_unlock(&subsys->su_mutex);
} }
......
...@@ -64,7 +64,6 @@ static void config_item_init(struct config_item *item) ...@@ -64,7 +64,6 @@ static void config_item_init(struct config_item *item)
*/ */
int config_item_set_name(struct config_item *item, const char *fmt, ...) int config_item_set_name(struct config_item *item, const char *fmt, ...)
{ {
int error = 0;
int limit = CONFIGFS_ITEM_NAME_LEN; int limit = CONFIGFS_ITEM_NAME_LEN;
int need; int need;
va_list args; va_list args;
...@@ -79,25 +78,11 @@ int config_item_set_name(struct config_item *item, const char *fmt, ...) ...@@ -79,25 +78,11 @@ int config_item_set_name(struct config_item *item, const char *fmt, ...)
if (need < limit) if (need < limit)
name = item->ci_namebuf; name = item->ci_namebuf;
else { else {
/*
* Need more space? Allocate it and try again
*/
limit = need + 1;
name = kmalloc(limit, GFP_KERNEL);
if (!name) {
error = -ENOMEM;
goto Done;
}
va_start(args, fmt); va_start(args, fmt);
need = vsnprintf(name, limit, fmt, args); name = kvasprintf(GFP_KERNEL, fmt, args);
va_end(args); va_end(args);
if (!name)
/* Still? Give up. */ return -EFAULT;
if (need >= limit) {
kfree(name);
error = -EFAULT;
goto Done;
}
} }
/* Free the old name, if necessary. */ /* Free the old name, if necessary. */
...@@ -106,8 +91,7 @@ int config_item_set_name(struct config_item *item, const char *fmt, ...) ...@@ -106,8 +91,7 @@ int config_item_set_name(struct config_item *item, const char *fmt, ...)
/* Now, set the new name */ /* Now, set the new name */
item->ci_name = name; item->ci_name = name;
Done: return 0;
return error;
} }
EXPORT_SYMBOL(config_item_set_name); EXPORT_SYMBOL(config_item_set_name);
......
...@@ -64,7 +64,7 @@ static void fill_item_path(struct config_item * item, char * buffer, int length) ...@@ -64,7 +64,7 @@ static void fill_item_path(struct config_item * item, char * buffer, int length)
/* back up enough to print this bus id with '/' */ /* back up enough to print this bus id with '/' */
length -= cur; length -= cur;
strncpy(buffer + length,config_item_name(p),cur); memcpy(buffer + length, config_item_name(p), cur);
*(buffer + --length) = '/'; *(buffer + --length) = '/';
} }
} }
......
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