Skip to content

Commit d484366

Browse files
AxelLinbroonie
authored andcommitted
ASoC: wm8978: fix a memory leak if a wm8978_register fail
There is a memory leak found if wm8978_register() fail. This patch moves the buffer allocate and release at the same level to prevent the memory leak. Signed-off-by: Axel Lin <[email protected]> Reviewed-by: Guennadi Liakhovetski <[email protected]> Acked-by: Liam Girdwood <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 4eaac50 commit d484366

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

sound/soc/codecs/wm8978.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,6 @@ static __devinit int wm8978_register(struct wm8978_priv *wm8978)
10761076
err_codec:
10771077
snd_soc_unregister_codec(codec);
10781078
err:
1079-
kfree(wm8978);
10801079
return ret;
10811080
}
10821081

@@ -1085,13 +1084,13 @@ static __devexit void wm8978_unregister(struct wm8978_priv *wm8978)
10851084
wm8978_set_bias_level(&wm8978->codec, SND_SOC_BIAS_OFF);
10861085
snd_soc_unregister_dai(&wm8978_dai);
10871086
snd_soc_unregister_codec(&wm8978->codec);
1088-
kfree(wm8978);
10891087
wm8978_codec = NULL;
10901088
}
10911089

10921090
static __devinit int wm8978_i2c_probe(struct i2c_client *i2c,
10931091
const struct i2c_device_id *id)
10941092
{
1093+
int ret;
10951094
struct wm8978_priv *wm8978;
10961095
struct snd_soc_codec *codec;
10971096

@@ -1107,13 +1106,18 @@ static __devinit int wm8978_i2c_probe(struct i2c_client *i2c,
11071106

11081107
codec->dev = &i2c->dev;
11091108

1110-
return wm8978_register(wm8978);
1109+
ret = wm8978_register(wm8978);
1110+
if (ret < 0)
1111+
kfree(wm8978);
1112+
1113+
return ret;
11111114
}
11121115

11131116
static __devexit int wm8978_i2c_remove(struct i2c_client *client)
11141117
{
11151118
struct wm8978_priv *wm8978 = i2c_get_clientdata(client);
11161119
wm8978_unregister(wm8978);
1120+
kfree(wm8978);
11171121
return 0;
11181122
}
11191123

0 commit comments

Comments
 (0)