summaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2022-08-01 18:56:35 +0200
committerTakashi Iwai <tiwai@suse.de>2022-08-02 16:03:43 +0200
commitade7956396d0e821097393bc4fe5773525f2634c (patch)
tree770d58a907fda09354eaf6e1980a69bcf3a55fc0 /sound
parent0980bb1ff0f0ef0a3fb08f7596167eda2c932b45 (diff)
ALSA: control-led: Replace sprintf() with sysfs_emit()
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 list_show(). Link: https://lore.kernel.org/r/20220801165639.26030-4-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound')
-rw-r--r--sound/core/control_led.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/sound/core/control_led.c b/sound/core/control_led.c
index 207828f30983..f975cc85772b 100644
--- a/sound/core/control_led.c
+++ b/sound/core/control_led.c
@@ -405,7 +405,7 @@ static ssize_t mode_show(struct device *dev,
case MODE_ON: str = "on"; break;
case MODE_OFF: str = "off"; break;
}
- return sprintf(buf, "%s\n", str);
+ return sysfs_emit(buf, "%s\n", str);
}
static ssize_t mode_store(struct device *dev,
@@ -443,7 +443,7 @@ static ssize_t brightness_show(struct device *dev,
{
struct snd_ctl_led *led = container_of(dev, struct snd_ctl_led, dev);
- return sprintf(buf, "%u\n", ledtrig_audio_get(led->trigger_type));
+ return sysfs_emit(buf, "%u\n", ledtrig_audio_get(led->trigger_type));
}
static DEVICE_ATTR_RW(mode);
@@ -618,8 +618,7 @@ static ssize_t list_show(struct device *dev,
struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev);
struct snd_card *card;
struct snd_ctl_led_ctl *lctl;
- char *buf2 = buf;
- size_t l;
+ size_t l = 0;
card = snd_card_ref(led_card->number);
if (!card)
@@ -627,23 +626,19 @@ static ssize_t list_show(struct device *dev,
down_read(&card->controls_rwsem);
mutex_lock(&snd_ctl_led_mutex);
if (snd_ctl_led_card_valid[led_card->number]) {
- list_for_each_entry(lctl, &led_card->led->controls, list)
- if (lctl->card == card) {
- if (buf2 - buf > PAGE_SIZE - 16)
- break;
- if (buf2 != buf)
- *buf2++ = ' ';
- l = scnprintf(buf2, 15, "%u",
- lctl->kctl->id.numid +
- lctl->index_offset);
- buf2[l] = '\0';
- buf2 += l + 1;
- }
+ list_for_each_entry(lctl, &led_card->led->controls, list) {
+ if (lctl->card != card)
+ continue;
+ if (l)
+ l += sysfs_emit_at(buf, l, " ");
+ l += sysfs_emit_at(buf, l, "%u",
+ lctl->kctl->id.numid + lctl->index_offset);
+ }
}
mutex_unlock(&snd_ctl_led_mutex);
up_read(&card->controls_rwsem);
snd_card_unref(card);
- return buf2 - buf;
+ return l;
}
static DEVICE_ATTR_WO(attach);