The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2 1/2] fs/resctrl: Avoid extra call to strlen() in schemata_list_add()
@ 2026-08-21  8:11 Dmitry Antipov
  2026-08-21  8:11 ` [PATCH v2 2/2] fs/resctrl: Simplify pseudo_lock_measure_trigger() Dmitry Antipov
  2026-08-25 18:25 ` [PATCH v2 1/2] fs/resctrl: Avoid extra call to strlen() in schemata_list_add() Reinette Chatre
  0 siblings, 2 replies; 4+ messages in thread
From: Dmitry Antipov @ 2026-08-21  8:11 UTC (permalink / raw)
  To: Reinette Chatre
  Cc: Tony Luck, Dave Martin, James Morse, Babu Moger, x86,
	linux-kernel, Dmitry Antipov

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>
---
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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] fs/resctrl: Simplify pseudo_lock_measure_trigger()
  2026-08-21  8:11 [PATCH v2 1/2] fs/resctrl: Avoid extra call to strlen() in schemata_list_add() Dmitry Antipov
@ 2026-08-21  8:11 ` Dmitry Antipov
  2026-08-25 18:25   ` Reinette Chatre
  2026-08-25 18:25 ` [PATCH v2 1/2] fs/resctrl: Avoid extra call to strlen() in schemata_list_add() Reinette Chatre
  1 sibling, 1 reply; 4+ messages in thread
From: Dmitry Antipov @ 2026-08-21  8:11 UTC (permalink / raw)
  To: Reinette Chatre
  Cc: Tony Luck, Dave Martin, James Morse, Babu Moger, x86,
	linux-kernel, Dmitry Antipov

Use convenient kstrtoint_from_user() to simplify pseudo_lock_measure_trigger().

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
v2: adjust title and commit message (Reinette)
---
 fs/resctrl/pseudo_lock.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/fs/resctrl/pseudo_lock.c b/fs/resctrl/pseudo_lock.c
index dea2b4bf966f..56ab63f19bad 100644
--- a/fs/resctrl/pseudo_lock.c
+++ b/fs/resctrl/pseudo_lock.c
@@ -750,17 +750,10 @@ static ssize_t pseudo_lock_measure_trigger(struct file *file,
 					   size_t count, loff_t *ppos)
 {
 	struct rdtgroup *rdtgrp = file->private_data;
-	size_t buf_size;
-	char buf[32];
 	int ret;
 	int sel;
 
-	buf_size = min(count, (sizeof(buf) - 1));
-	if (copy_from_user(buf, user_buf, buf_size))
-		return -EFAULT;
-
-	buf[buf_size] = '\0';
-	ret = kstrtoint(buf, 10, &sel);
+	ret = kstrtoint_from_user(user_buf, count, 10, &sel);
 	if (ret == 0) {
 		if (sel != 1 && sel != 2 && sel != 3)
 			return -EINVAL;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/2] fs/resctrl: Avoid extra call to strlen() in schemata_list_add()
  2026-08-21  8:11 [PATCH v2 1/2] fs/resctrl: Avoid extra call to strlen() in schemata_list_add() Dmitry Antipov
  2026-08-21  8:11 ` [PATCH v2 2/2] fs/resctrl: Simplify pseudo_lock_measure_trigger() Dmitry Antipov
@ 2026-08-25 18:25 ` Reinette Chatre
  1 sibling, 0 replies; 4+ messages in thread
From: Reinette Chatre @ 2026-08-25 18:25 UTC (permalink / raw)
  To: Dmitry Antipov
  Cc: Tony Luck, Dave Martin, James Morse, Babu Moger, x86,
	linux-kernel

Hi Dmitry,

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@yandex.ru>
> ---
Thank you.

Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>

Reinette


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 2/2] fs/resctrl: Simplify pseudo_lock_measure_trigger()
  2026-08-21  8:11 ` [PATCH v2 2/2] fs/resctrl: Simplify pseudo_lock_measure_trigger() Dmitry Antipov
@ 2026-08-25 18:25   ` Reinette Chatre
  0 siblings, 0 replies; 4+ messages in thread
From: Reinette Chatre @ 2026-08-25 18:25 UTC (permalink / raw)
  To: Dmitry Antipov
  Cc: Tony Luck, Dave Martin, James Morse, Babu Moger, x86,
	linux-kernel

Hi Dmitry,

On 8/21/26 1:11 AM, Dmitry Antipov wrote:
> Use convenient kstrtoint_from_user() to simplify pseudo_lock_measure_trigger().
> 
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> ---
Thank you.

Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>

Reinette

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-25 18:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-21  8:11 [PATCH v2 1/2] fs/resctrl: Avoid extra call to strlen() in schemata_list_add() Dmitry Antipov
2026-08-21  8:11 ` [PATCH v2 2/2] fs/resctrl: Simplify pseudo_lock_measure_trigger() Dmitry Antipov
2026-08-25 18:25   ` Reinette Chatre
2026-08-25 18:25 ` [PATCH v2 1/2] fs/resctrl: Avoid extra call to strlen() in schemata_list_add() Reinette Chatre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox