Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Dan Carpenter <dan.carpenter@linaro.org>,
	Mark Brown <broonie@kernel.org>, Sasha Levin <sashal@kernel.org>,
	kiseok.jo@irondevice.com, lgirdwood@gmail.com, perex@perex.cz,
	tiwai@suse.com, chenyuan0y@gmail.com,
	linux-sound@vger.kernel.org
Subject: [PATCH AUTOSEL 6.14 623/642] ASoC: sma1307: Fix error handling in sma1307_setting_loaded()
Date: Mon,  5 May 2025 18:13:59 -0400	[thread overview]
Message-ID: <20250505221419.2672473-623-sashal@kernel.org> (raw)
In-Reply-To: <20250505221419.2672473-1-sashal@kernel.org>

From: Dan Carpenter <dan.carpenter@linaro.org>

[ Upstream commit 012a6efcc805308b1d90a1056ba963eb08858645 ]

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: 0ec6bd16705f ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 sound/soc/codecs/sma1307.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/sound/soc/codecs/sma1307.c b/sound/soc/codecs/sma1307.c
index b9d8136fe3dc1..793abec56dd27 100644
--- a/sound/soc/codecs/sma1307.c
+++ b/sound/soc/codecs/sma1307.c
@@ -1710,7 +1710,7 @@ static void sma1307_check_fault_worker(struct work_struct *work)
 static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *file)
 {
 	const struct firmware *fw;
-	int *data, size, offset, num_mode;
+	int size, offset, num_mode;
 	int ret;
 
 	ret = request_firmware(&fw, file, sma1307->dev);
@@ -1727,7 +1727,7 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
 		return;
 	}
 
-	data = kzalloc(fw->size, GFP_KERNEL);
+	int *data __free(kfree) = kzalloc(fw->size, GFP_KERNEL);
 	if (!data) {
 		release_firmware(fw);
 		sma1307->set.status = false;
@@ -1747,7 +1747,6 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
 					   sma1307->set.header_size,
 					   GFP_KERNEL);
 	if (!sma1307->set.header) {
-		kfree(data);
 		sma1307->set.status = false;
 		return;
 	}
@@ -1768,8 +1767,6 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
 	    = devm_kzalloc(sma1307->dev,
 			   sma1307->set.def_size * sizeof(int), GFP_KERNEL);
 	if (!sma1307->set.def) {
-		kfree(data);
-		kfree(sma1307->set.header);
 		sma1307->set.status = false;
 		return;
 	}
@@ -1787,9 +1784,6 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
 				   sma1307->set.mode_size * 2 * sizeof(int),
 				   GFP_KERNEL);
 		if (!sma1307->set.mode_set[i]) {
-			kfree(data);
-			kfree(sma1307->set.header);
-			kfree(sma1307->set.def);
 			for (int j = 0; j < i; j++)
 				kfree(sma1307->set.mode_set[j]);
 			sma1307->set.status = false;
@@ -1804,7 +1798,6 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
 		}
 	}
 
-	kfree(data);
 	sma1307->set.status = true;
 
 }
-- 
2.39.5


      parent reply	other threads:[~2025-05-05 22:38 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250505221419.2672473-1-sashal@kernel.org>
2025-05-05 22:04 ` [PATCH AUTOSEL 6.14 036/642] ASoC: codecs: wsa884x: Correct VI sense channel mask Sasha Levin
2025-05-05 22:04 ` [PATCH AUTOSEL 6.14 037/642] ASoC: codecs: wsa883x: " Sasha Levin
2025-05-05 22:05 ` [PATCH AUTOSEL 6.14 136/642] ASoC: sma1307: Add NULL check in sma1307_setting_loaded() Sasha Levin
2025-05-05 22:05 ` [PATCH AUTOSEL 6.14 137/642] ASoC: pcm6240: Drop bogus code handling IRQ as GPIO Sasha Levin
2025-05-05 22:05 ` [PATCH AUTOSEL 6.14 138/642] ASoC: mediatek: mt6359: Add stub for mt6359_accdet_enable_jack_detect Sasha Levin
2025-05-05 22:06 ` [PATCH AUTOSEL 6.14 153/642] ASoC: sun4i-codec: support hp-det-gpios property Sasha Levin
2025-05-05 22:06 ` [PATCH AUTOSEL 6.14 154/642] ASoC: sun4i-codec: correct dapm widgets and controls for h616 Sasha Levin
2025-05-05 22:06 ` [PATCH AUTOSEL 6.14 201/642] ASoC: qcom: sm8250: explicitly set format in sm8250_be_hw_params_fixup() Sasha Levin
2025-05-05 22:07 ` [PATCH AUTOSEL 6.14 226/642] ALSA: seq: Improve data consistency at polling Sasha Levin
2025-05-05 22:08 ` [PATCH AUTOSEL 6.14 271/642] ALSA: hda/realtek: Enable PC beep passthrough for HP EliteBook 855 G7 Sasha Levin
2025-05-05 22:09 ` [PATCH AUTOSEL 6.14 327/642] ASoC: mediatek: mt8188: Treat DMIC_GAINx_CUR as non-volatile Sasha Levin
2025-05-05 22:09 ` [PATCH AUTOSEL 6.14 328/642] ASoC: mediatek: mt8188: Add reference for dmic clocks Sasha Levin
2025-05-05 22:10 ` [PATCH AUTOSEL 6.14 414/642] ASoC: ops: Enforce platform maximum on initial value Sasha Levin
2025-05-05 22:10 ` [PATCH AUTOSEL 6.14 415/642] ASoC: tas2764: Add reg defaults for TAS2764_INT_CLK_CFG Sasha Levin
2025-05-05 22:10 ` [PATCH AUTOSEL 6.14 416/642] ASoC: tas2764: Mark SW_RESET as volatile Sasha Levin
2025-05-05 22:10 ` [PATCH AUTOSEL 6.14 417/642] ASoC: tas2764: Power up/down amp on mute ops Sasha Levin
2025-05-05 22:10 ` [PATCH AUTOSEL 6.14 418/642] ASoC: soc-dai: check return value at snd_soc_dai_set_tdm_slot() Sasha Levin
2025-05-05 22:11 ` [PATCH AUTOSEL 6.14 453/642] soundwire: amd: change the soundwire wake enable/disable sequence Sasha Levin
2025-05-05 22:11 ` [PATCH AUTOSEL 6.14 454/642] soundwire: cadence_master: set frame shape and divider based on actual clk freq Sasha Levin
2025-05-05 22:13 ` [PATCH AUTOSEL 6.14 572/642] ASoC: codecs: pcm3168a: Allow for 24-bit in provider mode Sasha Levin
2025-05-05 22:13 ` [PATCH AUTOSEL 6.14 573/642] ASoC: soc-core: Stop using of_property_read_bool() for non-boolean properties Sasha Levin
2025-05-05 22:13 ` [PATCH AUTOSEL 6.14 574/642] ASoC: rt722-sdca: Add some missing readable registers Sasha Levin
2025-05-05 22:13 ` [PATCH AUTOSEL 6.14 591/642] ASoC: cpcap: Implement .set_bias_level Sasha Levin
2025-05-05 22:46   ` Mark Brown
2025-05-05 22:13 ` [PATCH AUTOSEL 6.14 601/642] ASoC: hdmi-codec: allow to refine formats actually supported Sasha Levin
2025-05-05 22:47   ` Mark Brown
2025-05-20 14:08     ` Sasha Levin
2025-05-05 22:13 ` Sasha Levin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250505221419.2672473-623-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=broonie@kernel.org \
    --cc=chenyuan0y@gmail.com \
    --cc=dan.carpenter@linaro.org \
    --cc=kiseok.jo@irondevice.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=stable@vger.kernel.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox