[PATCH 1/3] sh: dma-sysfs: use sysfs_emit{_at} in show functions

From: Thorsten Blum

Date: Mon Apr 20 2026 - 11:28:48 EST


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@xxxxxxxxx>
---
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);