diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-01-06 17:12:45 -0800 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-01-10 14:53:56 -0800 |
commit | 36ae1a96c4dcb0f6581d595cc5d43cf3a7e648c7 (patch) | |
tree | f0de43670060374bf9f2e81a4c2fcb65dc821545 /sound | |
parent | e4e9e05409280b50003280afffe27ade21480dd7 (diff) | |
download | linux-36ae1a96c4dcb0f6581d595cc5d43cf3a7e648c7.tar.gz linux-36ae1a96c4dcb0f6581d595cc5d43cf3a7e648c7.tar.bz2 linux-36ae1a96c4dcb0f6581d595cc5d43cf3a7e648c7.zip |
ASoC: Dynamically allocate the rtd device for a non-empty release()
The device model needs a release() function so it can free devices when
they become dereferenced. Do that for rtds.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/soc/soc-core.c | 44 | ||||
-rw-r--r-- | sound/soc/soc-dapm.c | 3 |
2 files changed, 26 insertions, 21 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index acbb96005a69..3986520b4677 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -169,8 +169,7 @@ static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf, static ssize_t codec_reg_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct snd_soc_pcm_runtime *rtd = - container_of(dev, struct snd_soc_pcm_runtime, dev); + struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0); } @@ -180,8 +179,7 @@ static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); static ssize_t pmdown_time_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct snd_soc_pcm_runtime *rtd = - container_of(dev, struct snd_soc_pcm_runtime, dev); + struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); return sprintf(buf, "%ld\n", rtd->pmdown_time); } @@ -190,8 +188,7 @@ static ssize_t pmdown_time_set(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct snd_soc_pcm_runtime *rtd = - container_of(dev, struct snd_soc_pcm_runtime, dev); + struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); int ret; ret = strict_strtol(buf, 10, &rtd->pmdown_time); @@ -884,9 +881,9 @@ static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order) /* unregister the rtd device */ if (rtd->dev_registered) { - device_remove_file(&rtd->dev, &dev_attr_pmdown_time); - device_remove_file(&rtd->dev, &dev_attr_codec_reg); - device_unregister(&rtd->dev); + device_remove_file(rtd->dev, &dev_attr_pmdown_time); + device_remove_file(rtd->dev, &dev_attr_codec_reg); + device_unregister(rtd->dev); rtd->dev_registered = 0; } @@ -1061,7 +1058,10 @@ err_probe: return ret; } -static void rtd_release(struct device *dev) {} +static void rtd_release(struct device *dev) +{ + kfree(dev); +} static int soc_post_component_init(struct snd_soc_card *card, struct snd_soc_codec *codec, @@ -1104,11 +1104,17 @@ static int soc_post_component_init(struct snd_soc_card *card, /* register the rtd device */ rtd->codec = codec; - rtd->dev.parent = card->dev; - rtd->dev.release = rtd_release; - rtd->dev.init_name = name; + + rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL); + if (!rtd->dev) + return -ENOMEM; + device_initialize(rtd->dev); + rtd->dev->parent = card->dev; + rtd->dev->release = rtd_release; + rtd->dev->init_name = name; + dev_set_drvdata(rtd->dev, rtd); mutex_init(&rtd->pcm_mutex); - ret = device_register(&rtd->dev); + ret = device_add(rtd->dev); if (ret < 0) { dev_err(card->dev, "asoc: failed to register runtime device: %d\n", ret); @@ -1117,14 +1123,14 @@ static int soc_post_component_init(struct snd_soc_card *card, rtd->dev_registered = 1; /* add DAPM sysfs entries for this codec */ - ret = snd_soc_dapm_sys_add(&rtd->dev); + ret = snd_soc_dapm_sys_add(rtd->dev); if (ret < 0) dev_err(codec->dev, "asoc: failed to add codec dapm sysfs entries: %d\n", ret); /* add codec sysfs entries */ - ret = device_create_file(&rtd->dev, &dev_attr_codec_reg); + ret = device_create_file(rtd->dev, &dev_attr_codec_reg); if (ret < 0) dev_err(codec->dev, "asoc: failed to add codec sysfs files: %d\n", ret); @@ -1213,7 +1219,7 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order) if (ret) return ret; - ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time); + ret = device_create_file(rtd->dev, &dev_attr_pmdown_time); if (ret < 0) printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n"); @@ -1311,8 +1317,8 @@ static void soc_remove_aux_dev(struct snd_soc_card *card, int num) /* unregister the rtd device */ if (rtd->dev_registered) { - device_remove_file(&rtd->dev, &dev_attr_codec_reg); - device_unregister(&rtd->dev); + device_remove_file(rtd->dev, &dev_attr_codec_reg); + device_del(rtd->dev); rtd->dev_registered = 0; } diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index e174d0811dae..3ad1f59b8028 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -1738,8 +1738,7 @@ static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, static ssize_t dapm_widget_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct snd_soc_pcm_runtime *rtd = - container_of(dev, struct snd_soc_pcm_runtime, dev); + struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); struct snd_soc_codec *codec =rtd->codec; struct snd_soc_dapm_widget *w; int count = 0; |