* [PATCHv2] [media] af0933: Don't go past arrays
@ 2014-11-04 20:35 Mauro Carvalho Chehab
2014-11-05 2:44 ` Antti Palosaari
0 siblings, 1 reply; 3+ messages in thread
From: Mauro Carvalho Chehab @ 2014-11-04 20:35 UTC (permalink / raw)
To: Linux Media Mailing List
Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Antti Palosaari
Fixes the following sparse warnings:
drivers/media/dvb-frontends/af9033.c:295 af9033_init() error: buffer overflow 'clock_adc_lut' 11 <= 11
drivers/media/dvb-frontends/af9033.c:300 af9033_init() error: buffer overflow 'clock_adc_lut' 11 <= 11
drivers/media/dvb-frontends/af9033.c:584 af9033_set_frontend() error: buffer overflow 'coeff_lut' 3 <= 3
drivers/media/dvb-frontends/af9033.c:595 af9033_set_frontend() error: buffer overflow 'clock_adc_lut' 11 <= 11
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
-
v2: Only changed the patch subject, as it fixes occurrences on 3
different arrays.
diff --git a/drivers/media/dvb-frontends/af9033.c b/drivers/media/dvb-frontends/af9033.c
index c17e34fd0fb4..82ce47bdf5dc 100644
--- a/drivers/media/dvb-frontends/af9033.c
+++ b/drivers/media/dvb-frontends/af9033.c
@@ -291,6 +291,12 @@ static int af9033_init(struct dvb_frontend *fe)
if (clock_adc_lut[i].clock == dev->cfg.clock)
break;
}
+ if (i == ARRAY_SIZE(clock_adc_lut)) {
+ dev_err(&dev->client->dev,
+ "Couldn't find ADC config for clock=%d\n",
+ dev->cfg.clock);
+ goto err;
+ }
adc_cw = af9033_div(dev, clock_adc_lut[i].adc, 1000000ul, 19ul);
buf[0] = (adc_cw >> 0) & 0xff;
@@ -580,7 +586,15 @@ static int af9033_set_frontend(struct dvb_frontend *fe)
break;
}
}
- ret = af9033_wr_regs(dev, 0x800001,
+ if (i == ARRAY_SIZE(coeff_lut)) {
+ dev_err(&dev->client->dev,
+ "Couldn't find LUT config for clock=%d\n",
+ dev->cfg.clock);
+ ret = -EINVAL;
+ goto err;
+ }
+
+ ret = af9033_wr_regs(dev, 0x800001,
coeff_lut[i].val, sizeof(coeff_lut[i].val));
}
@@ -592,6 +606,13 @@ static int af9033_set_frontend(struct dvb_frontend *fe)
if (clock_adc_lut[i].clock == dev->cfg.clock)
break;
}
+ if (i == ARRAY_SIZE(clock_adc_lut)) {
+ dev_err(&dev->client->dev,
+ "Couldn't find ADC clock for clock=%d\n",
+ dev->cfg.clock);
+ ret = -EINVAL;
+ goto err;
+ }
adc_freq = clock_adc_lut[i].adc;
/* get used IF frequency */
--
1.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCHv2] [media] af0933: Don't go past arrays
2014-11-04 20:35 [PATCHv2] [media] af0933: Don't go past arrays Mauro Carvalho Chehab
@ 2014-11-05 2:44 ` Antti Palosaari
2014-11-05 12:30 ` Mauro Carvalho Chehab
0 siblings, 1 reply; 3+ messages in thread
From: Antti Palosaari @ 2014-11-05 2:44 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab
Acked-by: Antti Palosaari <crope@iki.fi>
Reviewed-by: Antti Palosaari <crope@iki.fi>
anyhow, I think these branches could never taken in real life. But as a
killing warnings and potential future changes I am pretty fine!
regards
Antti
On 11/04/2014 10:35 PM, Mauro Carvalho Chehab wrote:
> Fixes the following sparse warnings:
> drivers/media/dvb-frontends/af9033.c:295 af9033_init() error: buffer overflow 'clock_adc_lut' 11 <= 11
> drivers/media/dvb-frontends/af9033.c:300 af9033_init() error: buffer overflow 'clock_adc_lut' 11 <= 11
> drivers/media/dvb-frontends/af9033.c:584 af9033_set_frontend() error: buffer overflow 'coeff_lut' 3 <= 3
> drivers/media/dvb-frontends/af9033.c:595 af9033_set_frontend() error: buffer overflow 'clock_adc_lut' 11 <= 11
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>
> -
> v2: Only changed the patch subject, as it fixes occurrences on 3
> different arrays.
>
> diff --git a/drivers/media/dvb-frontends/af9033.c b/drivers/media/dvb-frontends/af9033.c
> index c17e34fd0fb4..82ce47bdf5dc 100644
> --- a/drivers/media/dvb-frontends/af9033.c
> +++ b/drivers/media/dvb-frontends/af9033.c
> @@ -291,6 +291,12 @@ static int af9033_init(struct dvb_frontend *fe)
> if (clock_adc_lut[i].clock == dev->cfg.clock)
> break;
> }
> + if (i == ARRAY_SIZE(clock_adc_lut)) {
> + dev_err(&dev->client->dev,
> + "Couldn't find ADC config for clock=%d\n",
> + dev->cfg.clock);
> + goto err;
> + }
>
> adc_cw = af9033_div(dev, clock_adc_lut[i].adc, 1000000ul, 19ul);
> buf[0] = (adc_cw >> 0) & 0xff;
> @@ -580,7 +586,15 @@ static int af9033_set_frontend(struct dvb_frontend *fe)
> break;
> }
> }
> - ret = af9033_wr_regs(dev, 0x800001,
> + if (i == ARRAY_SIZE(coeff_lut)) {
> + dev_err(&dev->client->dev,
> + "Couldn't find LUT config for clock=%d\n",
> + dev->cfg.clock);
> + ret = -EINVAL;
> + goto err;
> + }
> +
> + ret = af9033_wr_regs(dev, 0x800001,
> coeff_lut[i].val, sizeof(coeff_lut[i].val));
> }
>
> @@ -592,6 +606,13 @@ static int af9033_set_frontend(struct dvb_frontend *fe)
> if (clock_adc_lut[i].clock == dev->cfg.clock)
> break;
> }
> + if (i == ARRAY_SIZE(clock_adc_lut)) {
> + dev_err(&dev->client->dev,
> + "Couldn't find ADC clock for clock=%d\n",
> + dev->cfg.clock);
> + ret = -EINVAL;
> + goto err;
> + }
> adc_freq = clock_adc_lut[i].adc;
>
> /* get used IF frequency */
>
--
http://palosaari.fi/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCHv2] [media] af0933: Don't go past arrays
2014-11-05 2:44 ` Antti Palosaari
@ 2014-11-05 12:30 ` Mauro Carvalho Chehab
0 siblings, 0 replies; 3+ messages in thread
From: Mauro Carvalho Chehab @ 2014-11-05 12:30 UTC (permalink / raw)
To: Antti Palosaari; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab
Em Wed, 05 Nov 2014 04:44:22 +0200
Antti Palosaari <crope@iki.fi> escreveu:
> Acked-by: Antti Palosaari <crope@iki.fi>
> Reviewed-by: Antti Palosaari <crope@iki.fi>
>
> anyhow, I think these branches could never taken in real life.
Yes, probably this never happens with current code.
> But as a
> killing warnings and potential future changes I am pretty fine!
The main goal is to kill warnings, but it also prevents future
mistakes. It is a way better to have a warning printed than
to go past the buffer and get random errors.
Regards,
Mauro
>
> regards
> Antti
>
> On 11/04/2014 10:35 PM, Mauro Carvalho Chehab wrote:
> > Fixes the following sparse warnings:
> > drivers/media/dvb-frontends/af9033.c:295 af9033_init() error: buffer overflow 'clock_adc_lut' 11 <= 11
> > drivers/media/dvb-frontends/af9033.c:300 af9033_init() error: buffer overflow 'clock_adc_lut' 11 <= 11
> > drivers/media/dvb-frontends/af9033.c:584 af9033_set_frontend() error: buffer overflow 'coeff_lut' 3 <= 3
> > drivers/media/dvb-frontends/af9033.c:595 af9033_set_frontend() error: buffer overflow 'clock_adc_lut' 11 <= 11
> >
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> >
> > -
> > v2: Only changed the patch subject, as it fixes occurrences on 3
> > different arrays.
> >
> > diff --git a/drivers/media/dvb-frontends/af9033.c b/drivers/media/dvb-frontends/af9033.c
> > index c17e34fd0fb4..82ce47bdf5dc 100644
> > --- a/drivers/media/dvb-frontends/af9033.c
> > +++ b/drivers/media/dvb-frontends/af9033.c
> > @@ -291,6 +291,12 @@ static int af9033_init(struct dvb_frontend *fe)
> > if (clock_adc_lut[i].clock == dev->cfg.clock)
> > break;
> > }
> > + if (i == ARRAY_SIZE(clock_adc_lut)) {
> > + dev_err(&dev->client->dev,
> > + "Couldn't find ADC config for clock=%d\n",
> > + dev->cfg.clock);
> > + goto err;
> > + }
> >
> > adc_cw = af9033_div(dev, clock_adc_lut[i].adc, 1000000ul, 19ul);
> > buf[0] = (adc_cw >> 0) & 0xff;
> > @@ -580,7 +586,15 @@ static int af9033_set_frontend(struct dvb_frontend *fe)
> > break;
> > }
> > }
> > - ret = af9033_wr_regs(dev, 0x800001,
> > + if (i == ARRAY_SIZE(coeff_lut)) {
> > + dev_err(&dev->client->dev,
> > + "Couldn't find LUT config for clock=%d\n",
> > + dev->cfg.clock);
> > + ret = -EINVAL;
> > + goto err;
> > + }
> > +
> > + ret = af9033_wr_regs(dev, 0x800001,
> > coeff_lut[i].val, sizeof(coeff_lut[i].val));
> > }
> >
> > @@ -592,6 +606,13 @@ static int af9033_set_frontend(struct dvb_frontend *fe)
> > if (clock_adc_lut[i].clock == dev->cfg.clock)
> > break;
> > }
> > + if (i == ARRAY_SIZE(clock_adc_lut)) {
> > + dev_err(&dev->client->dev,
> > + "Couldn't find ADC clock for clock=%d\n",
> > + dev->cfg.clock);
> > + ret = -EINVAL;
> > + goto err;
> > + }
> > adc_freq = clock_adc_lut[i].adc;
> >
> > /* get used IF frequency */
> >
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-11-05 12:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-04 20:35 [PATCHv2] [media] af0933: Don't go past arrays Mauro Carvalho Chehab
2014-11-05 2:44 ` Antti Palosaari
2014-11-05 12:30 ` Mauro Carvalho Chehab
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.