[alsa-devel] [PATCH 0/5] ASoC: dapm: Adjustments for some function implementations

From: Markus Elfring elfring@users.sourceforge.net Date: Thu, 10 Aug 2017 14:54:32 +0200
A few update suggestions were taken into account from static source code analysis.
Markus Elfring (5): Delete error messages for a failed memory allocation in snd_soc_dapm_new_pcm() Improve a size determination in two functions Use kcalloc() in snd_soc_dapm_new_widgets() Adjust one function call together with a variable assignment Adjust seven checks for null pointers
sound/soc/soc-dapm.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-)

From: Markus Elfring elfring@users.sourceforge.net Date: Thu, 10 Aug 2017 14:09:19 +0200
Omit extra messages for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_S... Signed-off-by: Markus Elfring elfring@users.sourceforge.net --- sound/soc/soc-dapm.c | 4 ---- 1 file changed, 4 deletions(-)
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index dcef67a9bd48..3adb914bc009 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -3854,8 +3854,6 @@ int snd_soc_dapm_new_pcm(struct snd_soc_card *card, (void *)(kcontrol_dai_link[0].private_value), sizeof(struct soc_enum), GFP_KERNEL); if (!private_value) { - dev_err(card->dev, "ASoC: Failed to create control for %s widget\n", - link_name); ret = -ENOMEM; goto outfree_link_name; } @@ -3866,8 +3864,6 @@ int snd_soc_dapm_new_pcm(struct snd_soc_card *card, sizeof(struct snd_kcontrol_new), GFP_KERNEL); if (!template.kcontrol_news) { - dev_err(card->dev, "ASoC: Failed to create control for %s widget\n", - link_name); ret = -ENOMEM; goto outfree_private_value; }

From: Markus Elfring elfring@users.sourceforge.net Date: Thu, 10 Aug 2017 14:15:47 +0200
Replace the specification of data structures by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net --- sound/soc/soc-dapm.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 3adb914bc009..e673961210e6 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -2651,7 +2651,7 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm, if (ret) return ret;
- path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL); + path = kzalloc(sizeof(*path), GFP_KERNEL); if (!path) return -ENOMEM;
@@ -3859,10 +3859,9 @@ int snd_soc_dapm_new_pcm(struct snd_soc_card *card, } kcontrol_dai_link[0].private_value = private_value; /* duplicate kcontrol_dai_link on heap so that memory persists */ - template.kcontrol_news = - devm_kmemdup(card->dev, &kcontrol_dai_link[0], - sizeof(struct snd_kcontrol_new), - GFP_KERNEL); + template.kcontrol_news = devm_kmemdup(card->dev, &kcontrol_dai_link[0], + sizeof(*template.kcontrol_news), + GFP_KERNEL); if (!template.kcontrol_news) { ret = -ENOMEM; goto outfree_private_value;

From: Markus Elfring elfring@users.sourceforge.net Date: Thu, 10 Aug 2017 14:30:48 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kcalloc".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net --- sound/soc/soc-dapm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index e673961210e6..3fa9f023bff7 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -3027,9 +3027,9 @@ int snd_soc_dapm_new_widgets(struct snd_soc_card *card) continue;
if (w->num_kcontrols) { - w->kcontrols = kzalloc(w->num_kcontrols * - sizeof(struct snd_kcontrol *), - GFP_KERNEL); + w->kcontrols = kcalloc(w->num_kcontrols, + sizeof(*w->kcontrols), + GFP_KERNEL); if (!w->kcontrols) { mutex_unlock(&card->dapm_mutex); return -ENOMEM;

From: Markus Elfring elfring@users.sourceforge.net Date: Thu, 10 Aug 2017 14:34:35 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix the affected source code place.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net --- sound/soc/soc-dapm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 3fa9f023bff7..4eea84d821c4 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -3441,7 +3441,8 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm, const char *prefix; int ret;
- if ((w = dapm_cnew_widget(widget)) == NULL) + w = dapm_cnew_widget(widget); + if (!w) return NULL;
switch (w->id) {

From: Markus Elfring elfring@users.sourceforge.net Date: Thu, 10 Aug 2017 14:41:30 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit
The script “checkpatch.pl” pointed information out like the following.
Comparison to NULL could be written !…
Thus fix affected source code places.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net --- sound/soc/soc-dapm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 4eea84d821c4..5a85b8773289 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -146,7 +146,7 @@ static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...) return;
buf = kmalloc(PAGE_SIZE, GFP_KERNEL); - if (buf == NULL) + if (!buf) return;
va_start(args, fmt); @@ -883,7 +883,7 @@ static int dapm_create_or_share_kcontrol(struct snd_soc_dapm_widget *w, long_name = kasprintf(GFP_KERNEL, "%s %s", w->name + prefix_len, w->kcontrol_news[kci].name); - if (long_name == NULL) + if (!long_name) return -ENOMEM;
name = long_name; @@ -1086,7 +1086,7 @@ static int dapm_widget_list_create(struct snd_soc_dapm_widget_list **list, size++;
*list = kzalloc(sizeof(**list) + size * sizeof(*w), GFP_KERNEL); - if (*list == NULL) + if (!*list) return -ENOMEM;
list_for_each_entry(w, widgets, work_list) @@ -2668,7 +2668,7 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm, path->is_supply = 1;
/* connect static paths */ - if (control == NULL) { + if (!control) { path->connect = 1; } else { switch (wsource->id) { @@ -2777,12 +2777,12 @@ static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm, if (!wsource) wsource = wtsource;
- if (wsource == NULL) { + if (!wsource) { dev_err(dapm->dev, "ASoC: no source widget found for %s\n", route->source); return -ENODEV; } - if (wsink == NULL) { + if (!wsink) { dev_err(dapm->dev, "ASoC: no sink widget found for %s\n", route->sink); return -ENODEV; @@ -3489,7 +3489,7 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm, w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, widget->name); else w->name = kstrdup_const(widget->name, GFP_KERNEL); - if (w->name == NULL) { + if (!w->name) { kfree(w); return NULL; }
participants (1)
-
SF Markus Elfring