All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thorsten Blum <thorsten.blum@linux.dev>
To: Rich Felker <dalias@libc.org>,
	John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org,
	Thorsten Blum <thorsten.blum@linux.dev>
Subject: [PATCH 2/2] sh: sq: use sysfs_emit_at() in mapping_show
Date: Fri, 24 Apr 2026 14:10:11 +0200	[thread overview]
Message-ID: <20260424121007.311797-6-thorsten.blum@linux.dev> (raw)
In-Reply-To: <20260424121007.311797-4-thorsten.blum@linux.dev>

Replace sprintf() with sysfs_emit_at() in mapping_show().
sysfs_emit_at() is preferred for formatting sysfs output because it
provides safer bounds checking and avoids manual buffer size accounting.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/sh/kernel/cpu/sh4/sq.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/sh/kernel/cpu/sh4/sq.c b/arch/sh/kernel/cpu/sh4/sq.c
index 908a8e09113b..50e7df13fcc2 100644
--- a/arch/sh/kernel/cpu/sh4/sq.c
+++ b/arch/sh/kernel/cpu/sh4/sq.c
@@ -14,6 +14,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/vmalloc.h>
 #include <linux/mm.h>
 #include <linux/io.h>
@@ -289,14 +290,14 @@ static ssize_t sq_sysfs_store(struct kobject *kobj, struct attribute *attr,
 static ssize_t mapping_show(char *buf)
 {
 	struct sq_mapping **list, *entry;
-	char *p = buf;
+	ssize_t len = 0;
 
 	for (list = &sq_mapping_list; (entry = *list); list = &entry->next)
-		p += sprintf(p, "%08lx-%08lx [%08lx]: %s\n",
-			     entry->sq_addr, entry->sq_addr + entry->size,
-			     entry->addr, entry->name);
+		len += sysfs_emit_at(buf, len, "%08lx-%08lx [%08lx]: %s\n",
+				entry->sq_addr, entry->sq_addr + entry->size,
+				entry->addr, entry->name);
 
-	return p - buf;
+	return len;
 }
 
 static ssize_t mapping_store(const char *buf, size_t count)

      reply	other threads:[~2026-04-24 12:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-24 12:10 [PATCH 1/2] sh: push-switch: use sysfs_emit() in switch_show Thorsten Blum
2026-04-24 12:10 ` Thorsten Blum [this message]

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=20260424121007.311797-6-thorsten.blum@linux.dev \
    --to=thorsten.blum@linux.dev \
    --cc=dalias@libc.org \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    /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.