diff mbox series

[-next,1/2] ASoC: tas5805m: Use devm_kmemdup to replace devm_kmalloc + memcpy

Message ID 20230810114738.2103792-2-lizetao1@huawei.com (mailing list archive)
State Accepted
Commit b0a4c7f5921d9c2998bdd767a93d995786d72adc
Headers show
Series Use devm_kmemdup to replace devm_kmalloc + memcpy | expand

Commit Message

Li Zetao Aug. 10, 2023, 11:47 a.m. UTC
Use the helper function devm_kmemdup() rather than duplicating its
implementation, which helps to enhance code readability.

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 sound/soc/codecs/tas5805m.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Daniel Beer Aug. 10, 2023, 6:55 p.m. UTC | #1
On Thu, Aug 10, 2023 at 07:47:37PM +0800, Li Zetao wrote:
> -	tas5805m->dsp_cfg_data = devm_kmalloc(dev, fw->size, GFP_KERNEL);
> +	tas5805m->dsp_cfg_data = devm_kmemdup(dev, fw->data, fw->size, GFP_KERNEL);
>  	if (!tas5805m->dsp_cfg_data) {
>  		release_firmware(fw);
>  		return -ENOMEM;
>  	}
> -	memcpy(tas5805m->dsp_cfg_data, fw->data, fw->size);
>  
>  	release_firmware(fw);

You could probably now move the release_firmware call to be immediately
after the devm_kmemdup attempt, and avoid having to call it from two
different places.

Cheers,
Daniel
diff mbox series

Patch

diff --git a/sound/soc/codecs/tas5805m.c b/sound/soc/codecs/tas5805m.c
index aca3756ffab6..3b53eba38a0b 100644
--- a/sound/soc/codecs/tas5805m.c
+++ b/sound/soc/codecs/tas5805m.c
@@ -520,12 +520,11 @@  static int tas5805m_i2c_probe(struct i2c_client *i2c)
 	}
 
 	tas5805m->dsp_cfg_len = fw->size;
-	tas5805m->dsp_cfg_data = devm_kmalloc(dev, fw->size, GFP_KERNEL);
+	tas5805m->dsp_cfg_data = devm_kmemdup(dev, fw->data, fw->size, GFP_KERNEL);
 	if (!tas5805m->dsp_cfg_data) {
 		release_firmware(fw);
 		return -ENOMEM;
 	}
-	memcpy(tas5805m->dsp_cfg_data, fw->data, fw->size);
 
 	release_firmware(fw);