From: Dharanitharan R <dharanitharan725@gmail.com>
To: Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
Dharanitharan R <dharanitharan725@gmail.com>
Subject: [PATCH v1] mtd: sm_ftl: use strscpy() in sm_attr_show()
Date: Sat, 6 Dec 2025 03:53:13 +0000 [thread overview]
Message-ID: <20251206035313.10190-1-dharanitharan725@gmail.com> (raw)
In sm_ftl.c, the sm_attr_show() function currently copies
attribute data using:
strncpy(buf, sm_attr->data, sm_attr->len);
return sm_attr->len;
Using strncpy() can be unsafe because it does not guarantee
a NUL terminator if the source length equals the buffer size.
Although sm_attr->data comes from internal structures and
is NUL-terminated, it is cleaner and safer to use strscpy(),
which guarantees NUL termination and avoids zero-padding.
The destination buffer is PAGE_SIZE bytes, which is sufficient
to hold sm_attr->data without truncation. The return value
of strscpy() matches the expected behavior of sm_attr_show().
Replace the strncpy() call with:
return strscpy(buf, sm_attr->data, PAGE_SIZE);
Signed-off-by: Dharanitharan R <dharanitharan725@gmail.com>
---
drivers/mtd/sm_ftl.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
index abc7b186353f..229fdc4a754a 100644
--- a/drivers/mtd/sm_ftl.c
+++ b/drivers/mtd/sm_ftl.c
@@ -44,8 +44,7 @@ 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;
+ return strscpy(buf, sm_attr->data, PAGE_SIZE);
}
--
2.43.0
next reply other threads:[~2025-12-06 3:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-06 3:53 Dharanitharan R [this message]
2025-12-16 8:06 ` Miquel Raynal
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=20251206035313.10190-1-dharanitharan725@gmail.com \
--to=dharanitharan725@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®