Re: [PATCH] pcm_native: Remove VLA usage

2018-03-29 Thread kbuild test robot
Hi Kyle,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on v4.16-rc7]
[cannot apply to sound/for-next next-20180329]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Kyle-Spiers/pcm_native-Remove-VLA-usage/20180330-073734
config: x86_64-randconfig-x019-201812 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   In file included from include/asm-generic/bug.h:5:0,
from arch/x86/include/asm/bug.h:83,
from include/linux/bug.h:5,
from include/linux/mmdebug.h:5,
from include/linux/mm.h:9,
from sound/core/pcm_native.c:22:
   sound/core/pcm_native.c: In function 'constrain_params_by_rules':
   include/linux/compiler.h:58:2: warning: this 'if' clause does not guard... 
[-Wmisleading-indentation]
 if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
 ^
   include/linux/compiler.h:56:23: note: in expansion of macro '__trace_if'
#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
  ^~
>> sound/core/pcm_native.c:401:3: note: in expansion of macro 'if'
  if (changed < 0)
  ^~
   sound/core/pcm_native.c:403:4: note: ...this statement, but the latter is 
misleadingly indented as if it were guarded by the 'if'
   return changed;
   ^~

vim +/if +401 sound/core/pcm_native.c

^1da177e4 Linus Torvalds   2005-04-16  319  
9cc07f55d Takashi Sakamoto 2017-06-09  320  static int 
constrain_params_by_rules(struct snd_pcm_substream *substream,
877211f5e Takashi Iwai 2005-11-17  321   
struct snd_pcm_hw_params *params)
^1da177e4 Linus Torvalds   2005-04-16  322  {
9cc07f55d Takashi Sakamoto 2017-06-09  323  struct snd_pcm_hw_constraints 
*constrs =
9cc07f55d Takashi Sakamoto 2017-06-09  324  
>runtime->hw_constraints;
^1da177e4 Linus Torvalds   2005-04-16  325  unsigned int k;
16c438ade Kyle Spiers  2018-03-28  326  unsigned int *rstamps;
^1da177e4 Linus Torvalds   2005-04-16  327  unsigned int 
vstamps[SNDRV_PCM_HW_PARAM_LAST_INTERVAL + 1];
d81052f92 Takashi Sakamoto 2017-06-09  328  unsigned int stamp;
a1c06e39a Takashi Sakamoto 2017-06-09  329  struct snd_pcm_hw_rule *r;
a1c06e39a Takashi Sakamoto 2017-06-09  330  unsigned int d;
9cc07f55d Takashi Sakamoto 2017-06-09  331  struct snd_mask old_mask;
9cc07f55d Takashi Sakamoto 2017-06-09  332  struct snd_interval 
old_interval;
a1c06e39a Takashi Sakamoto 2017-06-09  333  bool again;
9cc07f55d Takashi Sakamoto 2017-06-09  334  int changed;
^1da177e4 Linus Torvalds   2005-04-16  335  
d81052f92 Takashi Sakamoto 2017-06-09  336  /*
d81052f92 Takashi Sakamoto 2017-06-09  337   * Each application of rule has 
own sequence number.
d81052f92 Takashi Sakamoto 2017-06-09  338   *
d81052f92 Takashi Sakamoto 2017-06-09  339   * Each member of 'rstamps' 
array represents the sequence number of
d81052f92 Takashi Sakamoto 2017-06-09  340   * recent application of 
corresponding rule.
d81052f92 Takashi Sakamoto 2017-06-09  341   */
16c438ade Kyle Spiers  2018-03-28  342  
16c438ade Kyle Spiers  2018-03-28  343  rstamps = 
kcalloc(constrs->rules_num, sizeof(*rstamps), GFP_KERNEL);
d81052f92 Takashi Sakamoto 2017-06-09  344  
d81052f92 Takashi Sakamoto 2017-06-09  345  /*
d81052f92 Takashi Sakamoto 2017-06-09  346   * Each member of 'vstamps' 
array represents the sequence number of
d81052f92 Takashi Sakamoto 2017-06-09  347   * recent application of rule 
in which corresponding parameters were
d81052f92 Takashi Sakamoto 2017-06-09  348   * changed.
d81052f92 Takashi Sakamoto 2017-06-09  349   *
d81052f92 Takashi Sakamoto 2017-06-09  350   * In initial state, elements 
corresponding to parameters requested by
d81052f92 Takashi Sakamoto 2017-06-09  351   * a caller is 1. For 
unrequested parameters, corresponding members
d81052f92 Takashi Sakamoto 2017-06-09  352   * have 0 so that the 
parameters are never changed anymore.
d81052f92 Takashi Sakamoto 2017-06-09  353   */
^1da177e4 Linus Torvalds   2005-04-16  354  for (k = 0; k <= 
SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++)
^1da177e4 Linus Torvalds   2005-04-16  355  vstamps[k] = 
(params->rmask & (1 << k)) ? 1 : 0;
d81052f92 Takashi Sakamoto 2017-06-09  356  
d81052f92 Takashi Sakamoto 2017-06-09  357  /* Due to the above design, 
actual sequence number starts at 2. */
d81052f92 Takashi Sakamoto 2017-06-09  358  stamp = 2;
0d4e39996 Takashi Sakamoto 2017-06-09  359  retry:
d81052f92 Takashi Sakamoto 2017-06-09  360  /* Apply all rules in order. */
a1c06e39a Takashi Sakamoto 2017-06-09  361 

Re: [PATCH] pcm_native: Remove VLA usage

2018-03-29 Thread kbuild test robot
Hi Kyle,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on v4.16-rc7]
[cannot apply to sound/for-next next-20180329]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Kyle-Spiers/pcm_native-Remove-VLA-usage/20180330-073734
config: x86_64-randconfig-x019-201812 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   In file included from include/asm-generic/bug.h:5:0,
from arch/x86/include/asm/bug.h:83,
from include/linux/bug.h:5,
from include/linux/mmdebug.h:5,
from include/linux/mm.h:9,
from sound/core/pcm_native.c:22:
   sound/core/pcm_native.c: In function 'constrain_params_by_rules':
   include/linux/compiler.h:58:2: warning: this 'if' clause does not guard... 
[-Wmisleading-indentation]
 if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
 ^
   include/linux/compiler.h:56:23: note: in expansion of macro '__trace_if'
#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
  ^~
>> sound/core/pcm_native.c:401:3: note: in expansion of macro 'if'
  if (changed < 0)
  ^~
   sound/core/pcm_native.c:403:4: note: ...this statement, but the latter is 
misleadingly indented as if it were guarded by the 'if'
   return changed;
   ^~

vim +/if +401 sound/core/pcm_native.c

^1da177e4 Linus Torvalds   2005-04-16  319  
9cc07f55d Takashi Sakamoto 2017-06-09  320  static int 
constrain_params_by_rules(struct snd_pcm_substream *substream,
877211f5e Takashi Iwai 2005-11-17  321   
struct snd_pcm_hw_params *params)
^1da177e4 Linus Torvalds   2005-04-16  322  {
9cc07f55d Takashi Sakamoto 2017-06-09  323  struct snd_pcm_hw_constraints 
*constrs =
9cc07f55d Takashi Sakamoto 2017-06-09  324  
>runtime->hw_constraints;
^1da177e4 Linus Torvalds   2005-04-16  325  unsigned int k;
16c438ade Kyle Spiers  2018-03-28  326  unsigned int *rstamps;
^1da177e4 Linus Torvalds   2005-04-16  327  unsigned int 
vstamps[SNDRV_PCM_HW_PARAM_LAST_INTERVAL + 1];
d81052f92 Takashi Sakamoto 2017-06-09  328  unsigned int stamp;
a1c06e39a Takashi Sakamoto 2017-06-09  329  struct snd_pcm_hw_rule *r;
a1c06e39a Takashi Sakamoto 2017-06-09  330  unsigned int d;
9cc07f55d Takashi Sakamoto 2017-06-09  331  struct snd_mask old_mask;
9cc07f55d Takashi Sakamoto 2017-06-09  332  struct snd_interval 
old_interval;
a1c06e39a Takashi Sakamoto 2017-06-09  333  bool again;
9cc07f55d Takashi Sakamoto 2017-06-09  334  int changed;
^1da177e4 Linus Torvalds   2005-04-16  335  
d81052f92 Takashi Sakamoto 2017-06-09  336  /*
d81052f92 Takashi Sakamoto 2017-06-09  337   * Each application of rule has 
own sequence number.
d81052f92 Takashi Sakamoto 2017-06-09  338   *
d81052f92 Takashi Sakamoto 2017-06-09  339   * Each member of 'rstamps' 
array represents the sequence number of
d81052f92 Takashi Sakamoto 2017-06-09  340   * recent application of 
corresponding rule.
d81052f92 Takashi Sakamoto 2017-06-09  341   */
16c438ade Kyle Spiers  2018-03-28  342  
16c438ade Kyle Spiers  2018-03-28  343  rstamps = 
kcalloc(constrs->rules_num, sizeof(*rstamps), GFP_KERNEL);
d81052f92 Takashi Sakamoto 2017-06-09  344  
d81052f92 Takashi Sakamoto 2017-06-09  345  /*
d81052f92 Takashi Sakamoto 2017-06-09  346   * Each member of 'vstamps' 
array represents the sequence number of
d81052f92 Takashi Sakamoto 2017-06-09  347   * recent application of rule 
in which corresponding parameters were
d81052f92 Takashi Sakamoto 2017-06-09  348   * changed.
d81052f92 Takashi Sakamoto 2017-06-09  349   *
d81052f92 Takashi Sakamoto 2017-06-09  350   * In initial state, elements 
corresponding to parameters requested by
d81052f92 Takashi Sakamoto 2017-06-09  351   * a caller is 1. For 
unrequested parameters, corresponding members
d81052f92 Takashi Sakamoto 2017-06-09  352   * have 0 so that the 
parameters are never changed anymore.
d81052f92 Takashi Sakamoto 2017-06-09  353   */
^1da177e4 Linus Torvalds   2005-04-16  354  for (k = 0; k <= 
SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++)
^1da177e4 Linus Torvalds   2005-04-16  355  vstamps[k] = 
(params->rmask & (1 << k)) ? 1 : 0;
d81052f92 Takashi Sakamoto 2017-06-09  356  
d81052f92 Takashi Sakamoto 2017-06-09  357  /* Due to the above design, 
actual sequence number starts at 2. */
d81052f92 Takashi Sakamoto 2017-06-09  358  stamp = 2;
0d4e39996 Takashi Sakamoto 2017-06-09  359  retry:
d81052f92 Takashi Sakamoto 2017-06-09  360  /* Apply all rules in order. */
a1c06e39a Takashi Sakamoto 2017-06-09  361 

Re: [PATCH] pcm_native: Remove VLA usage

2018-03-29 Thread kbuild test robot
Hi Kyle,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on v4.16-rc7]
[cannot apply to sound/for-next next-20180329]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Kyle-Spiers/pcm_native-Remove-VLA-usage/20180330-073734
config: i386-randconfig-x075-201812 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All warnings (new ones prefixed by >>):

   sound/core/pcm_native.c: In function 'constrain_params_by_rules':
>> sound/core/pcm_native.c:401:3: warning: this 'if' clause does not guard... 
>> [-Wmisleading-indentation]
  if (changed < 0)
  ^~
   sound/core/pcm_native.c:403:4: note: ...this statement, but the latter is 
misleadingly indented as if it were guarded by the 'if'
   return changed;
   ^~

vim +/if +401 sound/core/pcm_native.c

^1da177e4 Linus Torvalds   2005-04-16  319  
9cc07f55d Takashi Sakamoto 2017-06-09  320  static int 
constrain_params_by_rules(struct snd_pcm_substream *substream,
877211f5e Takashi Iwai 2005-11-17  321   
struct snd_pcm_hw_params *params)
^1da177e4 Linus Torvalds   2005-04-16  322  {
9cc07f55d Takashi Sakamoto 2017-06-09  323  struct snd_pcm_hw_constraints 
*constrs =
9cc07f55d Takashi Sakamoto 2017-06-09  324  
>runtime->hw_constraints;
^1da177e4 Linus Torvalds   2005-04-16  325  unsigned int k;
16c438ade Kyle Spiers  2018-03-28  326  unsigned int *rstamps;
^1da177e4 Linus Torvalds   2005-04-16  327  unsigned int 
vstamps[SNDRV_PCM_HW_PARAM_LAST_INTERVAL + 1];
d81052f92 Takashi Sakamoto 2017-06-09  328  unsigned int stamp;
a1c06e39a Takashi Sakamoto 2017-06-09  329  struct snd_pcm_hw_rule *r;
a1c06e39a Takashi Sakamoto 2017-06-09  330  unsigned int d;
9cc07f55d Takashi Sakamoto 2017-06-09  331  struct snd_mask old_mask;
9cc07f55d Takashi Sakamoto 2017-06-09  332  struct snd_interval 
old_interval;
a1c06e39a Takashi Sakamoto 2017-06-09  333  bool again;
9cc07f55d Takashi Sakamoto 2017-06-09  334  int changed;
^1da177e4 Linus Torvalds   2005-04-16  335  
d81052f92 Takashi Sakamoto 2017-06-09  336  /*
d81052f92 Takashi Sakamoto 2017-06-09  337   * Each application of rule has 
own sequence number.
d81052f92 Takashi Sakamoto 2017-06-09  338   *
d81052f92 Takashi Sakamoto 2017-06-09  339   * Each member of 'rstamps' 
array represents the sequence number of
d81052f92 Takashi Sakamoto 2017-06-09  340   * recent application of 
corresponding rule.
d81052f92 Takashi Sakamoto 2017-06-09  341   */
16c438ade Kyle Spiers  2018-03-28  342  
16c438ade Kyle Spiers  2018-03-28  343  rstamps = 
kcalloc(constrs->rules_num, sizeof(*rstamps), GFP_KERNEL);
d81052f92 Takashi Sakamoto 2017-06-09  344  
d81052f92 Takashi Sakamoto 2017-06-09  345  /*
d81052f92 Takashi Sakamoto 2017-06-09  346   * Each member of 'vstamps' 
array represents the sequence number of
d81052f92 Takashi Sakamoto 2017-06-09  347   * recent application of rule 
in which corresponding parameters were
d81052f92 Takashi Sakamoto 2017-06-09  348   * changed.
d81052f92 Takashi Sakamoto 2017-06-09  349   *
d81052f92 Takashi Sakamoto 2017-06-09  350   * In initial state, elements 
corresponding to parameters requested by
d81052f92 Takashi Sakamoto 2017-06-09  351   * a caller is 1. For 
unrequested parameters, corresponding members
d81052f92 Takashi Sakamoto 2017-06-09  352   * have 0 so that the 
parameters are never changed anymore.
d81052f92 Takashi Sakamoto 2017-06-09  353   */
^1da177e4 Linus Torvalds   2005-04-16  354  for (k = 0; k <= 
SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++)
^1da177e4 Linus Torvalds   2005-04-16  355  vstamps[k] = 
(params->rmask & (1 << k)) ? 1 : 0;
d81052f92 Takashi Sakamoto 2017-06-09  356  
d81052f92 Takashi Sakamoto 2017-06-09  357  /* Due to the above design, 
actual sequence number starts at 2. */
d81052f92 Takashi Sakamoto 2017-06-09  358  stamp = 2;
0d4e39996 Takashi Sakamoto 2017-06-09  359  retry:
d81052f92 Takashi Sakamoto 2017-06-09  360  /* Apply all rules in order. */
a1c06e39a Takashi Sakamoto 2017-06-09  361  again = false;
^1da177e4 Linus Torvalds   2005-04-16  362  for (k = 0; k < 
constrs->rules_num; k++) {
a1c06e39a Takashi Sakamoto 2017-06-09  363  r = >rules[k];
d81052f92 Takashi Sakamoto 2017-06-09  364  
d81052f92 Takashi Sakamoto 2017-06-09  365  /*
d81052f92 Takashi Sakamoto 2017-06-09  366   * Check condition bits 
of this rule. When the rule has
d81052f92 Takashi Sakamoto 2017-06-09  367   * some condition bits, 
parameter without the bits is
d81052f92 Takashi Sakamoto 2017-06-09  368   * never processed. 

Re: [PATCH] pcm_native: Remove VLA usage

2018-03-29 Thread kbuild test robot
Hi Kyle,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on v4.16-rc7]
[cannot apply to sound/for-next next-20180329]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Kyle-Spiers/pcm_native-Remove-VLA-usage/20180330-073734
config: i386-randconfig-x075-201812 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All warnings (new ones prefixed by >>):

   sound/core/pcm_native.c: In function 'constrain_params_by_rules':
>> sound/core/pcm_native.c:401:3: warning: this 'if' clause does not guard... 
>> [-Wmisleading-indentation]
  if (changed < 0)
  ^~
   sound/core/pcm_native.c:403:4: note: ...this statement, but the latter is 
misleadingly indented as if it were guarded by the 'if'
   return changed;
   ^~

vim +/if +401 sound/core/pcm_native.c

^1da177e4 Linus Torvalds   2005-04-16  319  
9cc07f55d Takashi Sakamoto 2017-06-09  320  static int 
constrain_params_by_rules(struct snd_pcm_substream *substream,
877211f5e Takashi Iwai 2005-11-17  321   
struct snd_pcm_hw_params *params)
^1da177e4 Linus Torvalds   2005-04-16  322  {
9cc07f55d Takashi Sakamoto 2017-06-09  323  struct snd_pcm_hw_constraints 
*constrs =
9cc07f55d Takashi Sakamoto 2017-06-09  324  
>runtime->hw_constraints;
^1da177e4 Linus Torvalds   2005-04-16  325  unsigned int k;
16c438ade Kyle Spiers  2018-03-28  326  unsigned int *rstamps;
^1da177e4 Linus Torvalds   2005-04-16  327  unsigned int 
vstamps[SNDRV_PCM_HW_PARAM_LAST_INTERVAL + 1];
d81052f92 Takashi Sakamoto 2017-06-09  328  unsigned int stamp;
a1c06e39a Takashi Sakamoto 2017-06-09  329  struct snd_pcm_hw_rule *r;
a1c06e39a Takashi Sakamoto 2017-06-09  330  unsigned int d;
9cc07f55d Takashi Sakamoto 2017-06-09  331  struct snd_mask old_mask;
9cc07f55d Takashi Sakamoto 2017-06-09  332  struct snd_interval 
old_interval;
a1c06e39a Takashi Sakamoto 2017-06-09  333  bool again;
9cc07f55d Takashi Sakamoto 2017-06-09  334  int changed;
^1da177e4 Linus Torvalds   2005-04-16  335  
d81052f92 Takashi Sakamoto 2017-06-09  336  /*
d81052f92 Takashi Sakamoto 2017-06-09  337   * Each application of rule has 
own sequence number.
d81052f92 Takashi Sakamoto 2017-06-09  338   *
d81052f92 Takashi Sakamoto 2017-06-09  339   * Each member of 'rstamps' 
array represents the sequence number of
d81052f92 Takashi Sakamoto 2017-06-09  340   * recent application of 
corresponding rule.
d81052f92 Takashi Sakamoto 2017-06-09  341   */
16c438ade Kyle Spiers  2018-03-28  342  
16c438ade Kyle Spiers  2018-03-28  343  rstamps = 
kcalloc(constrs->rules_num, sizeof(*rstamps), GFP_KERNEL);
d81052f92 Takashi Sakamoto 2017-06-09  344  
d81052f92 Takashi Sakamoto 2017-06-09  345  /*
d81052f92 Takashi Sakamoto 2017-06-09  346   * Each member of 'vstamps' 
array represents the sequence number of
d81052f92 Takashi Sakamoto 2017-06-09  347   * recent application of rule 
in which corresponding parameters were
d81052f92 Takashi Sakamoto 2017-06-09  348   * changed.
d81052f92 Takashi Sakamoto 2017-06-09  349   *
d81052f92 Takashi Sakamoto 2017-06-09  350   * In initial state, elements 
corresponding to parameters requested by
d81052f92 Takashi Sakamoto 2017-06-09  351   * a caller is 1. For 
unrequested parameters, corresponding members
d81052f92 Takashi Sakamoto 2017-06-09  352   * have 0 so that the 
parameters are never changed anymore.
d81052f92 Takashi Sakamoto 2017-06-09  353   */
^1da177e4 Linus Torvalds   2005-04-16  354  for (k = 0; k <= 
SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++)
^1da177e4 Linus Torvalds   2005-04-16  355  vstamps[k] = 
(params->rmask & (1 << k)) ? 1 : 0;
d81052f92 Takashi Sakamoto 2017-06-09  356  
d81052f92 Takashi Sakamoto 2017-06-09  357  /* Due to the above design, 
actual sequence number starts at 2. */
d81052f92 Takashi Sakamoto 2017-06-09  358  stamp = 2;
0d4e39996 Takashi Sakamoto 2017-06-09  359  retry:
d81052f92 Takashi Sakamoto 2017-06-09  360  /* Apply all rules in order. */
a1c06e39a Takashi Sakamoto 2017-06-09  361  again = false;
^1da177e4 Linus Torvalds   2005-04-16  362  for (k = 0; k < 
constrs->rules_num; k++) {
a1c06e39a Takashi Sakamoto 2017-06-09  363  r = >rules[k];
d81052f92 Takashi Sakamoto 2017-06-09  364  
d81052f92 Takashi Sakamoto 2017-06-09  365  /*
d81052f92 Takashi Sakamoto 2017-06-09  366   * Check condition bits 
of this rule. When the rule has
d81052f92 Takashi Sakamoto 2017-06-09  367   * some condition bits, 
parameter without the bits is
d81052f92 Takashi Sakamoto 2017-06-09  368   * never processed. 

Re: [PATCH] pcm_native: Remove VLA usage

2018-03-28 Thread Kees Cook
On Wed, Mar 28, 2018 at 3:11 PM, Kyle Spiers  wrote:
> 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 
> ---
>  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 =
> >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;

Whoops, this needs { } s:

if (changed < 0) {
kfree(rstamps);
return changed;
}

Otherwise, looks good! Once that's fixed:

Reviewed-by: Kees Cook 

-Kees

>
> /*
> @@ -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
>



-- 
Kees Cook
Pixel Security


Re: [PATCH] pcm_native: Remove VLA usage

2018-03-28 Thread Kees Cook
On Wed, Mar 28, 2018 at 3:11 PM, Kyle Spiers  wrote:
> 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 
> ---
>  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 =
> >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;

Whoops, this needs { } s:

if (changed < 0) {
kfree(rstamps);
return changed;
}

Otherwise, looks good! Once that's fixed:

Reviewed-by: Kees Cook 

-Kees

>
> /*
> @@ -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
>



-- 
Kees Cook
Pixel Security


[PATCH] pcm_native: Remove VLA usage

2018-03-28 Thread Kyle Spiers
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 
---
 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 =
>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



[PATCH] pcm_native: Remove VLA usage

2018-03-28 Thread Kyle Spiers
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 
---
 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 =
>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