Skip to content

Commit be718b5

Browse files
committed
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
2 parents f66dc72 + cc57c07 commit be718b5

3 files changed

Lines changed: 16 additions & 21 deletions

File tree

‎fs/configfs/dir.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,16 @@ void configfs_unregister_group(struct config_group *group)
17771777
struct dentry *dentry = group->cg_item.ci_dentry;
17781778
struct dentry *parent = group->cg_item.ci_parent->ci_dentry;
17791779

1780+
mutex_lock(&subsys->su_mutex);
1781+
if (!group->cg_item.ci_parent->ci_group) {
1782+
/*
1783+
* The parent has already been unlinked and detached
1784+
* due to a rmdir.
1785+
*/
1786+
goto unlink_group;
1787+
}
1788+
mutex_unlock(&subsys->su_mutex);
1789+
17801790
inode_lock_nested(d_inode(parent), I_MUTEX_PARENT);
17811791
spin_lock(&configfs_dirent_lock);
17821792
configfs_detach_prep(dentry, NULL);
@@ -1791,6 +1801,7 @@ void configfs_unregister_group(struct config_group *group)
17911801
dput(dentry);
17921802

17931803
mutex_lock(&subsys->su_mutex);
1804+
unlink_group:
17941805
unlink_group(group);
17951806
mutex_unlock(&subsys->su_mutex);
17961807
}

‎fs/configfs/item.c‎

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ static void config_item_init(struct config_item *item)
6464
*/
6565
int config_item_set_name(struct config_item *item, const char *fmt, ...)
6666
{
67-
int error = 0;
6867
int limit = CONFIGFS_ITEM_NAME_LEN;
6968
int need;
7069
va_list args;
@@ -79,25 +78,11 @@ int config_item_set_name(struct config_item *item, const char *fmt, ...)
7978
if (need < limit)
8079
name = item->ci_namebuf;
8180
else {
82-
/*
83-
* Need more space? Allocate it and try again
84-
*/
85-
limit = need + 1;
86-
name = kmalloc(limit, GFP_KERNEL);
87-
if (!name) {
88-
error = -ENOMEM;
89-
goto Done;
90-
}
9181
va_start(args, fmt);
92-
need = vsnprintf(name, limit, fmt, args);
82+
name = kvasprintf(GFP_KERNEL, fmt, args);
9383
va_end(args);
94-
95-
/* Still? Give up. */
96-
if (need >= limit) {
97-
kfree(name);
98-
error = -EFAULT;
99-
goto Done;
100-
}
84+
if (!name)
85+
return -EFAULT;
10186
}
10287

10388
/* Free the old name, if necessary. */
@@ -106,8 +91,7 @@ int config_item_set_name(struct config_item *item, const char *fmt, ...)
10691

10792
/* Now, set the new name */
10893
item->ci_name = name;
109-
Done:
110-
return error;
94+
return 0;
11195
}
11296
EXPORT_SYMBOL(config_item_set_name);
11397

‎fs/configfs/symlink.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void fill_item_path(struct config_item * item, char * buffer, int length)
6464

6565
/* back up enough to print this bus id with '/' */
6666
length -= cur;
67-
strncpy(buffer + length,config_item_name(p),cur);
67+
memcpy(buffer + length, config_item_name(p), cur);
6868
*(buffer + --length) = '/';
6969
}
7070
}

0 commit comments

Comments
 (0)