[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87tt1djtot.fsf@bootlin.com>
Date: Mon, 08 Sep 2025 09:21:22 +0200
From: Miquel Raynal <miquel.raynal@...tlin.com>
To: Rahul Kumar <rk0006818@...il.com>
Cc: richard@....at, vigneshr@...com, linux-mtd@...ts.infradead.org,
linux-kernel@...r.kernel.org, linux-kernel-mentees@...ts.linux.dev,
skhan@...uxfoundation.org, Pratyush Yadav <pratyush@...nel.org>
Subject: Re: [PATCH v2] mtd: sm_ftl: replace strncpy with memcpy
Hi Rahul,
On 08/09/2025 at 12:31:24 +0530, Rahul Kumar <rk0006818@...il.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@...nel.org>
> Signed-off-by: Rahul Kumar <rk0006818@...il.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
Powered by blists - more mailing lists