Skip to content

Commit 015b4a1

Browse files
agabbasovgregkh
authored andcommitted
ravb: Fix bit fields checking in ravb_hwtstamp_get()
[ Upstream commit 68b9f08 ] In the function ravb_hwtstamp_get() in ravb_main.c with the existing values for RAVB_RXTSTAMP_TYPE_V2_L2_EVENT (0x2) and RAVB_RXTSTAMP_TYPE_ALL (0x6) if (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE_V2_L2_EVENT) config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; else if (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE_ALL) config.rx_filter = HWTSTAMP_FILTER_ALL; if the test on RAVB_RXTSTAMP_TYPE_ALL should be true, it will never be reached. This issue can be verified with 'hwtstamp_config' testing program (tools/testing/selftests/net/hwtstamp_config.c). Setting filter type to ALL and subsequent retrieving it gives incorrect value: $ hwtstamp_config eth0 OFF ALL flags = 0 tx_type = OFF rx_filter = ALL $ hwtstamp_config eth0 flags = 0 tx_type = OFF rx_filter = PTP_V2_L2_EVENT Correct this by converting if-else's to switch. Fixes: c156633 ("Renesas Ethernet AVB driver proper") Reported-by: Julia Lawall <[email protected]> Signed-off-by: Andrew Gabbasov <[email protected]> Reviewed-by: Sergei Shtylyov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 434b20a commit 015b4a1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/net/ethernet/renesas/ravb_main.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -1747,12 +1747,16 @@ static int ravb_hwtstamp_get(struct net_device *ndev, struct ifreq *req)
17471747
config.flags = 0;
17481748
config.tx_type = priv->tstamp_tx_ctrl ? HWTSTAMP_TX_ON :
17491749
HWTSTAMP_TX_OFF;
1750-
if (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE_V2_L2_EVENT)
1750+
switch (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE) {
1751+
case RAVB_RXTSTAMP_TYPE_V2_L2_EVENT:
17511752
config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
1752-
else if (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE_ALL)
1753+
break;
1754+
case RAVB_RXTSTAMP_TYPE_ALL:
17531755
config.rx_filter = HWTSTAMP_FILTER_ALL;
1754-
else
1756+
break;
1757+
default:
17551758
config.rx_filter = HWTSTAMP_FILTER_NONE;
1759+
}
17561760

17571761
return copy_to_user(req->ifr_data, &config, sizeof(config)) ?
17581762
-EFAULT : 0;

0 commit comments

Comments
 (0)