Commit 8e674ca7 authored by Vincent Mailhol's avatar Vincent Mailhol Committed by Marc Kleine-Budde
Browse files

can: do not increase rx_bytes statistics for RTR frames

The actual payload length of the CAN Remote Transmission Request (RTR)
frames is always 0, i.e. no payload is transmitted on the wire.
However, those RTR frames still use the DLC to indicate the length of
the requested frame.

As such, net_device_stats::rx_bytes should not be increased for the
RTR frames.

This patch fixes all the CAN drivers.

Link: https://lore.kernel.org/all/20211207121531.42941-5-mailhol.vincent@wanadoo.fr


Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Ludovic Desroches <ludovic.desroches@microchip.com>
Cc: Chandrasekar Ramakrishnan <rcsekar@samsung.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Chen-Yu Tsai <wens@csie.org>
Cc: Jernej Skrabec <jernej.skrabec@gmail.com>
Cc: Yasushi SHOJI <yashi@spacecubics.com>
Cc: Appana Durga Kedareswara rao <appana.durga.rao@xilinx.com>
Cc: Naga Sureshkumar Relli <naga.sureshkumar.relli@xilinx.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Stephane Grosjean <s.grosjean@peak-system.com>
Tested-by: Jimmy Assarsson <extja@kvaser.com> # kvaser
Signed-off-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Stefan Mätje <stefan.maetje@esd.eu> # esd_usb2
Tested-by: Stefan Mätje <stefan.maetje@esd.eu> # esd_usb2
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent f68eafeb
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -617,7 +617,9 @@ static void at91_read_msg(struct net_device *dev, unsigned int mb)
	at91_read_mb(dev, mb, cf);

	stats->rx_packets++;
	if (!(cf->can_id & CAN_RTR_FLAG))
		stats->rx_bytes += cf->len;

	netif_receive_skb(skb);

	can_led_event(dev, CAN_LED_EVENT_RX);
+2 −2
Original line number Diff line number Diff line
@@ -403,10 +403,10 @@ static int c_can_read_msg_object(struct net_device *dev, int iface, u32 ctrl)
				frame->data[i + 1] = data >> 8;
			}
		}
	}

	stats->rx_packets++;
		stats->rx_bytes += frame->len;
	}
	stats->rx_packets++;

	netif_receive_skb(skb);
	return 0;
+3 −2
Original line number Diff line number Diff line
@@ -489,10 +489,11 @@ static void cc770_rx(struct net_device *dev, unsigned int mo, u8 ctrl1)
		cf->len = can_cc_dlc2len((config & 0xf0) >> 4);
		for (i = 0; i < cf->len; i++)
			cf->data[i] = cc770_read_reg(priv, msgobj[mo].data[i]);
	}

	stats->rx_packets++;
		stats->rx_bytes += cf->len;
	}
	stats->rx_packets++;

	netif_rx(skb);
}

+2 −1
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ static int can_rx_offload_napi_poll(struct napi_struct *napi, int quota)
		work_done++;
		if (!(cf->can_id & CAN_ERR_FLAG)) {
			stats->rx_packets++;
			if (!(cf->can_id & CAN_RTR_FLAG))
				stats->rx_bytes += cf->len;
		}
		netif_receive_skb(skb);
+3 −3
Original line number Diff line number Diff line
@@ -1211,11 +1211,11 @@ static int grcan_receive(struct net_device *dev, int budget)
				shift = GRCAN_MSG_DATA_SHIFT(i);
				cf->data[i] = (u8)(slot[j] >> shift);
			}
		}

		/* Update statistics and read pointer */
		stats->rx_packets++;
			stats->rx_bytes += cf->len;
		}
		stats->rx_packets++;

		netif_receive_skb(skb);

		rd = grcan_ring_add(rd, GRCAN_MSG_SIZE, dma->rx.size);
Loading