Skip to content

Commit f806bdb

Browse files
committed
ALSA: hwdep: Take private_data as drvdata for sysfs
For referring to a different object from sysfs ops, take hwdep private_data as stored via dev_set_drvdata() at creating the device object. In that way, the same sysfs ops can be used by different device types. Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent caa751b commit f806bdb

2 files changed

Lines changed: 17 additions & 30 deletions

File tree

‎sound/core/hwdep.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ static int snd_hwdep_dev_register(struct snd_device *device)
441441
struct device *d = snd_get_device(SNDRV_DEVICE_TYPE_HWDEP,
442442
hwdep->card, hwdep->device);
443443
if (d) {
444+
if (hwdep->private_data)
445+
dev_set_drvdata(d, hwdep->private_data);
444446
err = sysfs_create_groups(&d->kobj, hwdep->groups);
445447
if (err < 0)
446448
dev_warn(card->dev,

‎sound/pci/hda/hda_hwdep.c‎

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ static ssize_t power_on_acct_show(struct device *dev,
163163
struct device_attribute *attr,
164164
char *buf)
165165
{
166-
struct snd_hwdep *hwdep = dev_get_drvdata(dev);
167-
struct hda_codec *codec = hwdep->private_data;
166+
struct hda_codec *codec = dev_get_drvdata(dev);
168167
snd_hda_update_power_acct(codec);
169168
return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_on_acct));
170169
}
@@ -173,8 +172,7 @@ static ssize_t power_off_acct_show(struct device *dev,
173172
struct device_attribute *attr,
174173
char *buf)
175174
{
176-
struct snd_hwdep *hwdep = dev_get_drvdata(dev);
177-
struct hda_codec *codec = hwdep->private_data;
175+
struct hda_codec *codec = dev_get_drvdata(dev);
178176
snd_hda_update_power_acct(codec);
179177
return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_off_acct));
180178
}
@@ -251,8 +249,7 @@ static ssize_t type##_show(struct device *dev, \
251249
struct device_attribute *attr, \
252250
char *buf) \
253251
{ \
254-
struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
255-
struct hda_codec *codec = hwdep->private_data; \
252+
struct hda_codec *codec = dev_get_drvdata(dev); \
256253
return sprintf(buf, "0x%x\n", codec->type); \
257254
}
258255

@@ -261,8 +258,7 @@ static ssize_t type##_show(struct device *dev, \
261258
struct device_attribute *attr, \
262259
char *buf) \
263260
{ \
264-
struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
265-
struct hda_codec *codec = hwdep->private_data; \
261+
struct hda_codec *codec = dev_get_drvdata(dev); \
266262
return sprintf(buf, "%s\n", \
267263
codec->type ? codec->type : ""); \
268264
}
@@ -281,8 +277,7 @@ static ssize_t type##_store(struct device *dev, \
281277
struct device_attribute *attr, \
282278
const char *buf, size_t count) \
283279
{ \
284-
struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
285-
struct hda_codec *codec = hwdep->private_data; \
280+
struct hda_codec *codec = dev_get_drvdata(dev); \
286281
unsigned long val; \
287282
int err = kstrtoul(buf, 0, &val); \
288283
if (err < 0) \
@@ -296,8 +291,7 @@ static ssize_t type##_store(struct device *dev, \
296291
struct device_attribute *attr, \
297292
const char *buf, size_t count) \
298293
{ \
299-
struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
300-
struct hda_codec *codec = hwdep->private_data; \
294+
struct hda_codec *codec = dev_get_drvdata(dev); \
301295
char *s = kstrndup_noeol(buf, 64); \
302296
if (!s) \
303297
return -ENOMEM; \
@@ -318,8 +312,7 @@ static ssize_t type##_store(struct device *dev, \
318312
struct device_attribute *attr, \
319313
const char *buf, size_t count) \
320314
{ \
321-
struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
322-
struct hda_codec *codec = hwdep->private_data; \
315+
struct hda_codec *codec = dev_get_drvdata(dev); \
323316
int err = 0; \
324317
if (*buf) \
325318
err = type##_codec(codec); \
@@ -333,8 +326,7 @@ static ssize_t init_verbs_show(struct device *dev,
333326
struct device_attribute *attr,
334327
char *buf)
335328
{
336-
struct snd_hwdep *hwdep = dev_get_drvdata(dev);
337-
struct hda_codec *codec = hwdep->private_data;
329+
struct hda_codec *codec = dev_get_drvdata(dev);
338330
int i, len = 0;
339331
mutex_lock(&codec->user_mutex);
340332
for (i = 0; i < codec->init_verbs.used; i++) {
@@ -373,8 +365,7 @@ static ssize_t init_verbs_store(struct device *dev,
373365
struct device_attribute *attr,
374366
const char *buf, size_t count)
375367
{
376-
struct snd_hwdep *hwdep = dev_get_drvdata(dev);
377-
struct hda_codec *codec = hwdep->private_data;
368+
struct hda_codec *codec = dev_get_drvdata(dev);
378369
int err = parse_init_verbs(codec, buf);
379370
if (err < 0)
380371
return err;
@@ -385,8 +376,7 @@ static ssize_t hints_show(struct device *dev,
385376
struct device_attribute *attr,
386377
char *buf)
387378
{
388-
struct snd_hwdep *hwdep = dev_get_drvdata(dev);
389-
struct hda_codec *codec = hwdep->private_data;
379+
struct hda_codec *codec = dev_get_drvdata(dev);
390380
int i, len = 0;
391381
mutex_lock(&codec->user_mutex);
392382
for (i = 0; i < codec->hints.used; i++) {
@@ -480,8 +470,7 @@ static ssize_t hints_store(struct device *dev,
480470
struct device_attribute *attr,
481471
const char *buf, size_t count)
482472
{
483-
struct snd_hwdep *hwdep = dev_get_drvdata(dev);
484-
struct hda_codec *codec = hwdep->private_data;
473+
struct hda_codec *codec = dev_get_drvdata(dev);
485474
int err = parse_hints(codec, buf);
486475
if (err < 0)
487476
return err;
@@ -507,26 +496,23 @@ static ssize_t init_pin_configs_show(struct device *dev,
507496
struct device_attribute *attr,
508497
char *buf)
509498
{
510-
struct snd_hwdep *hwdep = dev_get_drvdata(dev);
511-
struct hda_codec *codec = hwdep->private_data;
499+
struct hda_codec *codec = dev_get_drvdata(dev);
512500
return pin_configs_show(codec, &codec->init_pins, buf);
513501
}
514502

515503
static ssize_t user_pin_configs_show(struct device *dev,
516504
struct device_attribute *attr,
517505
char *buf)
518506
{
519-
struct snd_hwdep *hwdep = dev_get_drvdata(dev);
520-
struct hda_codec *codec = hwdep->private_data;
507+
struct hda_codec *codec = dev_get_drvdata(dev);
521508
return pin_configs_show(codec, &codec->user_pins, buf);
522509
}
523510

524511
static ssize_t driver_pin_configs_show(struct device *dev,
525512
struct device_attribute *attr,
526513
char *buf)
527514
{
528-
struct snd_hwdep *hwdep = dev_get_drvdata(dev);
529-
struct hda_codec *codec = hwdep->private_data;
515+
struct hda_codec *codec = dev_get_drvdata(dev);
530516
return pin_configs_show(codec, &codec->driver_pins, buf);
531517
}
532518

@@ -550,8 +536,7 @@ static ssize_t user_pin_configs_store(struct device *dev,
550536
struct device_attribute *attr,
551537
const char *buf, size_t count)
552538
{
553-
struct snd_hwdep *hwdep = dev_get_drvdata(dev);
554-
struct hda_codec *codec = hwdep->private_data;
539+
struct hda_codec *codec = dev_get_drvdata(dev);
555540
int err = parse_user_pin_configs(codec, buf);
556541
if (err < 0)
557542
return err;

0 commit comments

Comments
 (0)