From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Subject: [PATCH 2/7] ALSA: aoa: Replace sprintf() with sysfs_emit()
Date: Mon, 1 Aug 2022 18:56:34 +0200 [thread overview]
Message-ID: <20220801165639.26030-3-tiwai@suse.de> (raw)
In-Reply-To: <20220801165639.26030-1-tiwai@suse.de>
For sysfs outputs, it's safer to use a new helper, sysfs_emit(),
instead of the raw sprintf() & co. This patch replaces such sprintf()
calls with sysfs_emit() while simplifying the open code in
modalias_show(); as modalias[] is a NUL-terminated string, we can pass
it straightly to a printf() argument.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/aoa/soundbus/sysfs.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/sound/aoa/soundbus/sysfs.c b/sound/aoa/soundbus/sysfs.c
index dead3105689b..e87b28428b99 100644
--- a/sound/aoa/soundbus/sysfs.c
+++ b/sound/aoa/soundbus/sysfs.c
@@ -10,19 +10,13 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
{
struct soundbus_dev *sdev = to_soundbus_device(dev);
struct platform_device *of = &sdev->ofdev;
- int length;
- if (*sdev->modalias) {
- strscpy(buf, sdev->modalias, sizeof(sdev->modalias) + 1);
- strcat(buf, "\n");
- length = strlen(buf);
- } else {
- length = sprintf(buf, "of:N%pOFn%c%s\n",
- of->dev.of_node, 'T',
- of_node_get_device_type(of->dev.of_node));
- }
-
- return length;
+ if (*sdev->modalias)
+ return sysfs_emit(buf, "%s\n", sdev->modalias);
+ else
+ return sysfs_emit(buf, "of:N%pOFn%c%s\n",
+ of->dev.of_node, 'T',
+ of_node_get_device_type(of->dev.of_node));
}
static DEVICE_ATTR_RO(modalias);
@@ -32,7 +26,7 @@ static ssize_t name_show(struct device *dev,
struct soundbus_dev *sdev = to_soundbus_device(dev);
struct platform_device *of = &sdev->ofdev;
- return sprintf(buf, "%pOFn\n", of->dev.of_node);
+ return sysfs_emit(buf, "%pOFn\n", of->dev.of_node);
}
static DEVICE_ATTR_RO(name);
@@ -42,7 +36,7 @@ static ssize_t type_show(struct device *dev,
struct soundbus_dev *sdev = to_soundbus_device(dev);
struct platform_device *of = &sdev->ofdev;
- return sprintf(buf, "%s\n", of_node_get_device_type(of->dev.of_node));
+ return sysfs_emit(buf, "%s\n", of_node_get_device_type(of->dev.of_node));
}
static DEVICE_ATTR_RO(type);
--
2.35.3
next prev parent reply other threads:[~2022-08-01 16:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-01 16:56 [PATCH 0/7] ALSA: Replace sprintf() with sysfs_emit() Takashi Iwai
2022-08-01 16:56 ` [PATCH 1/7] ALSA: ac97: " Takashi Iwai
2022-08-01 16:56 ` Takashi Iwai [this message]
2022-08-01 16:56 ` [PATCH 3/7] ALSA: control-led: " Takashi Iwai
2022-08-01 16:56 ` [PATCH 4/7] ALSA: core: Replace scnprintf() " Takashi Iwai
2022-08-01 16:56 ` [PATCH 5/7] ALSA: pcm: Replace sprintf() " Takashi Iwai
2022-08-01 16:56 ` [PATCH 6/7] ALSA: hda: " Takashi Iwai
2022-08-01 16:56 ` [PATCH 7/7] ALSA: line6: " Takashi Iwai
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=20220801165639.26030-3-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.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.