Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-sound@vger.kernel.org,
	Daniel Beer <daniel.beer@igorinstitute.com>,
	Jaroslav Kysela <perex@perex.cz>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Takashi Iwai <tiwai@suse.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Julia Lawall <julia.lawall@inria.fr>
Subject: [PATCH 1/2] ASoC: tas5805m: Use scope-based resource management in tas5805m_i2c_probe()
Date: Mon, 16 Sep 2024 10:48:18 +0200	[thread overview]
Message-ID: <d3b37bcd-2d62-4a1c-b4a9-d47be271cdc6@web.de> (raw)
In-Reply-To: <a7ce512c-0f82-47f6-89fb-f7269e4fdfae@web.de>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 16 Sep 2024 10:11:59 +0200

Scope-based resource management became supported also for another
programming interface by contributions of Dmitry Torokhov on 2024-01-17.
See also the commit 8dde8fa0cc3edce73c050b9882d06c1a575f6402
("firmware_loader: introduce __free() cleanup hanler").

* Thus use the attribute “__free(firmware)”.

* Reduce the scope for the local variable “fw”.

* Omit explicit release_firmware() calls accordingly.


This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 sound/soc/codecs/tas5805m.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/sound/soc/codecs/tas5805m.c b/sound/soc/codecs/tas5805m.c
index 3b53eba38a0b..f37eec960364 100644
--- a/sound/soc/codecs/tas5805m.c
+++ b/sound/soc/codecs/tas5805m.c
@@ -464,7 +464,6 @@ static int tas5805m_i2c_probe(struct i2c_client *i2c)
 	struct tas5805m_priv *tas5805m;
 	char filename[128];
 	const char *config_name;
-	const struct firmware *fw;
 	int ret;

 	regmap = devm_regmap_init_i2c(i2c, &tas5805m_regmap);
@@ -509,24 +508,24 @@ static int tas5805m_i2c_probe(struct i2c_client *i2c)

 	snprintf(filename, sizeof(filename), "tas5805m_dsp_%s.bin",
 		 config_name);
-	ret = request_firmware(&fw, filename, dev);
-	if (ret)
-		return ret;

-	if ((fw->size < 2) || (fw->size & 1)) {
-		dev_err(dev, "firmware is invalid\n");
-		release_firmware(fw);
-		return -EINVAL;
-	}
+	{
+		struct firmware const *fw __free(firmware) = NULL;

-	tas5805m->dsp_cfg_len = fw->size;
-	tas5805m->dsp_cfg_data = devm_kmemdup(dev, fw->data, fw->size, GFP_KERNEL);
-	if (!tas5805m->dsp_cfg_data) {
-		release_firmware(fw);
-		return -ENOMEM;
-	}
+		ret = request_firmware(&fw, filename, dev);
+		if (ret)
+			return ret;
+
+		if ((fw->size < 2) || (fw->size & 1)) {
+			dev_err(dev, "firmware is invalid\n");
+			return -EINVAL;
+		}

-	release_firmware(fw);
+		tas5805m->dsp_cfg_len = fw->size;
+		tas5805m->dsp_cfg_data = devm_kmemdup(dev, fw->data, fw->size, GFP_KERNEL);
+		if (!tas5805m->dsp_cfg_data)
+			return -ENOMEM;
+	}

 	/* Do the first part of the power-on here, while we can expect
 	 * the I2S interface to be quiet. We must raise PDN# and then
--
2.46.0


  reply	other threads:[~2024-09-16  8:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-16  8:38 [PATCH 0/2] ASoC: tas5805m: Adjustments for tas5805m_i2c_probe() Markus Elfring
2024-09-16  8:48 ` Markus Elfring [this message]
2024-09-16  8:50 ` [PATCH 2/2] ASoC: tas5805m: Improve a size determination in tas5805m_i2c_probe() Markus Elfring
2024-09-30 21:26 ` (subset) [PATCH 0/2] ASoC: tas5805m: Adjustments for tas5805m_i2c_probe() Mark Brown

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=d3b37bcd-2d62-4a1c-b4a9-d47be271cdc6@web.de \
    --to=markus.elfring@web.de \
    --cc=broonie@kernel.org \
    --cc=daniel.beer@igorinstitute.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=julia.lawall@inria.fr \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --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