ALSA: core: use DEVICE_ATTR_*() macro

Use DEVICE_ATTR_*() helper instead of plain DEVICE_ATTR,
which makes the code a bit shorter and easier to read.

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Link: https://lore.kernel.org/r/20210526121828.8460-1-yuehaibing@huawei.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
YueHaibing
2021-05-26 20:18:28 +08:00
committed by Takashi Iwai
parent d360870a5b
commit 873fd81377

View File

@@ -665,16 +665,14 @@ void snd_card_set_id(struct snd_card *card, const char *nid)
} }
EXPORT_SYMBOL(snd_card_set_id); EXPORT_SYMBOL(snd_card_set_id);
static ssize_t static ssize_t id_show(struct device *dev,
card_id_show_attr(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct snd_card *card = container_of(dev, struct snd_card, card_dev); struct snd_card *card = container_of(dev, struct snd_card, card_dev);
return scnprintf(buf, PAGE_SIZE, "%s\n", card->id); return scnprintf(buf, PAGE_SIZE, "%s\n", card->id);
} }
static ssize_t static ssize_t id_store(struct device *dev, struct device_attribute *attr,
card_id_store_attr(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct snd_card *card = container_of(dev, struct snd_card, card_dev); struct snd_card *card = container_of(dev, struct snd_card, card_dev);
@@ -703,17 +701,16 @@ card_id_store_attr(struct device *dev, struct device_attribute *attr,
return count; return count;
} }
static DEVICE_ATTR(id, 0644, card_id_show_attr, card_id_store_attr); static DEVICE_ATTR_RW(id);
static ssize_t static ssize_t number_show(struct device *dev,
card_number_show_attr(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct snd_card *card = container_of(dev, struct snd_card, card_dev); struct snd_card *card = container_of(dev, struct snd_card, card_dev);
return scnprintf(buf, PAGE_SIZE, "%i\n", card->number); return scnprintf(buf, PAGE_SIZE, "%i\n", card->number);
} }
static DEVICE_ATTR(number, 0444, card_number_show_attr, NULL); static DEVICE_ATTR_RO(number);
static struct attribute *card_dev_attrs[] = { static struct attribute *card_dev_attrs[] = {
&dev_attr_id.attr, &dev_attr_id.attr,