linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] counter: Add default statement to switch() in quad8_function_read()
@ 2021-09-20 17:36 Tim Gardner
  0 siblings, 0 replies; only message in thread
From: Tim Gardner @ 2021-09-20 17:36 UTC (permalink / raw)
  To: linux-iio; +Cc: tim.gardner

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.

William Breathitt Gray <vilhelm.gray@gmail.com>
Syed Nayyar Waris <syednwaris@gmail.com>
linux-iio@vger.kernel.org
linux-kernel@vger.kernel.org
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
---
 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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-20 17:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-20 17:36 [PATCH][next] counter: Add default statement to switch() in quad8_function_read() Tim Gardner

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