linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tim Gardner <tim.gardner@canonical.com>
To: linux-iio@vger.kernel.org
Cc: tim.gardner@canonical.com,
	William Breathitt Gray <vilhelm.gray@gmail.com>,
	Syed Nayyar Waris <syednwaris@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v3][next] counter: Add default statement to switch() in quad8_function_read()
Date: Tue, 21 Sep 2021 07:37:49 -0600	[thread overview]
Message-ID: <20210921133749.15461-1-tim.gardner@canonical.com> (raw)
In-Reply-To: <YUkpBU8mN4yrDfu5@shinobu>

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


  reply	other threads:[~2021-09-21 13:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-20 17:37 [PATCH v2][next] counter: Add default statement to switch() in quad8_function_read() Tim Gardner
2021-09-21  0:36 ` William Breathitt Gray
2021-09-21 13:37   ` Tim Gardner [this message]
2021-09-21 22:51     ` [PATCH v3][next] " William Breathitt Gray

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210921133749.15461-1-tim.gardner@canonical.com \
    --to=tim.gardner@canonical.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syednwaris@gmail.com \
    --cc=vilhelm.gray@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).