* [PATCH] counter: add defaults to switch-statements
@ 2022-02-27 16:17 trix
2022-02-27 17:46 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: trix @ 2022-02-27 16:17 UTC (permalink / raw)
To: vilhelm.gray, nathan, ndesaulniers, Jonathan.Cameron
Cc: linux-iio, linux-kernel, llvm, Tom Rix
From: Tom Rix <trix@redhat.com>
Clang static analysis reports this representative problem
counter-chrdev.c:482:3: warning: Undefined or garbage value
returned to caller
return ret;
^~~~~~~~~~
counter_get_data() has a multilevel switches, some without
defaults, so ret is sometimes not set.
Add returning -EINVAL similar to other defaults.
Fixes: b6c50affda59 ("counter: Add character device interface")
Signed-off-by: Tom Rix <trix@redhat.com>
---
drivers/counter/counter-chrdev.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c
index b7c62f957a6a8..69d340be9c93f 100644
--- a/drivers/counter/counter-chrdev.c
+++ b/drivers/counter/counter-chrdev.c
@@ -477,6 +477,8 @@ static int counter_get_data(struct counter_device *const counter,
case COUNTER_SCOPE_COUNT:
ret = comp->count_u8_read(counter, parent, &value_u8);
break;
+ default:
+ return -EINVAL;
}
*value = value_u8;
return ret;
@@ -496,6 +498,8 @@ static int counter_get_data(struct counter_device *const counter,
case COUNTER_SCOPE_COUNT:
ret = comp->count_u32_read(counter, parent, &value_u32);
break;
+ default:
+ return -EINVAL;
}
*value = value_u32;
return ret;
--
2.26.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] counter: add defaults to switch-statements
2022-02-27 16:17 [PATCH] counter: add defaults to switch-statements trix
@ 2022-02-27 17:46 ` Jonathan Cameron
2022-02-28 13:03 ` William Breathitt Gray
0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2022-02-27 17:46 UTC (permalink / raw)
To: trix
Cc: vilhelm.gray, nathan, ndesaulniers, Jonathan.Cameron, linux-iio,
linux-kernel, llvm
On Sun, 27 Feb 2022 08:17:46 -0800
trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
>
> Clang static analysis reports this representative problem
> counter-chrdev.c:482:3: warning: Undefined or garbage value
> returned to caller
> return ret;
> ^~~~~~~~~~
>
> counter_get_data() has a multilevel switches, some without
> defaults, so ret is sometimes not set.
> Add returning -EINVAL similar to other defaults.
>
> Fixes: b6c50affda59 ("counter: Add character device interface")
> Signed-off-by: Tom Rix <trix@redhat.com>
I'm fairly sure this one is warning supression rather than a fix as
that type u8 being used in the switch is storing an enum which is
set only by kernel code and all values of the enum are covered.
However, that's not locally visible so to me the addition looks good, I'd
just be tempted to drop the fixes tag as backporting this looks like noise
to me.
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> drivers/counter/counter-chrdev.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c
> index b7c62f957a6a8..69d340be9c93f 100644
> --- a/drivers/counter/counter-chrdev.c
> +++ b/drivers/counter/counter-chrdev.c
> @@ -477,6 +477,8 @@ static int counter_get_data(struct counter_device *const counter,
> case COUNTER_SCOPE_COUNT:
> ret = comp->count_u8_read(counter, parent, &value_u8);
> break;
> + default:
> + return -EINVAL;
> }
> *value = value_u8;
> return ret;
> @@ -496,6 +498,8 @@ static int counter_get_data(struct counter_device *const counter,
> case COUNTER_SCOPE_COUNT:
> ret = comp->count_u32_read(counter, parent, &value_u32);
> break;
> + default:
> + return -EINVAL;
> }
> *value = value_u32;
> return ret;
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] counter: add defaults to switch-statements
2022-02-27 17:46 ` Jonathan Cameron
@ 2022-02-28 13:03 ` William Breathitt Gray
2022-02-28 13:18 ` Tom Rix
0 siblings, 1 reply; 4+ messages in thread
From: William Breathitt Gray @ 2022-02-28 13:03 UTC (permalink / raw)
To: Jonathan Cameron, trix
Cc: nathan, ndesaulniers, Jonathan.Cameron, linux-iio, linux-kernel,
llvm
On Sun, Feb 27, 2022 at 05:46:10PM +0000, Jonathan Cameron wrote:
> On Sun, 27 Feb 2022 08:17:46 -0800
> trix@redhat.com wrote:
>
> > From: Tom Rix <trix@redhat.com>
> >
> > Clang static analysis reports this representative problem
> > counter-chrdev.c:482:3: warning: Undefined or garbage value
> > returned to caller
> > return ret;
> > ^~~~~~~~~~
> >
> > counter_get_data() has a multilevel switches, some without
> > defaults, so ret is sometimes not set.
> > Add returning -EINVAL similar to other defaults.
> >
> > Fixes: b6c50affda59 ("counter: Add character device interface")
> > Signed-off-by: Tom Rix <trix@redhat.com>
> I'm fairly sure this one is warning supression rather than a fix as
> that type u8 being used in the switch is storing an enum which is
> set only by kernel code and all values of the enum are covered.
>
> However, that's not locally visible so to me the addition looks good, I'd
> just be tempted to drop the fixes tag as backporting this looks like noise
> to me.
>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Yes, this isn't really a bug because the only values available are those
from the enum, but I see how this is not immediately obvious at first.
If Tom has no objections, I'll pick this up and drop the fixes tag so
that we have it along with the other counter changes for the 5.18 merge.
Thanks,
William Breathitt Gray
> > ---
> > drivers/counter/counter-chrdev.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c
> > index b7c62f957a6a8..69d340be9c93f 100644
> > --- a/drivers/counter/counter-chrdev.c
> > +++ b/drivers/counter/counter-chrdev.c
> > @@ -477,6 +477,8 @@ static int counter_get_data(struct counter_device *const counter,
> > case COUNTER_SCOPE_COUNT:
> > ret = comp->count_u8_read(counter, parent, &value_u8);
> > break;
> > + default:
> > + return -EINVAL;
> > }
> > *value = value_u8;
> > return ret;
> > @@ -496,6 +498,8 @@ static int counter_get_data(struct counter_device *const counter,
> > case COUNTER_SCOPE_COUNT:
> > ret = comp->count_u32_read(counter, parent, &value_u32);
> > break;
> > + default:
> > + return -EINVAL;
> > }
> > *value = value_u32;
> > return ret;
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] counter: add defaults to switch-statements
2022-02-28 13:03 ` William Breathitt Gray
@ 2022-02-28 13:18 ` Tom Rix
0 siblings, 0 replies; 4+ messages in thread
From: Tom Rix @ 2022-02-28 13:18 UTC (permalink / raw)
To: William Breathitt Gray, Jonathan Cameron
Cc: nathan, ndesaulniers, Jonathan.Cameron, linux-iio, linux-kernel,
llvm
On 2/28/22 5:03 AM, William Breathitt Gray wrote:
> On Sun, Feb 27, 2022 at 05:46:10PM +0000, Jonathan Cameron wrote:
>> On Sun, 27 Feb 2022 08:17:46 -0800
>> trix@redhat.com wrote:
>>
>>> From: Tom Rix <trix@redhat.com>
>>>
>>> Clang static analysis reports this representative problem
>>> counter-chrdev.c:482:3: warning: Undefined or garbage value
>>> returned to caller
>>> return ret;
>>> ^~~~~~~~~~
>>>
>>> counter_get_data() has a multilevel switches, some without
>>> defaults, so ret is sometimes not set.
>>> Add returning -EINVAL similar to other defaults.
>>>
>>> Fixes: b6c50affda59 ("counter: Add character device interface")
>>> Signed-off-by: Tom Rix <trix@redhat.com>
>> I'm fairly sure this one is warning supression rather than a fix as
>> that type u8 being used in the switch is storing an enum which is
>> set only by kernel code and all values of the enum are covered.
>>
>> However, that's not locally visible so to me the addition looks good, I'd
>> just be tempted to drop the fixes tag as backporting this looks like noise
>> to me.
>>
>> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Yes, this isn't really a bug because the only values available are those
> from the enum, but I see how this is not immediately obvious at first.
> If Tom has no objections, I'll pick this up and drop the fixes tag so
> that we have it along with the other counter changes for the 5.18 merge.
Sounds good.
Thanks,
Tom
> Thanks,
>
> William Breathitt Gray
>
>>> ---
>>> drivers/counter/counter-chrdev.c | 4 ++++
>>> 1 file changed, 4 insertions(+)
>>>
>>> diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c
>>> index b7c62f957a6a8..69d340be9c93f 100644
>>> --- a/drivers/counter/counter-chrdev.c
>>> +++ b/drivers/counter/counter-chrdev.c
>>> @@ -477,6 +477,8 @@ static int counter_get_data(struct counter_device *const counter,
>>> case COUNTER_SCOPE_COUNT:
>>> ret = comp->count_u8_read(counter, parent, &value_u8);
>>> break;
>>> + default:
>>> + return -EINVAL;
>>> }
>>> *value = value_u8;
>>> return ret;
>>> @@ -496,6 +498,8 @@ static int counter_get_data(struct counter_device *const counter,
>>> case COUNTER_SCOPE_COUNT:
>>> ret = comp->count_u32_read(counter, parent, &value_u32);
>>> break;
>>> + default:
>>> + return -EINVAL;
>>> }
>>> *value = value_u32;
>>> return ret;
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-02-28 13:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-27 16:17 [PATCH] counter: add defaults to switch-statements trix
2022-02-27 17:46 ` Jonathan Cameron
2022-02-28 13:03 ` William Breathitt Gray
2022-02-28 13:18 ` Tom Rix
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox