linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: comedi: tio: fix multiple missing break in switch bugs
@ 2018-10-11 19:05 Gustavo A. R. Silva
  2018-10-12  9:04 ` Ian Abbott
  0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2018-10-11 19:05 UTC (permalink / raw)
  To: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman, Spencer E. Olson
  Cc: devel, linux-kernel, Gustavo A. R. Silva

Currently, there are multiple missing break statements in two switch code
blocks. This makes the execution path to fall all the way down through
to the default cases, which makes the function ni_tio_set_gate_src() to
always return -EINVAL.

Fix this by adding the missing break statements.

Also, notice that due to the absence of the break statements,
the following pieces of code are unreachable:

1078    if (ret)
1079            return ret;
1080    /* 3.  reenable & set mode to starts things back up */
1081    ni_tio_set_gate_mode(counter, src);

1098    if (ret)
1099            return ret;
1100    /* 3.  reenable & set mode to starts things back up */
1101    ni_tio_set_gate2_mode(counter, src);

So, by adding the missing breaks, this patch also fixes the problem
above.

Addresses-Coverity-ID: 1474165 ("Missing break in switch")
Addresses-Coverity-ID: 1474162 ("Structurally dead code")
Fixes: 347e244884c3 ("staging: comedi: tio: implement global tio/ctr routing")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 drivers/staging/comedi/drivers/ni_tio.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/staging/comedi/drivers/ni_tio.c b/drivers/staging/comedi/drivers/ni_tio.c
index 838614e..0eb388c 100644
--- a/drivers/staging/comedi/drivers/ni_tio.c
+++ b/drivers/staging/comedi/drivers/ni_tio.c
@@ -1070,8 +1070,10 @@ int ni_tio_set_gate_src(struct ni_gpct *counter,
 		case ni_gpct_variant_e_series:
 		case ni_gpct_variant_m_series:
 			ret = ni_m_set_gate(counter, chan);
+			break;
 		case ni_gpct_variant_660x:
 			ret = ni_660x_set_gate(counter, chan);
+			break;
 		default:
 			return -EINVAL;
 		}
@@ -1090,8 +1092,10 @@ int ni_tio_set_gate_src(struct ni_gpct *counter,
 		switch (counter_dev->variant) {
 		case ni_gpct_variant_m_series:
 			ret = ni_m_set_gate2(counter, chan);
+			break;
 		case ni_gpct_variant_660x:
 			ret = ni_660x_set_gate2(counter, chan);
+			break;
 		default:
 			return -EINVAL;
 		}
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: comedi: tio: fix multiple missing break in switch bugs
  2018-10-11 19:05 [PATCH] staging: comedi: tio: fix multiple missing break in switch bugs Gustavo A. R. Silva
@ 2018-10-12  9:04 ` Ian Abbott
  2018-10-12  9:06   ` Gustavo A. R. Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Abbott @ 2018-10-12  9:04 UTC (permalink / raw)
  To: Gustavo A. R. Silva, H Hartley Sweeten, Greg Kroah-Hartman,
	Spencer E. Olson
  Cc: devel, linux-kernel

On 11/10/2018 20:05, Gustavo A. R. Silva wrote:
> Currently, there are multiple missing break statements in two switch code
> blocks. This makes the execution path to fall all the way down through
> to the default cases, which makes the function ni_tio_set_gate_src() to
> always return -EINVAL.
> 
> Fix this by adding the missing break statements.
> 
> Also, notice that due to the absence of the break statements,
> the following pieces of code are unreachable:
> 
> 1078    if (ret)
> 1079            return ret;
> 1080    /* 3.  reenable & set mode to starts things back up */
> 1081    ni_tio_set_gate_mode(counter, src);
> 
> 1098    if (ret)
> 1099            return ret;
> 1100    /* 3.  reenable & set mode to starts things back up */
> 1101    ni_tio_set_gate2_mode(counter, src);
> 
> So, by adding the missing breaks, this patch also fixes the problem
> above.
> 
> Addresses-Coverity-ID: 1474165 ("Missing break in switch")
> Addresses-Coverity-ID: 1474162 ("Structurally dead code")
> Fixes: 347e244884c3 ("staging: comedi: tio: implement global tio/ctr routing")
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>   drivers/staging/comedi/drivers/ni_tio.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/staging/comedi/drivers/ni_tio.c b/drivers/staging/comedi/drivers/ni_tio.c
> index 838614e..0eb388c 100644
> --- a/drivers/staging/comedi/drivers/ni_tio.c
> +++ b/drivers/staging/comedi/drivers/ni_tio.c
> @@ -1070,8 +1070,10 @@ int ni_tio_set_gate_src(struct ni_gpct *counter,
>   		case ni_gpct_variant_e_series:
>   		case ni_gpct_variant_m_series:
>   			ret = ni_m_set_gate(counter, chan);
> +			break;
>   		case ni_gpct_variant_660x:
>   			ret = ni_660x_set_gate(counter, chan);
> +			break;
>   		default:
>   			return -EINVAL;
>   		}
> @@ -1090,8 +1092,10 @@ int ni_tio_set_gate_src(struct ni_gpct *counter,
>   		switch (counter_dev->variant) {
>   		case ni_gpct_variant_m_series:
>   			ret = ni_m_set_gate2(counter, chan);
> +			break;
>   		case ni_gpct_variant_660x:
>   			ret = ni_660x_set_gate2(counter, chan);
> +			break;
>   		default:
>   			return -EINVAL;
>   		}
> 

Thanks for catching that bug!

Reviewed-by: Ian Abbott <abbotti@mev.co.uk>

-- 
-=( Ian Abbott <abbotti@mev.co.uk> || Web: www.mev.co.uk )=-
-=( MEV Ltd. is a company registered in England & Wales. )=-
-=( Registered number: 02862268.  Registered address:    )=-
-=( 15 West Park Road, Bramhall, STOCKPORT, SK7 3JZ, UK. )=-

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: comedi: tio: fix multiple missing break in switch bugs
  2018-10-12  9:04 ` Ian Abbott
@ 2018-10-12  9:06   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2018-10-12  9:06 UTC (permalink / raw)
  To: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman, Spencer E. Olson
  Cc: devel, linux-kernel



On 10/12/18 11:04 AM, Ian Abbott wrote:
> On 11/10/2018 20:05, Gustavo A. R. Silva wrote:
>> Currently, there are multiple missing break statements in two switch code
>> blocks. This makes the execution path to fall all the way down through
>> to the default cases, which makes the function ni_tio_set_gate_src() to
>> always return -EINVAL.
>>
>> Fix this by adding the missing break statements.
>>
>> Also, notice that due to the absence of the break statements,
>> the following pieces of code are unreachable:
>>
>> 1078    if (ret)
>> 1079            return ret;
>> 1080    /* 3.  reenable & set mode to starts things back up */
>> 1081    ni_tio_set_gate_mode(counter, src);
>>
>> 1098    if (ret)
>> 1099            return ret;
>> 1100    /* 3.  reenable & set mode to starts things back up */
>> 1101    ni_tio_set_gate2_mode(counter, src);
>>
>> So, by adding the missing breaks, this patch also fixes the problem
>> above.
>>
>> Addresses-Coverity-ID: 1474165 ("Missing break in switch")
>> Addresses-Coverity-ID: 1474162 ("Structurally dead code")
>> Fixes: 347e244884c3 ("staging: comedi: tio: implement global tio/ctr routing")
>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
>> ---
>>   drivers/staging/comedi/drivers/ni_tio.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/drivers/staging/comedi/drivers/ni_tio.c b/drivers/staging/comedi/drivers/ni_tio.c
>> index 838614e..0eb388c 100644
>> --- a/drivers/staging/comedi/drivers/ni_tio.c
>> +++ b/drivers/staging/comedi/drivers/ni_tio.c
>> @@ -1070,8 +1070,10 @@ int ni_tio_set_gate_src(struct ni_gpct *counter,
>>           case ni_gpct_variant_e_series:
>>           case ni_gpct_variant_m_series:
>>               ret = ni_m_set_gate(counter, chan);
>> +            break;
>>           case ni_gpct_variant_660x:
>>               ret = ni_660x_set_gate(counter, chan);
>> +            break;
>>           default:
>>               return -EINVAL;
>>           }
>> @@ -1090,8 +1092,10 @@ int ni_tio_set_gate_src(struct ni_gpct *counter,
>>           switch (counter_dev->variant) {
>>           case ni_gpct_variant_m_series:
>>               ret = ni_m_set_gate2(counter, chan);
>> +            break;
>>           case ni_gpct_variant_660x:
>>               ret = ni_660x_set_gate2(counter, chan);
>> +            break;
>>           default:
>>               return -EINVAL;
>>           }
>>
> 
> Thanks for catching that bug!
> 

Glad to help. :)

> Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
> 

Thanks
--
Gustavo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-10-12  9:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-11 19:05 [PATCH] staging: comedi: tio: fix multiple missing break in switch bugs Gustavo A. R. Silva
2018-10-12  9:04 ` Ian Abbott
2018-10-12  9:06   ` Gustavo A. R. Silva

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).