lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210921133749.15461-1-tim.gardner@canonical.com>
Date:   Tue, 21 Sep 2021 07:37:49 -0600
From:   Tim Gardner <tim.gardner@...onical.com>
To:     linux-iio@...r.kernel.org
Cc:     tim.gardner@...onical.com,
        William Breathitt Gray <vilhelm.gray@...il.com>,
        Syed Nayyar Waris <syednwaris@...il.com>,
        linux-kernel@...r.kernel.org
Subject: [PATCH v3][next] 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 setting a return error code.

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>
---
v2 - Add the correct Cc's
v3 - Add comment to the default switch statement. Also noticed v2 would have
     returned with a lock held. Fix that by returning a variable return code.
---
 drivers/counter/104-quad-8.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index c587f295d720..7faca6b760e7 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -201,6 +201,7 @@ static int quad8_function_read(struct counter_device *counter,
 {
 	struct quad8 *const priv = counter->priv;
 	const int id = count->id;
+	int ret = 0;
 
 	mutex_lock(&priv->lock);
 
@@ -215,13 +216,16 @@ static int quad8_function_read(struct counter_device *counter,
 		case 2:
 			*function = COUNTER_FUNCTION_QUADRATURE_X4;
 			break;
+		default:
+			/* should never reach this path */
+			ret = -EINVAL;
 		}
 	else
 		*function = COUNTER_FUNCTION_PULSE_DIRECTION;
 
 	mutex_unlock(&priv->lock);
 
-	return 0;
+	return ret;
 }
 
 static int quad8_function_write(struct counter_device *counter,
-- 
2.33.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ