Skip to contentSkip to conversation

ASoC: Add max98925 codec driver

DISCUSSION Dan Carpenter 2 participants 3 messages Mar 17, 2015 – Jul 20, 2015

lore
Share & tools
lore
#0 lore raw

Hello Anish Kumar,

The patch 1ff2765182d1: "ASoC: Add max98925 codec driver" from Mar 9, 2015, leads to the following static checker warning:

	sound/soc/codecs/max98925.c:274 max98925_rate_value()
	error: buffer overflow 'rate_table' 9 <= 9

sound/soc/codecs/max98925.c
259 static inline int max98925_rate_value(struct snd_soc_codec *codec,
260 int rate, int clock, int *value, int *n, int *m)
261 {
262 int ret = -EINVAL;
263 int i;
264
265 for (i = 0; i < ARRAY_SIZE(rate_table); i++) {
266 if (rate_table[i].rate >= rate) {

   267                          *value = rate_table[i].sr;
   268                          *n = rate_table[i].divisors[clock][0];
   269                          *m = rate_table[i].divisors[clock][1];
   270                          ret = 0;
   271                          break;
   272                  }
   273          }
   274          dev_dbg(codec->dev, "%s: sample rate is %d, returning %d\n",
   275                                  __func__, rate_table[i].rate, *value);
                                                  ^^^^^^^^^^^^^^^^^^

If we don't break then we're off by one.

276 return ret;
277 }

regards,
dan carpenter

#1 lore raw
Quoted 27 lines · Dan Carpenter

Hello Anish Kumar,

The patch 1ff2765182d1: "ASoC: Add max98925 codec driver" from Mar 9, 2015, leads to the following static checker warning:

	sound/soc/codecs/max98925.c:274 max98925_rate_value()
	error: buffer overflow 'rate_table' 9 <= 9

sound/soc/codecs/max98925.c
259 static inline int max98925_rate_value(struct snd_soc_codec *codec,
260 int rate, int clock, int *value, int *n, int *m)

   261  {
   262          int ret = -EINVAL;
   263          int i;
   264  
   265          for (i = 0; i < ARRAY_SIZE(rate_table); i++) {
   266                  if (rate_table[i].rate >= rate) {
   267                          *value = rate_table[i].sr;
   268                          *n = rate_table[i].divisors[clock][0];
   269                          *m = rate_table[i].divisors[clock][1];
   270                          ret = 0;
   271                          break;
   272                  }
   273          }
   274          dev_dbg(codec->dev, "%s: sample rate is %d, returning %d\n",
   275                                  __func__, rate_table[i].rate, *value);
                                                  ^^^^^^^^^^^^^^^^^^
Quoted 1 line

If we don't break then we're off by one.

I'm going to just delete this because these warnings are annoying and debug printks are pointless and if you cared then you would have fixed it by now.

regards,
dan carpenter

#2 lore raw
Quoted 30 lines · Dan Carpenter
Quoted 27 lines · Dan Carpenter

Hello Anish Kumar,

The patch 1ff2765182d1: "ASoC: Add max98925 codec driver" from Mar 9, 2015, leads to the following static checker warning:

sound/soc/codecs/max98925.c:274 max98925_rate_value()
error: buffer overflow 'rate_table' 9 <= 9

sound/soc/codecs/max98925.c
259 static inline int max98925_rate_value(struct snd_soc_codec *codec,
260 int rate, int clock, int *value, int *n, int *m)

   261  {
   262          int ret = -EINVAL;
   263          int i;
   264
   265          for (i = 0; i < ARRAY_SIZE(rate_table); i++) {
   266                  if (rate_table[i].rate >= rate) {
   267                          *value = rate_table[i].sr;
   268                          *n = rate_table[i].divisors[clock][0];
   269                          *m = rate_table[i].divisors[clock][1];
   270                          ret = 0;
   271                          break;
   272                  }
   273          }
   274          dev_dbg(codec->dev, "%s: sample rate is %d, returning %d\n",
   275                                  __func__, rate_table[i].rate, *value);
                                                  ^^^^^^^^^^^^^^^^^^
Quoted 1 line

If we don't break then we're off by one.

Quoted 3 lines

I'm going to just delete this because these warnings are annoying and debug printks are pointless and if you cared then you would have fixed it by now.

Please go ahead.

Quoted 4 lines

regards,
dan carpenter