* [PATCH v2] media: si2165: fix a missing check of return value
@ 2018-12-21 4:54 Kangjie Lu
2018-12-21 8:24 ` Matthias Schwarzott
0 siblings, 1 reply; 4+ messages in thread
From: Kangjie Lu @ 2018-12-21 4:54 UTC (permalink / raw)
To: kjlu
Cc: pakki001, Matthias Schwarzott, Mauro Carvalho Chehab,
linux-media, linux-kernel
si2165_readreg8() may fail. Looking into si2165_readreg8(), we will find
that "val_tmp" will be an uninitialized value when regmap_read() fails.
"val_tmp" is then assigned to "val". So if si2165_readreg8() fails,
"val" will be a random value. Further use will lead to undefined
behaviors. The fix checks if si2165_readreg8() fails, and if so, returns
its error code upstream.
Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
drivers/media/dvb-frontends/si2165.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/media/dvb-frontends/si2165.c b/drivers/media/dvb-frontends/si2165.c
index feacd8da421d..d55d8f169dca 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -275,18 +275,20 @@ static u32 si2165_get_fe_clk(struct si2165_state *state)
static int si2165_wait_init_done(struct si2165_state *state)
{
- int ret = -EINVAL;
+ int ret;
u8 val = 0;
int i;
for (i = 0; i < 3; ++i) {
- si2165_readreg8(state, REG_INIT_DONE, &val);
+ ret = si2165_readreg8(state, REG_INIT_DONE, &val);
+ if (ret < 0)
+ return ret;
if (val == 0x01)
return 0;
usleep_range(1000, 50000);
}
dev_err(&state->client->dev, "init_done was not set\n");
- return ret;
+ return -EINVAL;
}
static int si2165_upload_firmware_block(struct si2165_state *state,
--
2.17.2 (Apple Git-113)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] media: si2165: fix a missing check of return value
2018-12-21 4:54 [PATCH v2] media: si2165: fix a missing check of return value Kangjie Lu
@ 2018-12-21 8:24 ` Matthias Schwarzott
2019-03-05 21:17 ` Sean Young
0 siblings, 1 reply; 4+ messages in thread
From: Matthias Schwarzott @ 2018-12-21 8:24 UTC (permalink / raw)
To: Kangjie Lu; +Cc: pakki001, Mauro Carvalho Chehab, linux-media, linux-kernel
Am 21.12.18 um 05:54 schrieb Kangjie Lu:
> si2165_readreg8() may fail. Looking into si2165_readreg8(), we will find
> that "val_tmp" will be an uninitialized value when regmap_read() fails.
> "val_tmp" is then assigned to "val". So if si2165_readreg8() fails,
> "val" will be a random value. Further use will lead to undefined
> behaviors. The fix checks if si2165_readreg8() fails, and if so, returns
> its error code upstream.
>
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Reviewed-by: Matthias Schwarzott <zzam@gentoo.org>
> ---
> drivers/media/dvb-frontends/si2165.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/dvb-frontends/si2165.c b/drivers/media/dvb-frontends/si2165.c
> index feacd8da421d..d55d8f169dca 100644
> --- a/drivers/media/dvb-frontends/si2165.c
> +++ b/drivers/media/dvb-frontends/si2165.c
> @@ -275,18 +275,20 @@ static u32 si2165_get_fe_clk(struct si2165_state *state)
>
> static int si2165_wait_init_done(struct si2165_state *state)
> {
> - int ret = -EINVAL;
> + int ret;
> u8 val = 0;
> int i;
>
> for (i = 0; i < 3; ++i) {
> - si2165_readreg8(state, REG_INIT_DONE, &val);
> + ret = si2165_readreg8(state, REG_INIT_DONE, &val);
> + if (ret < 0)
> + return ret;
> if (val == 0x01)
> return 0;
> usleep_range(1000, 50000);
> }
> dev_err(&state->client->dev, "init_done was not set\n");
> - return ret;
> + return -EINVAL;
> }
>
> static int si2165_upload_firmware_block(struct si2165_state *state,
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] media: si2165: fix a missing check of return value
2018-12-21 8:24 ` Matthias Schwarzott
@ 2019-03-05 21:17 ` Sean Young
2019-03-06 21:36 ` Matthias Schwarzott
0 siblings, 1 reply; 4+ messages in thread
From: Sean Young @ 2019-03-05 21:17 UTC (permalink / raw)
To: Matthias Schwarzott
Cc: Kangjie Lu, pakki001, Mauro Carvalho Chehab, linux-media, linux-kernel
On Fri, Dec 21, 2018 at 09:24:46AM +0100, Matthias Schwarzott wrote:
> Am 21.12.18 um 05:54 schrieb Kangjie Lu:
> > si2165_readreg8() may fail. Looking into si2165_readreg8(), we will find
> > that "val_tmp" will be an uninitialized value when regmap_read() fails.
> > "val_tmp" is then assigned to "val". So if si2165_readreg8() fails,
> > "val" will be a random value. Further use will lead to undefined
> > behaviors. The fix checks if si2165_readreg8() fails, and if so, returns
> > its error code upstream.
> >
> > Signed-off-by: Kangjie Lu <kjlu@umn.edu>
>
> Reviewed-by: Matthias Schwarzott <zzam@gentoo.org>
Unless it is tested on the actual hardware we can't apply this. This could
introduce regressions.
Sean
>
> > ---
> > drivers/media/dvb-frontends/si2165.c | 8 +++++---
> > 1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/media/dvb-frontends/si2165.c b/drivers/media/dvb-frontends/si2165.c
> > index feacd8da421d..d55d8f169dca 100644
> > --- a/drivers/media/dvb-frontends/si2165.c
> > +++ b/drivers/media/dvb-frontends/si2165.c
> > @@ -275,18 +275,20 @@ static u32 si2165_get_fe_clk(struct si2165_state *state)
> >
> > static int si2165_wait_init_done(struct si2165_state *state)
> > {
> > - int ret = -EINVAL;
> > + int ret;
> > u8 val = 0;
> > int i;
> >
> > for (i = 0; i < 3; ++i) {
> > - si2165_readreg8(state, REG_INIT_DONE, &val);
> > + ret = si2165_readreg8(state, REG_INIT_DONE, &val);
> > + if (ret < 0)
> > + return ret;
> > if (val == 0x01)
> > return 0;
> > usleep_range(1000, 50000);
> > }
> > dev_err(&state->client->dev, "init_done was not set\n");
> > - return ret;
> > + return -EINVAL;
> > }
> >
> > static int si2165_upload_firmware_block(struct si2165_state *state,
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] media: si2165: fix a missing check of return value
2019-03-05 21:17 ` Sean Young
@ 2019-03-06 21:36 ` Matthias Schwarzott
0 siblings, 0 replies; 4+ messages in thread
From: Matthias Schwarzott @ 2019-03-06 21:36 UTC (permalink / raw)
To: Sean Young
Cc: Kangjie Lu, pakki001, Mauro Carvalho Chehab, linux-media, linux-kernel
Am 05.03.19 um 22:17 schrieb Sean Young:
> On Fri, Dec 21, 2018 at 09:24:46AM +0100, Matthias Schwarzott wrote:
>> Am 21.12.18 um 05:54 schrieb Kangjie Lu:
>>> si2165_readreg8() may fail. Looking into si2165_readreg8(), we will find
>>> that "val_tmp" will be an uninitialized value when regmap_read() fails.
>>> "val_tmp" is then assigned to "val". So if si2165_readreg8() fails,
>>> "val" will be a random value. Further use will lead to undefined
>>> behaviors. The fix checks if si2165_readreg8() fails, and if so, returns
>>> its error code upstream.
>>>
>>> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
>>
>> Reviewed-by: Matthias Schwarzott <zzam@gentoo.org>
>
> Unless it is tested on the actual hardware we can't apply this. This could
> introduce regressions.
>
I tested it on a Hauppauge WinTV-HVR5500 tuning to DVB-C.
Regards
Matthias
Tested-by: Matthias Schwarzott <zzam@gentoo.org>
> Sean
>
>>
>>> ---
>>> drivers/media/dvb-frontends/si2165.c | 8 +++++---
>>> 1 file changed, 5 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/media/dvb-frontends/si2165.c b/drivers/media/dvb-frontends/si2165.c
>>> index feacd8da421d..d55d8f169dca 100644
>>> --- a/drivers/media/dvb-frontends/si2165.c
>>> +++ b/drivers/media/dvb-frontends/si2165.c
>>> @@ -275,18 +275,20 @@ static u32 si2165_get_fe_clk(struct si2165_state *state)
>>>
>>> static int si2165_wait_init_done(struct si2165_state *state)
>>> {
>>> - int ret = -EINVAL;
>>> + int ret;
>>> u8 val = 0;
>>> int i;
>>>
>>> for (i = 0; i < 3; ++i) {
>>> - si2165_readreg8(state, REG_INIT_DONE, &val);
>>> + ret = si2165_readreg8(state, REG_INIT_DONE, &val);
>>> + if (ret < 0)
>>> + return ret;
>>> if (val == 0x01)
>>> return 0;
>>> usleep_range(1000, 50000);
>>> }
>>> dev_err(&state->client->dev, "init_done was not set\n");
>>> - return ret;
>>> + return -EINVAL;
>>> }
>>>
>>> static int si2165_upload_firmware_block(struct si2165_state *state,
>>>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-03-06 21:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-21 4:54 [PATCH v2] media: si2165: fix a missing check of return value Kangjie Lu
2018-12-21 8:24 ` Matthias Schwarzott
2019-03-05 21:17 ` Sean Young
2019-03-06 21:36 ` Matthias Schwarzott
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).