Commit ade79563 authored by Takashi Iwai's avatar Takashi Iwai

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.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 0980bb1f
...@@ -405,7 +405,7 @@ static ssize_t mode_show(struct device *dev, ...@@ -405,7 +405,7 @@ static ssize_t mode_show(struct device *dev,
case MODE_ON: str = "on"; break; case MODE_ON: str = "on"; break;
case MODE_OFF: str = "off"; 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, static ssize_t mode_store(struct device *dev,
...@@ -443,7 +443,7 @@ static ssize_t brightness_show(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); 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); static DEVICE_ATTR_RW(mode);
...@@ -618,8 +618,7 @@ static ssize_t list_show(struct device *dev, ...@@ -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_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev);
struct snd_card *card; struct snd_card *card;
struct snd_ctl_led_ctl *lctl; struct snd_ctl_led_ctl *lctl;
char *buf2 = buf; size_t l = 0;
size_t l;
card = snd_card_ref(led_card->number); card = snd_card_ref(led_card->number);
if (!card) if (!card)
...@@ -627,23 +626,19 @@ static ssize_t list_show(struct device *dev, ...@@ -627,23 +626,19 @@ static ssize_t list_show(struct device *dev,
down_read(&card->controls_rwsem); down_read(&card->controls_rwsem);
mutex_lock(&snd_ctl_led_mutex); mutex_lock(&snd_ctl_led_mutex);
if (snd_ctl_led_card_valid[led_card->number]) { if (snd_ctl_led_card_valid[led_card->number]) {
list_for_each_entry(lctl, &led_card->led->controls, list) list_for_each_entry(lctl, &led_card->led->controls, list) {
if (lctl->card == card) { if (lctl->card != card)
if (buf2 - buf > PAGE_SIZE - 16) continue;
break; if (l)
if (buf2 != buf) l += sysfs_emit_at(buf, l, " ");
*buf2++ = ' '; l += sysfs_emit_at(buf, l, "%u",
l = scnprintf(buf2, 15, "%u", lctl->kctl->id.numid + lctl->index_offset);
lctl->kctl->id.numid + }
lctl->index_offset);
buf2[l] = '\0';
buf2 += l + 1;
}
} }
mutex_unlock(&snd_ctl_led_mutex); mutex_unlock(&snd_ctl_led_mutex);
up_read(&card->controls_rwsem); up_read(&card->controls_rwsem);
snd_card_unref(card); snd_card_unref(card);
return buf2 - buf; return l;
} }
static DEVICE_ATTR_WO(attach); static DEVICE_ATTR_WO(attach);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment