Skip to content

Commit 012a6ef

Browse files
Dan Carpenterbroonie
authored andcommitted
ASoC: sma1307: Fix error handling in sma1307_setting_loaded()
There are a couple bugs in this code: 1) The cleanup code calls kfree(sma1307->set.header) and kfree(sma1307->set.def) but those functions were allocated using devm_kzalloc(). It results in a double free. Delete all these kfree() calls. 2) A missing call to kfree(data) if the checksum was wrong on this error path: if ((sma1307->set.checksum >> 8) != SMA1307_SETTING_CHECKSUM) { Since the "data" pointer is supposed to be freed on every return, I changed that to use the __free(kfree) cleanup attribute. Fixes: 0ec6bd1 ("ASoC: sma1307: Add NULL check in sma1307_setting_loaded()") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Link: https://patch.msgid.link/8d32dd96-1404-4373-9b6c-c612a9c18c4c@stanley.mountain Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 2593f7e commit 012a6ef

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

sound/soc/codecs/sma1307.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ static void sma1307_check_fault_worker(struct work_struct *work)
17051705
static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *file)
17061706
{
17071707
const struct firmware *fw;
1708-
int *data, size, offset, num_mode;
1708+
int size, offset, num_mode;
17091709
int ret;
17101710

17111711
ret = request_firmware(&fw, file, sma1307->dev);
@@ -1722,7 +1722,7 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
17221722
return;
17231723
}
17241724

1725-
data = kzalloc(fw->size, GFP_KERNEL);
1725+
int *data __free(kfree) = kzalloc(fw->size, GFP_KERNEL);
17261726
if (!data) {
17271727
release_firmware(fw);
17281728
sma1307->set.status = false;
@@ -1742,7 +1742,6 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
17421742
sma1307->set.header_size,
17431743
GFP_KERNEL);
17441744
if (!sma1307->set.header) {
1745-
kfree(data);
17461745
sma1307->set.status = false;
17471746
return;
17481747
}
@@ -1763,8 +1762,6 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
17631762
= devm_kzalloc(sma1307->dev,
17641763
sma1307->set.def_size * sizeof(int), GFP_KERNEL);
17651764
if (!sma1307->set.def) {
1766-
kfree(data);
1767-
kfree(sma1307->set.header);
17681765
sma1307->set.status = false;
17691766
return;
17701767
}
@@ -1782,9 +1779,6 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
17821779
sma1307->set.mode_size * 2 * sizeof(int),
17831780
GFP_KERNEL);
17841781
if (!sma1307->set.mode_set[i]) {
1785-
kfree(data);
1786-
kfree(sma1307->set.header);
1787-
kfree(sma1307->set.def);
17881782
for (int j = 0; j < i; j++)
17891783
kfree(sma1307->set.mode_set[j]);
17901784
sma1307->set.status = false;
@@ -1799,7 +1793,6 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
17991793
}
18001794
}
18011795

1802-
kfree(data);
18031796
sma1307->set.status = true;
18041797

18051798
}

0 commit comments

Comments
 (0)