Skip to content

Commit 375a683

Browse files
committed
Merge tag 'linux-can-fixes-for-6.0-20220921' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says: ==================== pull-request: can 2022-09-21 The 1st patch is by me, targets the flexcan driver and fixes a potential system hang on single core systems under high CAN packet rate. The next 2 patches are also by me and target the gs_usb driver. A potential race condition during the ndo_open callback as well as the return value if the ethtool identify feature is not supported are fixed. * tag 'linux-can-fixes-for-6.0-20220921' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can: can: gs_usb: gs_usb_set_phys_id(): return with error if identify is not supported can: gs_usb: gs_can_open(): fix race dev->can.state condition can: flexcan: flexcan_mailbox_read() fix return value for drop = true ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 65e5d27 + 0f2211f commit 375a683

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

drivers/net/can/flexcan/flexcan-core.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -941,11 +941,6 @@ static struct sk_buff *flexcan_mailbox_read(struct can_rx_offload *offload,
941941
u32 reg_ctrl, reg_id, reg_iflag1;
942942
int i;
943943

944-
if (unlikely(drop)) {
945-
skb = ERR_PTR(-ENOBUFS);
946-
goto mark_as_read;
947-
}
948-
949944
mb = flexcan_get_mb(priv, n);
950945

951946
if (priv->devtype_data.quirks & FLEXCAN_QUIRK_USE_RX_MAILBOX) {
@@ -974,6 +969,11 @@ static struct sk_buff *flexcan_mailbox_read(struct can_rx_offload *offload,
974969
reg_ctrl = priv->read(&mb->can_ctrl);
975970
}
976971

972+
if (unlikely(drop)) {
973+
skb = ERR_PTR(-ENOBUFS);
974+
goto mark_as_read;
975+
}
976+
977977
if (reg_ctrl & FLEXCAN_MB_CNT_EDL)
978978
skb = alloc_canfd_skb(offload->dev, &cfd);
979979
else

drivers/net/can/usb/gs_usb.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ static int gs_can_open(struct net_device *netdev)
824824
flags |= GS_CAN_MODE_TRIPLE_SAMPLE;
825825

826826
/* finally start device */
827+
dev->can.state = CAN_STATE_ERROR_ACTIVE;
827828
dm->mode = cpu_to_le32(GS_CAN_MODE_START);
828829
dm->flags = cpu_to_le32(flags);
829830
rc = usb_control_msg(interface_to_usbdev(dev->iface),
@@ -835,13 +836,12 @@ static int gs_can_open(struct net_device *netdev)
835836
if (rc < 0) {
836837
netdev_err(netdev, "Couldn't start device (err=%d)\n", rc);
837838
kfree(dm);
839+
dev->can.state = CAN_STATE_STOPPED;
838840
return rc;
839841
}
840842

841843
kfree(dm);
842844

843-
dev->can.state = CAN_STATE_ERROR_ACTIVE;
844-
845845
parent->active_channels++;
846846
if (!(dev->can.ctrlmode & CAN_CTRLMODE_LISTENONLY))
847847
netif_start_queue(netdev);
@@ -925,17 +925,21 @@ static int gs_usb_set_identify(struct net_device *netdev, bool do_identify)
925925
}
926926

927927
/* blink LED's for finding the this interface */
928-
static int gs_usb_set_phys_id(struct net_device *dev,
928+
static int gs_usb_set_phys_id(struct net_device *netdev,
929929
enum ethtool_phys_id_state state)
930930
{
931+
const struct gs_can *dev = netdev_priv(netdev);
931932
int rc = 0;
932933

934+
if (!(dev->feature & GS_CAN_FEATURE_IDENTIFY))
935+
return -EOPNOTSUPP;
936+
933937
switch (state) {
934938
case ETHTOOL_ID_ACTIVE:
935-
rc = gs_usb_set_identify(dev, GS_CAN_IDENTIFY_ON);
939+
rc = gs_usb_set_identify(netdev, GS_CAN_IDENTIFY_ON);
936940
break;
937941
case ETHTOOL_ID_INACTIVE:
938-
rc = gs_usb_set_identify(dev, GS_CAN_IDENTIFY_OFF);
942+
rc = gs_usb_set_identify(netdev, GS_CAN_IDENTIFY_OFF);
939943
break;
940944
default:
941945
break;
@@ -1072,9 +1076,10 @@ static struct gs_can *gs_make_candev(unsigned int channel,
10721076
dev->feature |= GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX |
10731077
GS_CAN_FEATURE_QUIRK_BREQ_CANTACT_PRO;
10741078

1075-
if (le32_to_cpu(dconf->sw_version) > 1)
1076-
if (feature & GS_CAN_FEATURE_IDENTIFY)
1077-
netdev->ethtool_ops = &gs_usb_ethtool_ops;
1079+
/* GS_CAN_FEATURE_IDENTIFY is only supported for sw_version > 1 */
1080+
if (!(le32_to_cpu(dconf->sw_version) > 1 &&
1081+
feature & GS_CAN_FEATURE_IDENTIFY))
1082+
dev->feature &= ~GS_CAN_FEATURE_IDENTIFY;
10781083

10791084
kfree(bt_const);
10801085

0 commit comments

Comments
 (0)