All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: target: avoid strlen() in target_core_call_addhbatotarget()
@ 2026-07-22  6:35 Dmitry Antipov
  2026-07-22  6:48 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Antipov @ 2026-07-22  6:35 UTC (permalink / raw)
  To: Martin K . Petersen; +Cc: linux-scsi, target-devel, Dmitry Antipov

Since 'snprintf()' is capable to detect output truncation, an extra call
to 'strlen()' in 'target_core_call_addhbatotarget()' may be dropped.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 drivers/target/target_core_configfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index 2b19a956007b..3214047031b8 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -3635,13 +3635,13 @@ static struct config_group *target_core_call_addhbatotarget(
 	unsigned long plugin_dep_id = 0;
 	int ret;
 
-	if (strlen(name) >= TARGET_CORE_NAME_MAX_LEN) {
+	ret = snprintf(buf, TARGET_CORE_NAME_MAX_LEN, "%s", name);
+	if (ret >= TARGET_CORE_NAME_MAX_LEN) {
 		pr_err("Passed *name strlen(): %d exceeds"
 			" TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name),
 			TARGET_CORE_NAME_MAX_LEN);
 		return ERR_PTR(-ENAMETOOLONG);
 	}
-	snprintf(buf, TARGET_CORE_NAME_MAX_LEN, "%s", name);
 
 	str = strstr(buf, "_");
 	if (!str) {
-- 
2.55.0


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

end of thread, other threads:[~2026-07-22  8:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-22  6:35 [PATCH] scsi: target: avoid strlen() in target_core_call_addhbatotarget() Dmitry Antipov
2026-07-22  6:48 ` sashiko-bot
2026-07-22  8:14   ` [PATCH v2] " Dmitry Antipov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.