* [PATCH 1/3] sh: dma-sysfs: use sysfs_emit{_at} in show functions
@ 2026-04-20 15:09 Thorsten Blum
2026-04-20 15:09 ` [PATCH 2/3] sh: dma-sysfs: use strscpy in dma_store_dev_id Thorsten Blum
2026-04-20 15:10 ` [PATCH 3/3] sh: dma: drop redundant size argument from strscpy in request_dma Thorsten Blum
0 siblings, 2 replies; 5+ messages in thread
From: Thorsten Blum @ 2026-04-20 15:09 UTC (permalink / raw)
To: Yoshinori Sato, Rich Felker, John Paul Adrian Glaubitz
Cc: Thorsten Blum, linux-sh, linux-kernel
Replace sprintf() with sysfs_emit() and sysfs_emit_at() in sysfs show
functions. sysfs_emit() and sysfs_emit_at() are preferred for formatting
sysfs output because they provide safer bounds checking.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/sh/drivers/dma/dma-sysfs.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/arch/sh/drivers/dma/dma-sysfs.c b/arch/sh/drivers/dma/dma-sysfs.c
index 9f666280d80c..d4e16cfc7a12 100644
--- a/arch/sh/drivers/dma/dma-sysfs.c
+++ b/arch/sh/drivers/dma/dma-sysfs.c
@@ -13,6 +13,7 @@
#include <linux/platform_device.h>
#include <linux/err.h>
#include <linux/string.h>
+#include <linux/sysfs.h>
#include <asm/dma.h>
static const struct bus_type dma_subsys = {
@@ -33,9 +34,9 @@ static ssize_t dma_show_devices(struct device *dev,
if (unlikely(!info) || !channel)
continue;
- len += sprintf(buf + len, "%2d: %14s %s\n",
- channel->chan, info->name,
- channel->dev_id);
+ len += sysfs_emit_at(buf, len, "%2d: %14s %s\n",
+ channel->chan, info->name,
+ channel->dev_id);
}
return len;
@@ -65,7 +66,7 @@ static ssize_t dma_show_dev_id(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dma_channel *channel = to_dma_channel(dev);
- return sprintf(buf, "%s\n", channel->dev_id);
+ return sysfs_emit(buf, "%s\n", channel->dev_id);
}
static ssize_t dma_store_dev_id(struct device *dev,
@@ -98,7 +99,7 @@ static ssize_t dma_show_mode(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dma_channel *channel = to_dma_channel(dev);
- return sprintf(buf, "0x%08x\n", channel->mode);
+ return sysfs_emit(buf, "0x%08x\n", channel->mode);
}
static ssize_t dma_store_mode(struct device *dev,
@@ -117,7 +118,7 @@ static ssize_t dma_show_##field(struct device *dev, \
struct device_attribute *attr, char *buf)\
{ \
struct dma_channel *channel = to_dma_channel(dev); \
- return sprintf(buf, fmt, channel->field); \
+ return sysfs_emit(buf, fmt, channel->field); \
} \
static DEVICE_ATTR(field, S_IRUGO, dma_show_##field, NULL);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] sh: dma-sysfs: use strscpy in dma_store_dev_id
2026-04-20 15:09 [PATCH 1/3] sh: dma-sysfs: use sysfs_emit{_at} in show functions Thorsten Blum
@ 2026-04-20 15:09 ` Thorsten Blum
2026-04-21 7:04 ` Geert Uytterhoeven
2026-04-20 15:10 ` [PATCH 3/3] sh: dma: drop redundant size argument from strscpy in request_dma Thorsten Blum
1 sibling, 1 reply; 5+ messages in thread
From: Thorsten Blum @ 2026-04-20 15:09 UTC (permalink / raw)
To: Yoshinori Sato, Rich Felker, John Paul Adrian Glaubitz
Cc: Thorsten Blum, linux-sh, linux-kernel
strcpy() has been deprecated¹ because it performs no bounds checking on
the destination buffer, which can lead to buffer overflows. Replace it
with the safer strscpy().
¹ https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/sh/drivers/dma/dma-sysfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/sh/drivers/dma/dma-sysfs.c b/arch/sh/drivers/dma/dma-sysfs.c
index d4e16cfc7a12..d1d6b9bb0d7e 100644
--- a/arch/sh/drivers/dma/dma-sysfs.c
+++ b/arch/sh/drivers/dma/dma-sysfs.c
@@ -74,7 +74,7 @@ static ssize_t dma_store_dev_id(struct device *dev,
const char *buf, size_t count)
{
struct dma_channel *channel = to_dma_channel(dev);
- strcpy(channel->dev_id, buf);
+ strscpy(channel->dev_id, buf);
return count;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] sh: dma: drop redundant size argument from strscpy in request_dma
2026-04-20 15:09 [PATCH 1/3] sh: dma-sysfs: use sysfs_emit{_at} in show functions Thorsten Blum
2026-04-20 15:09 ` [PATCH 2/3] sh: dma-sysfs: use strscpy in dma_store_dev_id Thorsten Blum
@ 2026-04-20 15:10 ` Thorsten Blum
2026-04-21 7:05 ` Geert Uytterhoeven
1 sibling, 1 reply; 5+ messages in thread
From: Thorsten Blum @ 2026-04-20 15:10 UTC (permalink / raw)
To: Yoshinori Sato, Rich Felker, John Paul Adrian Glaubitz
Cc: Thorsten Blum, linux-sh, linux-kernel
The strscpy() size argument is optional if the destination buffer has a
fixed length. Use the two-argument version of strscpy() to copy 'dev_id'
to simplify the code.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/sh/drivers/dma/dma-api.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/sh/drivers/dma/dma-api.c b/arch/sh/drivers/dma/dma-api.c
index 87e5a8928873..15e2c10c9805 100644
--- a/arch/sh/drivers/dma/dma-api.c
+++ b/arch/sh/drivers/dma/dma-api.c
@@ -96,7 +96,7 @@ int request_dma(unsigned int chan, const char *dev_id)
if (atomic_xchg(&channel->busy, 1))
return -EBUSY;
- strscpy(channel->dev_id, dev_id, sizeof(channel->dev_id));
+ strscpy(channel->dev_id, dev_id);
if (info->ops->request) {
result = info->ops->request(channel);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] sh: dma-sysfs: use strscpy in dma_store_dev_id
2026-04-20 15:09 ` [PATCH 2/3] sh: dma-sysfs: use strscpy in dma_store_dev_id Thorsten Blum
@ 2026-04-21 7:04 ` Geert Uytterhoeven
0 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2026-04-21 7:04 UTC (permalink / raw)
To: Thorsten Blum
Cc: Yoshinori Sato, Rich Felker, John Paul Adrian Glaubitz, linux-sh,
linux-kernel
On Mon, 20 Apr 2026 at 17:28, Thorsten Blum <thorsten.blum@linux.dev> wrote:
> strcpy() has been deprecated¹ because it performs no bounds checking on
> the destination buffer, which can lead to buffer overflows. Replace it
> with the safer strscpy().
>
> ¹ https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 3/3] sh: dma: drop redundant size argument from strscpy in request_dma
2026-04-20 15:10 ` [PATCH 3/3] sh: dma: drop redundant size argument from strscpy in request_dma Thorsten Blum
@ 2026-04-21 7:05 ` Geert Uytterhoeven
0 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2026-04-21 7:05 UTC (permalink / raw)
To: Thorsten Blum
Cc: Yoshinori Sato, Rich Felker, John Paul Adrian Glaubitz, linux-sh,
linux-kernel
On Mon, 20 Apr 2026 at 17:28, Thorsten Blum <thorsten.blum@linux.dev> wrote:
> The strscpy() size argument is optional if the destination buffer has a
> fixed length. Use the two-argument version of strscpy() to copy 'dev_id'
> to simplify the code.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-21 7:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-20 15:09 [PATCH 1/3] sh: dma-sysfs: use sysfs_emit{_at} in show functions Thorsten Blum
2026-04-20 15:09 ` [PATCH 2/3] sh: dma-sysfs: use strscpy in dma_store_dev_id Thorsten Blum
2026-04-21 7:04 ` Geert Uytterhoeven
2026-04-20 15:10 ` [PATCH 3/3] sh: dma: drop redundant size argument from strscpy in request_dma Thorsten Blum
2026-04-21 7:05 ` Geert Uytterhoeven
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox