[tip: x86/cache] fs/resctrl: Avoid extra call to strlen() in schemata_list_add()

tip-bot2 for Dmitry Antipov posted 1 patch 1 week ago
fs/resctrl/rdtgroup.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
[tip: x86/cache] fs/resctrl: Avoid extra call to strlen() in schemata_list_add()
Posted by tip-bot2 for Dmitry Antipov 1 week ago
The following commit has been merged into the x86/cache branch of tip:

Commit-ID:     4b31656d917c46c6d9f874162ede4f54b2a5959f
Gitweb:        https://git.kernel.org/tip/4b31656d917c46c6d9f874162ede4f54b2a5959f
Author:        Dmitry Antipov <dmantipov@yandex.ru>
AuthorDate:    Fri, 21 Aug 2026 11:11:27 +03:00
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Thu, 17 Sep 2026 10:41:53 -07:00

fs/resctrl: Avoid extra call to strlen() in schemata_list_add()

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 <dmantipov@yandex.ru>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Link: https://patch.msgid.link/20260821081128.19242-1-dmantipov@yandex.ru
---
 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 5dcbb0a..68be9b9 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