All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dmitry Antipov" <dmantipov@yandex.ru>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: target: avoid strlen() in target_core_call_addhbatotarget()
Date: Wed, 22 Jul 2026 06:48:21 +0000	[thread overview]
Message-ID: <20260722064821.B56F71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260722063523.669361-1-dmantipov@yandex.ru>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Incomplete replacement of strlen(): a redundant call to strlen(name) remains in the error handling path despite the length already being captured.
--

--- Patch [1]: [PATCH] scsi: target: avoid strlen() in target_core_call_addhbatotarget() ---
commit 03360414acae57f08ec406c8bedc559ab4a7788c
Author: Dmitry Antipov <dmantipov@yandex.ru>

scsi: target: avoid strlen() in target_core_call_addhbatotarget()

This commit avoids calling strlen() by leveraging the return value of
snprintf() to detect if the string exceeds the maximum length.

> diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
> index 2b19a956007b7..3214047031b86 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),

[Severity: Low]
Since ret now holds the exact length of the input string, could this remaining
call to strlen(name) in target_core_call_addhbatotarget() be replaced with ret
to completely avoid strlen() on this path?

>  			TARGET_CORE_NAME_MAX_LEN);
>  		return ERR_PTR(-ENAMETOOLONG);
>  	}
> -	snprintf(buf, TARGET_CORE_NAME_MAX_LEN, "%s", name);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260722063523.669361-1-dmantipov@yandex.ru?part=1

  reply	other threads:[~2026-07-22  6:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22  6:35 [PATCH] scsi: target: avoid strlen() in target_core_call_addhbatotarget() Dmitry Antipov
2026-07-22  6:48 ` sashiko-bot [this message]
2026-07-22  8:14   ` [PATCH v2] " Dmitry Antipov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260722064821.B56F71F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmantipov@yandex.ru \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.