From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Rahul Kumar <rk0006818@gmail.com>
Cc: richard@nod.at, vigneshr@ti.com, linux-mtd@lists.infradead.org,
linux-kernel@vger.kernel.org,
linux-kernel-mentees@lists.linux.dev, skhan@linuxfoundation.org,
Pratyush Yadav <pratyush@kernel.org>
Subject: Re: [PATCH v2] mtd: sm_ftl: replace strncpy with memcpy
Date: Mon, 08 Sep 2025 09:21:22 +0200 [thread overview]
Message-ID: <87tt1djtot.fsf@bootlin.com> (raw)
In-Reply-To: <20250908070124.2647038-1-rk0006818@gmail.com> (Rahul Kumar's message of "Mon, 8 Sep 2025 12:31:24 +0530")
Hi Rahul,
On 08/09/2025 at 12:31:24 +0530, Rahul Kumar <rk0006818@gmail.com> wrote:
> Replace strncpy with memcpy in sm_attr_show and explicitly add a NUL
> terminator after the copy. Also update the return value to reflect the
> extra byte written for the terminator. This aligns with current kernel
> best practices as strncpy is deprecated for such use, as explained in
> Documentation/process/deprecated.rst.
The doc states "strscpy" as a replacement, not memcpy.
> No functional change, only cleanup for consistency.
>
> Suggested-by: Pratyush Yadav <pratyush@kernel.org>
> Signed-off-by: Rahul Kumar <rk0006818@gmail.com>
> ---
> Changes in v1:
> - Update return value to match the extra NUL written.
> Link to v1: https://lore.kernel.org/all/mafs0ms7bvcd2.fsf@kernel.org/T/#t
> ---
> drivers/mtd/sm_ftl.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
> index d28d4f1790f5..3c5d6d0c728f 100644
> --- a/drivers/mtd/sm_ftl.c
> +++ b/drivers/mtd/sm_ftl.c
> @@ -44,8 +44,9 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
> struct sm_sysfs_attribute *sm_attr =
> container_of(attr, struct sm_sysfs_attribute, dev_attr);
>
> - strncpy(buf, sm_attr->data, sm_attr->len);
> - return sm_attr->len;
> + memcpy(buf, sm_attr->data, sm_attr->len);
> + buf[sm_attr->len] = '\0';
> + return sm_attr->len + 1;
Are we sure the buffer is always sm_attr->len + 1 long?
Thanks,
Miquèl
WARNING: multiple messages have this Message-ID (diff)
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Rahul Kumar <rk0006818@gmail.com>
Cc: richard@nod.at, vigneshr@ti.com, linux-mtd@lists.infradead.org,
linux-kernel@vger.kernel.org,
linux-kernel-mentees@lists.linux.dev, skhan@linuxfoundation.org,
Pratyush Yadav <pratyush@kernel.org>
Subject: Re: [PATCH v2] mtd: sm_ftl: replace strncpy with memcpy
Date: Mon, 08 Sep 2025 09:21:22 +0200 [thread overview]
Message-ID: <87tt1djtot.fsf@bootlin.com> (raw)
In-Reply-To: <20250908070124.2647038-1-rk0006818@gmail.com> (Rahul Kumar's message of "Mon, 8 Sep 2025 12:31:24 +0530")
Hi Rahul,
On 08/09/2025 at 12:31:24 +0530, Rahul Kumar <rk0006818@gmail.com> wrote:
> Replace strncpy with memcpy in sm_attr_show and explicitly add a NUL
> terminator after the copy. Also update the return value to reflect the
> extra byte written for the terminator. This aligns with current kernel
> best practices as strncpy is deprecated for such use, as explained in
> Documentation/process/deprecated.rst.
The doc states "strscpy" as a replacement, not memcpy.
> No functional change, only cleanup for consistency.
>
> Suggested-by: Pratyush Yadav <pratyush@kernel.org>
> Signed-off-by: Rahul Kumar <rk0006818@gmail.com>
> ---
> Changes in v1:
> - Update return value to match the extra NUL written.
> Link to v1: https://lore.kernel.org/all/mafs0ms7bvcd2.fsf@kernel.org/T/#t
> ---
> drivers/mtd/sm_ftl.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
> index d28d4f1790f5..3c5d6d0c728f 100644
> --- a/drivers/mtd/sm_ftl.c
> +++ b/drivers/mtd/sm_ftl.c
> @@ -44,8 +44,9 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
> struct sm_sysfs_attribute *sm_attr =
> container_of(attr, struct sm_sysfs_attribute, dev_attr);
>
> - strncpy(buf, sm_attr->data, sm_attr->len);
> - return sm_attr->len;
> + memcpy(buf, sm_attr->data, sm_attr->len);
> + buf[sm_attr->len] = '\0';
> + return sm_attr->len + 1;
Are we sure the buffer is always sm_attr->len + 1 long?
Thanks,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2025-09-08 7:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-08 7:01 [PATCH v2] mtd: sm_ftl: replace strncpy with memcpy Rahul Kumar
2025-09-08 7:01 ` Rahul Kumar
2025-09-08 7:21 ` Miquel Raynal [this message]
2025-09-08 7:21 ` Miquel Raynal
2025-09-08 9:04 ` Richard Weinberger
2025-09-08 9:04 ` Richard Weinberger
2025-09-09 11:45 ` Pratyush Yadav
2025-09-09 11:45 ` Pratyush Yadav
2025-09-09 12:12 ` Rahul Kumar
2025-09-09 12:12 ` Rahul Kumar
2025-09-09 19:50 ` Richard Weinberger
2025-09-09 19:50 ` Richard Weinberger
2025-09-10 7:02 ` Rahul Kumar
2025-09-10 7:02 ` Rahul Kumar
2025-09-09 11:27 ` Pratyush Yadav
2025-09-09 11:27 ` Pratyush Yadav
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=87tt1djtot.fsf@bootlin.com \
--to=miquel.raynal@bootlin.com \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=pratyush@kernel.org \
--cc=richard@nod.at \
--cc=rk0006818@gmail.com \
--cc=skhan@linuxfoundation.org \
--cc=vigneshr@ti.com \
/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.