All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: pcm: Use krealloc() for resizing the rules array
@ 2018-03-13 11:42 Takashi Iwai
  2018-03-13 14:17 ` Takashi Sakamoto
  0 siblings, 1 reply; 2+ messages in thread
From: Takashi Iwai @ 2018-03-13 11:42 UTC (permalink / raw)
  To: alsa-devel

Just a minor simplification.  Change from kcalloc() shouldn't matter
as each array element is fully initialized.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/core/pcm_lib.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index a83152e7d387..f4a19509cccf 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -1129,16 +1129,12 @@ int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, unsigned int cond,
 	if (constrs->rules_num >= constrs->rules_all) {
 		struct snd_pcm_hw_rule *new;
 		unsigned int new_rules = constrs->rules_all + 16;
-		new = kcalloc(new_rules, sizeof(*c), GFP_KERNEL);
+		new = krealloc(constrs->rules, new_rules * sizeof(*c),
+			       GFP_KERNEL);
 		if (!new) {
 			va_end(args);
 			return -ENOMEM;
 		}
-		if (constrs->rules) {
-			memcpy(new, constrs->rules,
-			       constrs->rules_num * sizeof(*c));
-			kfree(constrs->rules);
-		}
 		constrs->rules = new;
 		constrs->rules_all = new_rules;
 	}
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: pcm: Use krealloc() for resizing the rules array
  2018-03-13 11:42 [PATCH] ALSA: pcm: Use krealloc() for resizing the rules array Takashi Iwai
@ 2018-03-13 14:17 ` Takashi Sakamoto
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Sakamoto @ 2018-03-13 14:17 UTC (permalink / raw)
  To: Takashi Iwai, alsa-devel

Hi,

On Mar 13 2018 20:42, Takashi Iwai wrote:
> Just a minor simplification.  Change from kcalloc() shouldn't matter
> as each array element is fully initialized.
> 
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
>   sound/core/pcm_lib.c | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)

I think this is a good simplification and preferable, too. Some local 
variables in this block could be replaced by assignment but for 
readability it's better to keep them as is, in my opinion.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>

> diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
> index a83152e7d387..f4a19509cccf 100644
> --- a/sound/core/pcm_lib.c
> +++ b/sound/core/pcm_lib.c
> @@ -1129,16 +1129,12 @@ int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, unsigned int cond,
>   	if (constrs->rules_num >= constrs->rules_all) {
>   		struct snd_pcm_hw_rule *new;
>   		unsigned int new_rules = constrs->rules_all + 16;
> -		new = kcalloc(new_rules, sizeof(*c), GFP_KERNEL);
> +		new = krealloc(constrs->rules, new_rules * sizeof(*c),
> +			       GFP_KERNEL);
>   		if (!new) {
>   			va_end(args);
>   			return -ENOMEM;
>   		}
> -		if (constrs->rules) {
> -			memcpy(new, constrs->rules,
> -			       constrs->rules_num * sizeof(*c));
> -			kfree(constrs->rules);
> -		}
>   		constrs->rules = new;
>   		constrs->rules_all = new_rules;
>   	}

Regards

Takashi Sakamoto

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-03-13 14:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-13 11:42 [PATCH] ALSA: pcm: Use krealloc() for resizing the rules array Takashi Iwai
2018-03-13 14:17 ` Takashi Sakamoto

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.