Skip to contentSkip to conversation

can: janz-ican3: initialize dlc variable

PATCH Applied [email protected] 3 participants 3 messages Jan 8, 2022 – Jan 9, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 can: janz-ican3: initialize dlc variable

From: Tom Rix <[email protected]>

Clang static analysis reports this problem
janz-ican3.c:1311:2: warning: Undefined or garbage value returned to caller

        return dlc;
        ^~~~~~~~~~

dlc is only set with this conditional

	if (!(cf->can_id & CAN_RTR_FLAG))
		dlc = cf->len;

But is always returned. So initialize dlc to 0.

Fixes cc4b08c31b5c ("can: do not increase tx_bytes statistics for RTR frames")
---
 drivers/net/can/janz-ican3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/janz-ican3.c +1 -1
index 5b677af5f2a41..808c105cf8f7e 100644
@@ -1285,7 +1285,7 @@ static unsigned int ican3_get_echo_skb(struct ican3_dev *mod)
 {
 	struct sk_buff *skb = skb_dequeue(&mod->echoq);
 	struct can_frame *cf;
-	u8 dlc;
+	u8 dlc = 0;
 
 	/* this should never trigger unless there is a driver bug */
 	if (!skb) {
Signature · 1 line
2.26.3
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · On Sat. 8 Jan 2022 à 23:33, <[email protected]> wrote:

From: Tom Rix <[email protected]>

Clang static analysis reports this problem
janz-ican3.c:1311:2: warning: Undefined or garbage value returned to caller

Quoted 8 lines
        return dlc;
        ^~~~~~~~~~

dlc is only set with this conditional

        if (!(cf->can_id & CAN_RTR_FLAG))
                dlc = cf->len;

But is always returned. So initialize dlc to 0.

Yes. The actual intent is to return a length of 0 for RTR frames.

Quoted 20 lines
Fixes cc4b08c31b5c ("can: do not increase tx_bytes statistics for RTR frames")
---
 drivers/net/can/janz-ican3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/janz-ican3.c +1 -2
index 5b677af5f2a41..808c105cf8f7e 100644
@@ -1285,7 +1285,7 @@ static unsigned int ican3_get_echo_skb(struct ican3_dev *mod)
 {
        struct sk_buff *skb = skb_dequeue(&mod->echoq);
        struct can_frame *cf;
-       u8 dlc;
+       u8 dlc = 0;
 
        /* this should never trigger unless there is a driver bug */
        if (!skb) {
--
Quoted 1 line

2.26.3

I missed that when writing the patch.

I thought that I did my due diligence by running a "make W=1" with GCC but I did not catch the error. I should have been more precocious and run a "make W=2".

Thank you.

#2 lore raw
In reply to [email protected]
This patch was applied to netdev/net-next.git (master) by Marc Kleine-Budde <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by Marc Kleine-Budde <[email protected]>:

Quoted 8 lines · On Sat, 8 Jan 2022 06:33:19 -0800 you wrote:

From: Tom Rix <[email protected]>

Clang static analysis reports this problem
janz-ican3.c:1311:2: warning: Undefined or garbage value returned to caller

        return dlc;
        ^~~~~~~~~~

[...]

Here is the summary with links:
- can: janz-ican3: initialize dlc variable

    https://git.kernel.org/netdev/net-next/c/c57979256283

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html