[PATCH v2 1/2] fs/resctrl: Avoid extra call to strlen() in schemata_list_add()
Dmitry Antipov <[email protected]>
| Newsgroups | org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
After passing an overflow check, it's safe to assume that snprintf() returns the number of characters emitted. So drop the unnecessary call to strlen(). Signed-off-by: Dmitry Antipov <[email protected]> --- v2: adjust title and commit message (Reinette) --- fs/resctrl/rdtgroup.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 5dcbb0a964e8..68be9b903ac6 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2858,7 +2858,7 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type { struct resctrl_schema *s; const char *suffix = ""; - int ret, cl; + int cl; s = kzalloc_obj(*s); if (!s) @@ -2882,14 +2882,12 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type break; } - ret = snprintf(s->name, sizeof(s->name), "%s%s", r->name, suffix); - if (ret >= sizeof(s->name)) { + cl = snprintf(s->name, sizeof(s->name), "%s%s", r->name, suffix); + if (cl >= sizeof(s->name)) { kfree(s); return -EINVAL; } - cl = strlen(s->name); - /* * If CDP is supported by this resource, but not enabled, * include the suffix. This ensures the tabular format of the -- 2.55.0