mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kyle Spiers <kyle@spiers.me>
To: perex@perex.cz
Cc: tiwai@suse.com, o-takashi@sakamocchi.jp,
	alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
	keescook@chromium.org, Kyle Spiers <kyle@spiers.me>
Subject: [PATCH] pcm_native: Remove VLA usage
Date: Wed, 28 Mar 2018 15:11:19 -0700	[thread overview]
Message-ID: <1522275079-2229-1-git-send-email-kyle@spiers.me> (raw)

As part of the effort to remove VLAs from the kernel[1], this changes
the allocation of the rstamps array from being on the stack to being
kcalloc()ed. This also allows for the removal of the explicit zeroing
loop.

[1] https://lkml.org/lkml/2018/3/7/621

Signed-off-by: Kyle Spiers <kyle@spiers.me>
---
 sound/core/pcm_native.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 77ba50d..57240b8 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -323,7 +323,7 @@ static int constrain_params_by_rules(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_constraints *constrs =
 					&substream->runtime->hw_constraints;
 	unsigned int k;
-	unsigned int rstamps[constrs->rules_num];
+	unsigned int *rstamps;
 	unsigned int vstamps[SNDRV_PCM_HW_PARAM_LAST_INTERVAL + 1];
 	unsigned int stamp;
 	struct snd_pcm_hw_rule *r;
@@ -339,8 +339,8 @@ static int constrain_params_by_rules(struct snd_pcm_substream *substream,
 	 * Each member of 'rstamps' array represents the sequence number of
 	 * recent application of corresponding rule.
 	 */
-	for (k = 0; k < constrs->rules_num; k++)
-		rstamps[k] = 0;
+
+	rstamps = kcalloc(constrs->rules_num, sizeof(*rstamps), GFP_KERNEL);
 
 	/*
 	 * Each member of 'vstamps' array represents the sequence number of
@@ -399,6 +399,7 @@ static int constrain_params_by_rules(struct snd_pcm_substream *substream,
 
 		changed = r->func(params, r);
 		if (changed < 0)
+			kfree(rstamps);
 			return changed;
 
 		/*
@@ -430,6 +431,7 @@ static int constrain_params_by_rules(struct snd_pcm_substream *substream,
 	if (again)
 		goto retry;
 
+	kfree(rstamps);
 	return 0;
 }
 
-- 
2.7.4

             reply	other threads:[~2018-03-28 22:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-28 22:11 Kyle Spiers [this message]
2018-03-28 22:14 ` Kees Cook
2018-03-30  0:07 ` kbuild test robot
2018-03-30  1:16 ` kbuild test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1522275079-2229-1-git-send-email-kyle@spiers.me \
    --to=kyle@spiers.me \
    --cc=alsa-devel@alsa-project.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=o-takashi@sakamocchi.jp \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®