Skip to contentSkip to conversation

ASoc: tas2781: replace devm_kzalloc and scnprintf with devm_kasprintf

PATCH Superseded Shenghao Ding 2 participants 3 messages Aug 20, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Shenghao Ding

author maintainer
#0 lore raw

PATCH 1/1 ASoc: tas2781: replace devm_kzalloc and scnprintf with devm_kasprintf

Replace devm_kzalloc and scnprintf with devm_kasprintf.

---
 sound/soc/codecs/tas2781-i2c.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
sound/soc/codecs/tas2781-i2c.c +10 -13
index 9a32e0504857..1451ba0fa5b4 100644
@@ -346,13 +346,11 @@ static int tasdevice_create_control(struct tasdevice_priv *tas_priv)
 	}
 
 	/* Create a mixer item for selecting the active profile */
-	name = devm_kzalloc(tas_priv->dev, SNDRV_CTL_ELEM_ID_NAME_MAXLEN,
-		GFP_KERNEL);
+	name = devm_kasprintf(tas_priv->dev, GFP_KERNEL, "Speaker Profile Id");
 	if (!name) {
 		ret = -ENOMEM;
 		goto out;
 	}
-	scnprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "Speaker Profile Id");
 	prof_ctrls[mix_index].name = name;
 	prof_ctrls[mix_index].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
 	prof_ctrls[mix_index].info = tasdevice_info_profile;
@@ -441,18 +439,13 @@ static int tasdevice_dsp_create_ctrls(struct tasdevice_priv *tas_priv)
 		goto out;
 	}
 
-	/* Create a mixer item for selecting the active profile */
-	prog_name = devm_kzalloc(tas_priv->dev,
-		SNDRV_CTL_ELEM_ID_NAME_MAXLEN, GFP_KERNEL);
-	conf_name = devm_kzalloc(tas_priv->dev, SNDRV_CTL_ELEM_ID_NAME_MAXLEN,
-		GFP_KERNEL);
-	if (!prog_name || !conf_name) {
+	/* Create mixer items for selecting the active Program and Config */
+	prog_name = devm_kasprintf(tas_priv->dev, GFP_KERNEL,
+		"Speaker Program Id");
+	if (!prog_name) {
 		ret = -ENOMEM;
 		goto out;
 	}
-
-	scnprintf(prog_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN,
-		"Speaker Program Id");
 	dsp_ctrls[mix_index].name = prog_name;
 	dsp_ctrls[mix_index].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
 	dsp_ctrls[mix_index].info = tasdevice_info_programs;
@@ -460,8 +453,12 @@ static int tasdevice_dsp_create_ctrls(struct tasdevice_priv *tas_priv)
 	dsp_ctrls[mix_index].put = tasdevice_program_put;
 	mix_index++;
 
-	scnprintf(conf_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN,
+	conf_name = devm_kasprintf(tas_priv->dev, GFP_KERNEL,
 		"Speaker Config Id");
+	if (!conf_name) {
+		ret = -ENOMEM;
+		goto out;
+	}
 	dsp_ctrls[mix_index].name = conf_name;
 	dsp_ctrls[mix_index].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
 	dsp_ctrls[mix_index].info = tasdevice_info_configurations;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 1 line · Shenghao Ding

Replace devm_kzalloc and scnprintf with devm_kasprintf.

We refer to functions as func() [mind the parentheses].

...

sound/soc/codecs/tas2781-i2c.c static int tasdevice_create_control(struct tasdevice_priv *tas_priv) · line 349

Quoted 1 line
sound/soc/codecs/tas2781-i2c.c +1 -0
+	name = devm_kasprintf(tas_priv->dev, GFP_KERNEL, "Speaker Profile Id");

These three do not use any formatting strings. Effectively it simply devm_kstrdup() in all cases. But see the Q below.

Quoted 9 lines
sound/soc/codecs/tas2781-i2c.c +4 -0
 	if (!name) {
 		ret = -ENOMEM;
 		goto out;
 	}
 
+	/* Create mixer items for selecting the active Program and Config */
+	prog_name = devm_kasprintf(tas_priv->dev, GFP_KERNEL,
+		"Speaker Program Id");
+	if (!prog_name) {

sound/soc/codecs/tas2781-i2c.c static int tasdevice_dsp_create_ctrls(struct tasdevice_priv *tas_priv)

Quoted 10 lines
sound/soc/codecs/tas2781-i2c.c +5 -0
 		ret = -ENOMEM;
 		goto out;
 	}
 
+	conf_name = devm_kasprintf(tas_priv->dev, GFP_KERNEL,
 		"Speaker Config Id");
+	if (!conf_name) {
+		ret = -ENOMEM;
+		goto out;
+	}

So, why all these may not be constant literals assigned directly to the respective data structures?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#2 lore raw

Hi Andy
Thanks for your comments.

Quoted 37 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Tuesday, August 20, 2024 6:46 PM
To: Ding, Shenghao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; pierre- [email protected]; [email protected]; [email protected]; [email protected]; Salazar, Ivan <[email protected]>; [email protected]; Yue, Jaden <[email protected]>; yung- [email protected]; Rao, Dipa <[email protected]>; [email protected]; Lo, Henry <[email protected]>; [email protected]; Xu, Baojun <[email protected]>; [email protected]; [email protected]; Navada Kanyana, Mukund <[email protected]>; [email protected]; Kutty, Aanya <[email protected]>; Mahmud, Nayeem <[email protected]>; [email protected]; [email protected]; Ji, Jesse <jesse- [email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXTERNAL] Re: [PATCH] ASoc: tas2781: replace devm_kzalloc and scnprintf with devm_kasprintf

On Tue, Aug 20, 2024 at 01: 09: 24PM +0800, Shenghao Ding wrote: > Replace devm_kzalloc and scnprintf with devm_kasprintf. We refer to functions as func() [mind the parentheses]. .. . > + name = devm_kasprintf(tas_priv->dev, GFP_KERNEL, ZjQcmQRYFpfptBannerStart This message was sent from outside of Texas Instruments.
Do not click links or open attachments unless you recognize the source of this email and know the content is safe.
<https://us-phishalarm-
ewt.proofpoint.com/EWT/v1/G3vK!uBdnVXvGNoHUwG8oNvKLEKxWzmhYG82 GpsitRhNsb0P1mOVL0znkPABZUh4PJ5lEeMlWbeMkT3aHKGSKjzs$>
Report Suspicious

ZjQcmQRYFpfptBannerEnd

Quoted 1 line · Shenghao Ding

Replace devm_kzalloc and scnprintf with devm_kasprintf.

We refer to functions as func() [mind the parentheses].

Quoted 7 lines

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+	name = devm_kasprintf(tas_priv->dev, GFP_KERNEL, "Speaker Profile
+Id");

These three do not use any formatting strings. Effectively it simply devm_kstrdup() in all cases. But see the Q below.

Accept.

Quoted 14 lines
Quoted 13 lines
sound/soc/codecs/tas2781-i2c.c +4 -0
 	if (!name) {
 		ret = -ENOMEM;
 		goto out;
 	}
 
+	/* Create mixer items for selecting the active Program and Config */
+	prog_name = devm_kasprintf(tas_priv->dev, GFP_KERNEL,
+		"Speaker Program Id");
+	if (!prog_name) {
 		ret = -ENOMEM;
 		goto out;
 	}
Quoted 9 lines

sound/soc/codecs/tas2781-i2c.c static int tasdevice_dsp_create_ctrls(struct tasdevice_priv *tas_priv) · line 461

Quoted 6 lines
sound/soc/codecs/tas2781-i2c.c +5 -0
+	conf_name = devm_kasprintf(tas_priv->dev, GFP_KERNEL,
 		"Speaker Config Id");
+	if (!conf_name) {
+		ret = -ENOMEM;
+		goto out;
+	}

So, why all these may not be constant literals assigned directly to the respective data structures?

The total of Profile, config and program are different with the bin file. It can't be set to the fixed value.

Quoted 5 lines

--
With Best Regards,
Andy Shevchenko