Re: [PATCH v2 1/2] fs/resctrl: Avoid extra call to strlen() in schemata_list_add()
From: Reinette Chatre
Date: Thu Sep 03 2026 - 12:41:16 EST
Dear x86 maintainers,
Could you please consider both cleanups in this series for inclusion?
Thank you very much.
Reinette
On 8/21/26 1:11 AM, Dmitry Antipov wrote:
> 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@xxxxxxxxx>
> ---
> 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