Skip to contentSkip to conversation

counter: Add default statement to switch() in quad8_function_read()

PATCH Superseded Tim Gardner 1 participant 1 message Sep 20, 2021

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 counter: Add default statement to switch() in quad8_function_read()

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 <[email protected]>
Syed Nayyar Waris <[email protected]>
[email protected]
[email protected]

---
 drivers/counter/104-quad-8.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/counter/104-quad-8.c +2 -0
index c587f295d720..3a69d35b82ea 100644
@@ -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;
Signature · 1 line
2.33.0