Message ID | 20240820050926.101-1-shenghao-ding@ti.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | ASoc: tas2781: replace devm_kzalloc and scnprintf with devm_kasprintf | expand |
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, "Speaker Profile Id"); These three do not use any formatting strings. Effectively it simply devm_kstrdup() in all cases. But see the Q below. > 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; > } > + 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?
Hi Andy Thanks for your comments. > -----Original Message----- > From: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > Sent: Tuesday, August 20, 2024 6:46 PM > To: Ding, Shenghao <shenghao-ding@ti.com> > Cc: broonie@kernel.org; lgirdwood@gmail.com; perex@perex.cz; pierre- > louis.bossart@linux.intel.com; 13916275206@139.com; zhourui@huaqin.com; > alsa-devel@alsa-project.org; Salazar, Ivan <i-salazar@ti.com>; > liam.r.girdwood@intel.com; Yue, Jaden <jaden-yue@ti.com>; yung- > chuan.liao@linux.intel.com; Rao, Dipa <dipa@ti.com>; yuhsuan@google.com; > Lo, Henry <henry.lo@ti.com>; tiwai@suse.de; Xu, Baojun <baojun.xu@ti.com>; > Baojun.Xu@fpt.com; judyhsiao@google.com; Navada Kanyana, Mukund > <navada@ti.com>; cujomalainey@google.com; Kutty, Aanya <aanya@ti.com>; > Mahmud, Nayeem <nayeem.mahmud@ti.com>; > savyasanchi.shukla@netradyne.com; flaviopr@microsoft.com; Ji, Jesse <jesse- > ji@ti.com>; darren.ye@mediatek.com; antheas.dk@gmail.com; > Jerry2.Huang@lcfuturecenter.com; jim.shil@goertek.com > 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 > 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, "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. > > > 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; > > } > > > + 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. > > -- > With Best Regards, > Andy Shevchenko >
diff --git a/sound/soc/codecs/tas2781-i2c.c b/sound/soc/codecs/tas2781-i2c.c index 9a32e0504857..1451ba0fa5b4 100644 --- a/sound/soc/codecs/tas2781-i2c.c +++ b/sound/soc/codecs/tas2781-i2c.c @@ -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;
Replace devm_kzalloc and scnprintf with devm_kasprintf. Signed-off-by: Shenghao Ding <shenghao-ding@ti.com> --- sound/soc/codecs/tas2781-i2c.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)