[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <40956844-c18d-31d2-1f2c-e164dfe82ecf@gentoo.org>
Date: Thu, 20 Dec 2018 14:46:52 +0100
From: Matthias Schwarzott <zzam@...too.org>
To: Kangjie Lu <kjlu@....edu>
Cc: pakki001@....edu, Mauro Carvalho Chehab <mchehab@...nel.org>,
linux-media@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] media: si2165: fix a missing check of return value
Am 20.12.18 um 09:12 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
> "-EINVAL".
>
Good catch. I reviewed it.
See below.
> Signed-off-by: Kangjie Lu <kjlu@....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..c134f312fa5b 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 -EINVAL;
This code should return "ret" instead of "-EINVAL".
> if (val == 0x01)
> return 0;
> usleep_range(1000, 50000);
> }
> dev_err(&state->client->dev, "init_done was not set\n");
> - return ret;
> + return -EINVAL;
Here I am not sure if -ETIMEDOUT would be a better return code.
> }
>
> static int si2165_upload_firmware_block(struct si2165_state *state,
>
Powered by blists - more mailing lists