aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-01-06 20:12:45 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-01-10 17:53:56 -0500
commit36ae1a96c4dcb0f6581d595cc5d43cf3a7e648c7 (patch)
treef0de43670060374bf9f2e81a4c2fcb65dc821545 /sound/soc
parente4e9e05409280b50003280afffe27ade21480dd7 (diff)
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/soc')
-rw-r--r--sound/soc/soc-core.c44
-rw-r--r--sound/soc/soc-dapm.c3
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,
169static ssize_t codec_reg_show(struct device *dev, 169static ssize_t codec_reg_show(struct device *dev,
170 struct device_attribute *attr, char *buf) 170 struct device_attribute *attr, char *buf)
171{ 171{
172 struct snd_soc_pcm_runtime *rtd = 172 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
173 container_of(dev, struct snd_soc_pcm_runtime, dev);
174 173
175 return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0); 174 return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
176} 175}
@@ -180,8 +179,7 @@ static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
180static ssize_t pmdown_time_show(struct device *dev, 179static ssize_t pmdown_time_show(struct device *dev,
181 struct device_attribute *attr, char *buf) 180 struct device_attribute *attr, char *buf)
182{ 181{
183 struct snd_soc_pcm_runtime *rtd = 182 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
184 container_of(dev, struct snd_soc_pcm_runtime, dev);
185 183
186 return sprintf(buf, "%ld\n", rtd->pmdown_time); 184 return sprintf(buf, "%ld\n", rtd->pmdown_time);
187} 185}
@@ -190,8 +188,7 @@ static ssize_t pmdown_time_set(struct device *dev,
190 struct device_attribute *attr, 188 struct device_attribute *attr,
191 const char *buf, size_t count) 189 const char *buf, size_t count)
192{ 190{
193 struct snd_soc_pcm_runtime *rtd = 191 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
194 container_of(dev, struct snd_soc_pcm_runtime, dev);
195 int ret; 192 int ret;
196 193
197 ret = strict_strtol(buf, 10, &rtd->pmdown_time); 194 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)
884 881
885 /* unregister the rtd device */ 882 /* unregister the rtd device */
886 if (rtd->dev_registered) { 883 if (rtd->dev_registered) {
887 device_remove_file(&rtd->dev, &dev_attr_pmdown_time); 884 device_remove_file(rtd->dev, &dev_attr_pmdown_time);
888 device_remove_file(&rtd->dev, &dev_attr_codec_reg); 885 device_remove_file(rtd->dev, &dev_attr_codec_reg);
889 device_unregister(&rtd->dev); 886 device_unregister(rtd->dev);
890 rtd->dev_registered = 0; 887 rtd->dev_registered = 0;
891 } 888 }
892 889
@@ -1061,7 +1058,10 @@ err_probe:
1061 return ret; 1058 return ret;
1062} 1059}
1063 1060
1064static void rtd_release(struct device *dev) {} 1061static void rtd_release(struct device *dev)
1062{
1063 kfree(dev);
1064}
1065 1065
1066static int soc_post_component_init(struct snd_soc_card *card, 1066static int soc_post_component_init(struct snd_soc_card *card,
1067 struct snd_soc_codec *codec, 1067 struct snd_soc_codec *codec,
@@ -1104,11 +1104,17 @@ static int soc_post_component_init(struct snd_soc_card *card,
1104 1104
1105 /* register the rtd device */ 1105 /* register the rtd device */
1106 rtd->codec = codec; 1106 rtd->codec = codec;
1107 rtd->dev.parent = card->dev; 1107
1108 rtd->dev.release = rtd_release; 1108 rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1109 rtd->dev.init_name = name; 1109 if (!rtd->dev)
1110 return -ENOMEM;
1111 device_initialize(rtd->dev);
1112 rtd->dev->parent = card->dev;
1113 rtd->dev->release = rtd_release;
1114 rtd->dev->init_name = name;
1115 dev_set_drvdata(rtd->dev, rtd);
1110 mutex_init(&rtd->pcm_mutex); 1116 mutex_init(&rtd->pcm_mutex);
1111 ret = device_register(&rtd->dev); 1117 ret = device_add(rtd->dev);
1112 if (ret < 0) { 1118 if (ret < 0) {
1113 dev_err(card->dev, 1119 dev_err(card->dev,
1114 "asoc: failed to register runtime device: %d\n", ret); 1120 "asoc: failed to register runtime device: %d\n", ret);
@@ -1117,14 +1123,14 @@ static int soc_post_component_init(struct snd_soc_card *card,
1117 rtd->dev_registered = 1; 1123 rtd->dev_registered = 1;
1118 1124
1119 /* add DAPM sysfs entries for this codec */ 1125 /* add DAPM sysfs entries for this codec */
1120 ret = snd_soc_dapm_sys_add(&rtd->dev); 1126 ret = snd_soc_dapm_sys_add(rtd->dev);
1121 if (ret < 0) 1127 if (ret < 0)
1122 dev_err(codec->dev, 1128 dev_err(codec->dev,
1123 "asoc: failed to add codec dapm sysfs entries: %d\n", 1129 "asoc: failed to add codec dapm sysfs entries: %d\n",
1124 ret); 1130 ret);
1125 1131
1126 /* add codec sysfs entries */ 1132 /* add codec sysfs entries */
1127 ret = device_create_file(&rtd->dev, &dev_attr_codec_reg); 1133 ret = device_create_file(rtd->dev, &dev_attr_codec_reg);
1128 if (ret < 0) 1134 if (ret < 0)
1129 dev_err(codec->dev, 1135 dev_err(codec->dev,
1130 "asoc: failed to add codec sysfs files: %d\n", ret); 1136 "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)
1213 if (ret) 1219 if (ret)
1214 return ret; 1220 return ret;
1215 1221
1216 ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time); 1222 ret = device_create_file(rtd->dev, &dev_attr_pmdown_time);
1217 if (ret < 0) 1223 if (ret < 0)
1218 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n"); 1224 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1219 1225
@@ -1311,8 +1317,8 @@ static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1311 1317
1312 /* unregister the rtd device */ 1318 /* unregister the rtd device */
1313 if (rtd->dev_registered) { 1319 if (rtd->dev_registered) {
1314 device_remove_file(&rtd->dev, &dev_attr_codec_reg); 1320 device_remove_file(rtd->dev, &dev_attr_codec_reg);
1315 device_unregister(&rtd->dev); 1321 device_del(rtd->dev);
1316 rtd->dev_registered = 0; 1322 rtd->dev_registered = 0;
1317 } 1323 }
1318 1324
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,
1738static ssize_t dapm_widget_show(struct device *dev, 1738static ssize_t dapm_widget_show(struct device *dev,
1739 struct device_attribute *attr, char *buf) 1739 struct device_attribute *attr, char *buf)
1740{ 1740{
1741 struct snd_soc_pcm_runtime *rtd = 1741 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
1742 container_of(dev, struct snd_soc_pcm_runtime, dev);
1743 struct snd_soc_codec *codec =rtd->codec; 1742 struct snd_soc_codec *codec =rtd->codec;
1744 struct snd_soc_dapm_widget *w; 1743 struct snd_soc_dapm_widget *w;
1745 int count = 0; 1744 int count = 0;