From: Thorsten Blum <thorsten.blum@linux.dev>
To: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
linux1394-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: [PATCH] firewire: core: clean up modalias buffer handling
Date: Sun, 29 Mar 2026 23:19:40 +0200 [thread overview]
Message-ID: <20260329211940.371395-2-thorsten.blum@linux.dev> (raw)
Use scnprintf() in get_modalias() to return the number of characters
actually written to the destination buffer.
Also reserve space for the trailing newline in modalias_show() and
append it explicitly, instead of using strcpy() and relying on the
formatted modalias to fit within PAGE_SIZE.
While the current code is safe, this makes the sysfs buffer handling
more explicit and consistent.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/firewire/core-device.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
index c0f17da27a22..182eb4321e47 100644
--- a/drivers/firewire/core-device.c
+++ b/drivers/firewire/core-device.c
@@ -234,9 +234,9 @@ static int get_modalias(const struct fw_unit *unit, char *buffer, size_t buffer_
get_modalias_ids(unit, id);
- return snprintf(buffer, buffer_size,
- "ieee1394:ven%08Xmo%08Xsp%08Xver%08X",
- id[0], id[1], id[2], id[3]);
+ return scnprintf(buffer, buffer_size,
+ "ieee1394:ven%08Xmo%08Xsp%08Xver%08X",
+ id[0], id[1], id[2], id[3]);
}
static int fw_unit_uevent(const struct device *dev, struct kobj_uevent_env *env)
@@ -435,8 +435,9 @@ static ssize_t modalias_show(struct device *dev,
struct fw_unit *unit = fw_unit(dev);
int length;
- length = get_modalias(unit, buf, PAGE_SIZE);
- strcpy(buf + length, "\n");
+ length = get_modalias(unit, buf, PAGE_SIZE - 1);
+ buf[length] = '\n';
+ buf[length + 1] = '\0';
return length + 1;
}
next reply other threads:[~2026-03-29 21:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-29 21:19 Thorsten Blum [this message]
2026-03-30 0:57 ` [PATCH] firewire: core: clean up modalias buffer handling Takashi Sakamoto
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=20260329211940.371395-2-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux1394-devel@lists.sourceforge.net \
--cc=o-takashi@sakamocchi.jp \
/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