Skip to contentSkip to conversation

sound: soc: fix invalid free of devm_ allocated data

PATCH In review Silviu-Mihai Popescu 2 participants 3 messages Mar 16, 2013 – Mar 20, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sound: soc: fix invalid free of devm_ allocated data

The objects allocated by devm_* APIs are managed by devres and are freed when the device is detached. Hence there is no need to use kfree() explicitly.

---
 sound/soc/soc-core.c |    2 --
 1 file changed, 2 deletions(-)
sound/soc/soc-core.c +0 -2
index b7e84a7..407b0a3 100644
@@ -4197,7 +4197,6 @@ int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
 			dev_err(card->dev,
 				"ASoC: Property '%s' index %d could not be read: %d\n",
 				propname, 2 * i, ret);
-			kfree(routes);
 			return -EINVAL;
 		}
 		ret = of_property_read_string_index(np, propname,
@@ -4206,7 +4205,6 @@ int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
 			dev_err(card->dev,
 				"ASoC: Property '%s' index %d could not be read: %d\n",
 				propname, (2 * i) + 1, ret);
-			kfree(routes);
 			return -EINVAL;
 		}
 	}
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 2 lines · Silviu-Mihai Popescu

The objects allocated by devm_* APIs are managed by devres and are freed when the device is detached. Hence there is no need to use kfree() explicitly.

In this case since we're in error handling paths which might not be fatal (though I suspect they probably should be normally) it looks like the better fix is to use devm_kfree() to free immediately. Otherwise the unused memory will end up hanging around for as long as the device is bound.

#2 lore raw
In reply to Silviu-Mihai Popescu
Quoted 2 lines · Silviu-Mihai Popescu

The objects allocated by devm_* APIs are managed by devres and are freed when the device is detached. Hence there is no need to use kfree() explicitly.

...but I applied this anyway since it's clearly an improvement and a small leak is better than a crash.