Skip to content

Commit 81ca297

Browse files
andy-shevakpm00
authored andcommitted
relay: use kasprintf() instead of fixed buffer formatting
Improve readability and maintainability by replacing a hard coded string allocation and formatting by using the kasprintf() helper. It also eliminates the GCC compiler warning (with CONFIG_WERROR=y, which is default, it becomes an error: kernel/relay.c:357:42: error: `snprintf' output may be truncated before the last format character [-Werror=format-truncation=] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 48376a4 commit 81ca297

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

kernel/relay.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,9 @@ static struct dentry *relay_create_buf_file(struct rchan *chan,
351351
struct dentry *dentry;
352352
char *tmpname;
353353

354-
tmpname = kzalloc(NAME_MAX + 1, GFP_KERNEL);
354+
tmpname = kasprintf(GFP_KERNEL, "%s%d", chan->base_filename, cpu);
355355
if (!tmpname)
356356
return NULL;
357-
snprintf(tmpname, NAME_MAX, "%s%d", chan->base_filename, cpu);
358357

359358
/* Create file in fs */
360359
dentry = chan->cb->create_buf_file(tmpname, chan->parent,

0 commit comments

Comments
 (0)