[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YUkpBU8mN4yrDfu5@shinobu>
Date: Tue, 21 Sep 2021 09:36:21 +0900
From: William Breathitt Gray <vilhelm.gray@...il.com>
To: Tim Gardner <tim.gardner@...onical.com>
Cc: jic23@...nel.org, linux-iio@...r.kernel.org,
Syed Nayyar Waris <syednwaris@...il.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2][next] counter: Add default statement to switch() in
quad8_function_read()
On Mon, Sep 20, 2021 at 11:37:37AM -0600, Tim Gardner wrote:
> v2: Add the correct Cc's
>
> Coverity complains of a possible use of an uninitialized variable
> in quad8_action_read().
>
> CID 119643 (#1 of 1): Uninitialized scalar variable (UNINIT)
> 4. uninit_use: Using uninitialized value function.
> 346 switch (function) {
>
> The call to quad8_function_read() could theoretically return without
> assigning a value to '*function', thus causing the use of an
> ininitialized variable 'function' in quad8_action_read().
>
> Fix this by adding a default statement to the switch in
> quad8_function_read() and returning an error.
>
> Cc: William Breathitt Gray <vilhelm.gray@...il.com>
> Cc: Syed Nayyar Waris <syednwaris@...il.com>
> Cc: linux-iio@...r.kernel.org
> Cc: linux-kernel@...r.kernel.org
> Signed-off-by: Tim Gardner <tim.gardner@...onical.com>
Hello Tim,
The possible values of quadrature_scale are hardcoded in
quad8_function_write() so we should never have scale value greater than
2. But it would be a good idea to provide a default statement here to
pacify the warning, or at least mitigate shooting ourselves in the foot
in the future if this part of the code is changed.
Please add a comment similar to the default statement in
quad8_function_write() indicating that we should never reach this path,
and also return a more informative error code such as -EINVAL.
William Breathitt Gray
> ---
> drivers/counter/104-quad-8.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
> index c587f295d720..3a69d35b82ea 100644
> --- a/drivers/counter/104-quad-8.c
> +++ b/drivers/counter/104-quad-8.c
> @@ -215,6 +215,8 @@ static int quad8_function_read(struct counter_device *counter,
> case 2:
> *function = COUNTER_FUNCTION_QUADRATURE_X4;
> break;
> + default:
> + return -1;
> }
> else
> *function = COUNTER_FUNCTION_PULSE_DIRECTION;
> --
> 2.33.0
>
Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)
Powered by blists - more mailing lists