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: <20241126-illegal-prehistoric-mongoose-1a61ad-mkl@pengutronix.de>
Date: Tue, 26 Nov 2024 10:32:54 +0100
From: Marc Kleine-Budde <mkl@...gutronix.de>
To: Dario Binacchi <dario.binacchi@...rulasolutions.com>
Cc: linux-kernel@...r.kernel.org, linux-amarula@...rulasolutions.com, 
	Chen-Yu Tsai <wens@...e.org>, Gerhard Bertelsmann <info@...hard-bertelsmann.de>, 
	Jernej Skrabec <jernej.skrabec@...il.com>, Maxime Ripard <mripard@...nel.org>, 
	Samuel Holland <samuel@...lland.org>, Vincent Mailhol <mailhol.vincent@...adoo.fr>, 
	linux-arm-kernel@...ts.infradead.org, linux-can@...r.kernel.org, linux-sunxi@...ts.linux.dev
Subject: Re: [PATCH v2 10/12] can: sun4i_can: fix {rx,tx}_errors statistics

On 22.11.2024 23:15:51, Dario Binacchi wrote:
> The sun4i_can_err() function only incremented the receive error counter
> and never the transmit error counter, even if the STA_ERR_DIR flag
> reported that an error had occurred during transmission. Increment the
> receive/transmit error counter based on the value of the STA_ERR_DIR
> flag.
> 
> Fixes: 0738eff14d81 ("can: Allwinner A10/A20 CAN Controller support - Kernel module")
> Signed-off-by: Dario Binacchi <dario.binacchi@...rulasolutions.com>

Fails to build from source:

| drivers/net/can/sun4i_can.c:583:7: error: variable 'ecc' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
|   583 |                 if (likely(skb)) {
|       |                     ^~~~~~~~~~~
| include/linux/compiler.h:76:20: note: expanded from macro 'likely'
|    76 | # define likely(x)      __builtin_expect(!!(x), 1)
|       |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~
| drivers/net/can/sun4i_can.c:606:8: note: uninitialized use occurs here
|   606 |                 if ((ecc & SUN4I_STA_ERR_DIR) == 0) {
|       |                      ^~~
| drivers/net/can/sun4i_can.c:583:3: note: remove the 'if' if its condition is always true
|   583 |                 if (likely(skb)) {
|       |                 ^~~~~~~~~~~~~~~~
| drivers/net/can/sun4i_can.c:534:9: note: initialize the variable 'ecc' to silence this warning
|   534 |         u32 ecc, alc;
|       |                ^
|       |                 = 0
| 1 error generated.

Fixes by moving the "ecc = readl();":

--- a/drivers/net/can/sun4i_can.c
+++ b/drivers/net/can/sun4i_can.c
@@ -579,11 +579,9 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status)
                 /* bus error interrupt */
                 netdev_dbg(dev, "bus error interrupt\n");
                 priv->can.can_stats.bus_error++;
-                stats->rx_errors++;
+                ecc = readl(priv->base + SUN4I_REG_STA_ADDR);
 
                 if (likely(skb)) {
-                        ecc = readl(priv->base + SUN4I_REG_STA_ADDR);
-
                         cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
 
                         switch (ecc & SUN4I_STA_MASK_ERR) {
@@ -601,9 +599,15 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status)
                                                >> 16;
                                 break;
                         }
-                        /* error occurred during transmission? */
-                        if ((ecc & SUN4I_STA_ERR_DIR) == 0)
+                }
+
+                /* error occurred during transmission? */
+                if ((ecc & SUN4I_STA_ERR_DIR) == 0) {
+                        if (likely(skb))
                                 cf->data[2] |= CAN_ERR_PROT_TX;
+                        stats->tx_errors++;
+                } else {
+                        stats->rx_errors++;
                 }
         }
         if (isrc & SUN4I_INT_ERR_PASSIVE) {


Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ