ASoC: tas5805m: Adjustments for tas5805m_i2c_probe()
cover ASoC: tas5805m: Adjustments for tas5805m_i2c_probe()
From: Markus Elfring <[email protected]>
Date: Mon, 16 Sep 2024 10:30:10 +0200
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (2):
Use scope-based resource management
Improve a size determination
sound/soc/codecs/tas5805m.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
--
2.46.0
PATCH 1/2 ASoC: tas5805m: Use scope-based resource management in tas5805m_i2c_probe()
From: Markus Elfring <[email protected]>
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.
--- sound/soc/codecs/tas5805m.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
sound/soc/codecs/tas5805m.c +15 -16
@@ -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
PATCH 2/2 ASoC: tas5805m: Improve a size determination in tas5805m_i2c_probe()
In reply to Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 16 Sep 2024 10:20:12 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- sound/soc/codecs/tas5805m.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/tas5805m.c +1 -1
@@ -473,7 +473,7 @@ static int tas5805m_i2c_probe(struct i2c_client *i2c)return ret; } - tas5805m =devm_kzalloc (dev,sizeof (struct tas5805m_priv ),GFP_KERNEL ); + tas5805m =devm_kzalloc (dev,sizeof (*tas5805m),GFP_KERNEL );if (!tas5805m)return -ENOMEM ;
--
2.46.0
Mark Brown
maintainerRe: (subset) [PATCH 0/2] ASoC: tas5805m: Adjustments for tas5805m_i2c_probe()
In reply to Markus ElfringQuoted 8 lines · Markus Elfring
A few update suggestions were taken into account
from static source code analysis.Markus Elfring (2):
Use scope-based resource management
Improve a size determination[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[2/2] ASoC: tas5805m: Improve a size determination in tas5805m_i2c_probe()
commit: 0e9f73f109025f0d5d16b104b6684e6c03aa0c83
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark