Skip to content

Commit d0742c4

Browse files
committed
Merge tag 'linux-can-fixes-for-5.10-20201127' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says: ==================== pull-request: can 2020-11-27 The first patch is by me and target the gs_usb driver and fixes the endianess problem with candleLight firmware. Another patch by me for the mcp251xfd driver add sanity checking to bail out if no IRQ is configured. The next three patches target the m_can driver. A patch by me removes the hardcoded IRQF_TRIGGER_FALLING from the request_threaded_irq() as this clashes with the trigger level specified in the DT. Further a patch by me fixes the nominal bitiming tseg2 min value for modern m_can cores. Pankaj Sharma's patch add support for cores version 3.3.x. The last patch by Oliver Hartkopp is for af_can and converts a WARN() into a pr_warn(), which is triggered by the syzkaller. It was able to create a situation where the closing of a socket runs simultaneously to the notifier call chain for removing the CAN network device in use. * tag 'linux-can-fixes-for-5.10-20201127' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can: can: af_can: can_rx_unregister(): remove WARN() statement from list operation sanity check can: m_can: m_can_dev_setup(): add support for bosch mcan version 3.3.0 can: m_can: fix nominal bitiming tseg2 min for version >= 3.1 can: m_can: m_can_open(): remove IRQF_TRIGGER_FALLING from request_threaded_irq()'s flags can: mcp251xfd: mcp251xfd_probe(): bail out if no IRQ was given can: gs_usb: fix endianess problem with candleLight firmware ==================== Link: https://lore.kernel.org/r/20201127100301.512603-1-mkl@pengutronix.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 985f733 + d73ff9b commit d0742c4

4 files changed

Lines changed: 83 additions & 65 deletions

File tree

drivers/net/can/m_can/m_can.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ static const struct can_bittiming_const m_can_bittiming_const_31X = {
10331033
.name = KBUILD_MODNAME,
10341034
.tseg1_min = 2, /* Time segment 1 = prop_seg + phase_seg1 */
10351035
.tseg1_max = 256,
1036-
.tseg2_min = 1, /* Time segment 2 = phase_seg2 */
1036+
.tseg2_min = 2, /* Time segment 2 = phase_seg2 */
10371037
.tseg2_max = 128,
10381038
.sjw_max = 128,
10391039
.brp_min = 1,
@@ -1385,6 +1385,8 @@ static int m_can_dev_setup(struct m_can_classdev *m_can_dev)
13851385
&m_can_data_bittiming_const_31X;
13861386
break;
13871387
case 32:
1388+
case 33:
1389+
/* Support both MCAN version v3.2.x and v3.3.0 */
13881390
m_can_dev->can.bittiming_const = m_can_dev->bit_timing ?
13891391
m_can_dev->bit_timing : &m_can_bittiming_const_31X;
13901392

@@ -1653,7 +1655,7 @@ static int m_can_open(struct net_device *dev)
16531655
INIT_WORK(&cdev->tx_work, m_can_tx_work_queue);
16541656

16551657
err = request_threaded_irq(dev->irq, NULL, m_can_isr,
1656-
IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
1658+
IRQF_ONESHOT,
16571659
dev->name, dev);
16581660
} else {
16591661
err = request_irq(dev->irq, m_can_isr, IRQF_SHARED, dev->name,

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,6 +2738,10 @@ static int mcp251xfd_probe(struct spi_device *spi)
27382738
u32 freq;
27392739
int err;
27402740

2741+
if (!spi->irq)
2742+
return dev_err_probe(&spi->dev, -ENXIO,
2743+
"No IRQ specified (maybe node \"interrupts-extended\" in DT missing)!\n");
2744+
27412745
rx_int = devm_gpiod_get_optional(&spi->dev, "microchip,rx-int",
27422746
GPIOD_IN);
27432747
if (PTR_ERR(rx_int) == -EPROBE_DEFER)

drivers/net/can/usb/gs_usb.c

Lines changed: 70 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,27 @@ enum gs_can_identify_mode {
6363
};
6464

6565
/* data types passed between host and device */
66+
67+
/* The firmware on the original USB2CAN by Geschwister Schneider
68+
* Technologie Entwicklungs- und Vertriebs UG exchanges all data
69+
* between the host and the device in host byte order. This is done
70+
* with the struct gs_host_config::byte_order member, which is sent
71+
* first to indicate the desired byte order.
72+
*
73+
* The widely used open source firmware candleLight doesn't support
74+
* this feature and exchanges the data in little endian byte order.
75+
*/
6676
struct gs_host_config {
67-
u32 byte_order;
77+
__le32 byte_order;
6878
} __packed;
69-
/* All data exchanged between host and device is exchanged in host byte order,
70-
* thanks to the struct gs_host_config byte_order member, which is sent first
71-
* to indicate the desired byte order.
72-
*/
7379

7480
struct gs_device_config {
7581
u8 reserved1;
7682
u8 reserved2;
7783
u8 reserved3;
7884
u8 icount;
79-
u32 sw_version;
80-
u32 hw_version;
85+
__le32 sw_version;
86+
__le32 hw_version;
8187
} __packed;
8288

8389
#define GS_CAN_MODE_NORMAL 0
@@ -87,26 +93,26 @@ struct gs_device_config {
8793
#define GS_CAN_MODE_ONE_SHOT BIT(3)
8894

8995
struct gs_device_mode {
90-
u32 mode;
91-
u32 flags;
96+
__le32 mode;
97+
__le32 flags;
9298
} __packed;
9399

94100
struct gs_device_state {
95-
u32 state;
96-
u32 rxerr;
97-
u32 txerr;
101+
__le32 state;
102+
__le32 rxerr;
103+
__le32 txerr;
98104
} __packed;
99105

100106
struct gs_device_bittiming {
101-
u32 prop_seg;
102-
u32 phase_seg1;
103-
u32 phase_seg2;
104-
u32 sjw;
105-
u32 brp;
107+
__le32 prop_seg;
108+
__le32 phase_seg1;
109+
__le32 phase_seg2;
110+
__le32 sjw;
111+
__le32 brp;
106112
} __packed;
107113

108114
struct gs_identify_mode {
109-
u32 mode;
115+
__le32 mode;
110116
} __packed;
111117

112118
#define GS_CAN_FEATURE_LISTEN_ONLY BIT(0)
@@ -117,23 +123,23 @@ struct gs_identify_mode {
117123
#define GS_CAN_FEATURE_IDENTIFY BIT(5)
118124

119125
struct gs_device_bt_const {
120-
u32 feature;
121-
u32 fclk_can;
122-
u32 tseg1_min;
123-
u32 tseg1_max;
124-
u32 tseg2_min;
125-
u32 tseg2_max;
126-
u32 sjw_max;
127-
u32 brp_min;
128-
u32 brp_max;
129-
u32 brp_inc;
126+
__le32 feature;
127+
__le32 fclk_can;
128+
__le32 tseg1_min;
129+
__le32 tseg1_max;
130+
__le32 tseg2_min;
131+
__le32 tseg2_max;
132+
__le32 sjw_max;
133+
__le32 brp_min;
134+
__le32 brp_max;
135+
__le32 brp_inc;
130136
} __packed;
131137

132138
#define GS_CAN_FLAG_OVERFLOW 1
133139

134140
struct gs_host_frame {
135141
u32 echo_id;
136-
u32 can_id;
142+
__le32 can_id;
137143

138144
u8 can_dlc;
139145
u8 channel;
@@ -329,13 +335,13 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
329335
if (!skb)
330336
return;
331337

332-
cf->can_id = hf->can_id;
338+
cf->can_id = le32_to_cpu(hf->can_id);
333339

334340
cf->can_dlc = get_can_dlc(hf->can_dlc);
335341
memcpy(cf->data, hf->data, 8);
336342

337343
/* ERROR frames tell us information about the controller */
338-
if (hf->can_id & CAN_ERR_FLAG)
344+
if (le32_to_cpu(hf->can_id) & CAN_ERR_FLAG)
339345
gs_update_state(dev, cf);
340346

341347
netdev->stats.rx_packets++;
@@ -418,11 +424,11 @@ static int gs_usb_set_bittiming(struct net_device *netdev)
418424
if (!dbt)
419425
return -ENOMEM;
420426

421-
dbt->prop_seg = bt->prop_seg;
422-
dbt->phase_seg1 = bt->phase_seg1;
423-
dbt->phase_seg2 = bt->phase_seg2;
424-
dbt->sjw = bt->sjw;
425-
dbt->brp = bt->brp;
427+
dbt->prop_seg = cpu_to_le32(bt->prop_seg);
428+
dbt->phase_seg1 = cpu_to_le32(bt->phase_seg1);
429+
dbt->phase_seg2 = cpu_to_le32(bt->phase_seg2);
430+
dbt->sjw = cpu_to_le32(bt->sjw);
431+
dbt->brp = cpu_to_le32(bt->brp);
426432

427433
/* request bit timings */
428434
rc = usb_control_msg(interface_to_usbdev(intf),
@@ -503,7 +509,7 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb,
503509

504510
cf = (struct can_frame *)skb->data;
505511

506-
hf->can_id = cf->can_id;
512+
hf->can_id = cpu_to_le32(cf->can_id);
507513
hf->can_dlc = cf->can_dlc;
508514
memcpy(hf->data, cf->data, cf->can_dlc);
509515

@@ -573,6 +579,7 @@ static int gs_can_open(struct net_device *netdev)
573579
int rc, i;
574580
struct gs_device_mode *dm;
575581
u32 ctrlmode;
582+
u32 flags = 0;
576583

577584
rc = open_candev(netdev);
578585
if (rc)
@@ -640,24 +647,24 @@ static int gs_can_open(struct net_device *netdev)
640647

641648
/* flags */
642649
ctrlmode = dev->can.ctrlmode;
643-
dm->flags = 0;
644650

645651
if (ctrlmode & CAN_CTRLMODE_LOOPBACK)
646-
dm->flags |= GS_CAN_MODE_LOOP_BACK;
652+
flags |= GS_CAN_MODE_LOOP_BACK;
647653
else if (ctrlmode & CAN_CTRLMODE_LISTENONLY)
648-
dm->flags |= GS_CAN_MODE_LISTEN_ONLY;
654+
flags |= GS_CAN_MODE_LISTEN_ONLY;
649655

650656
/* Controller is not allowed to retry TX
651657
* this mode is unavailable on atmels uc3c hardware
652658
*/
653659
if (ctrlmode & CAN_CTRLMODE_ONE_SHOT)
654-
dm->flags |= GS_CAN_MODE_ONE_SHOT;
660+
flags |= GS_CAN_MODE_ONE_SHOT;
655661

656662
if (ctrlmode & CAN_CTRLMODE_3_SAMPLES)
657-
dm->flags |= GS_CAN_MODE_TRIPLE_SAMPLE;
663+
flags |= GS_CAN_MODE_TRIPLE_SAMPLE;
658664

659665
/* finally start device */
660-
dm->mode = GS_CAN_MODE_START;
666+
dm->mode = cpu_to_le32(GS_CAN_MODE_START);
667+
dm->flags = cpu_to_le32(flags);
661668
rc = usb_control_msg(interface_to_usbdev(dev->iface),
662669
usb_sndctrlpipe(interface_to_usbdev(dev->iface), 0),
663670
GS_USB_BREQ_MODE,
@@ -737,9 +744,9 @@ static int gs_usb_set_identify(struct net_device *netdev, bool do_identify)
737744
return -ENOMEM;
738745

739746
if (do_identify)
740-
imode->mode = GS_CAN_IDENTIFY_ON;
747+
imode->mode = cpu_to_le32(GS_CAN_IDENTIFY_ON);
741748
else
742-
imode->mode = GS_CAN_IDENTIFY_OFF;
749+
imode->mode = cpu_to_le32(GS_CAN_IDENTIFY_OFF);
743750

744751
rc = usb_control_msg(interface_to_usbdev(dev->iface),
745752
usb_sndctrlpipe(interface_to_usbdev(dev->iface),
@@ -790,6 +797,7 @@ static struct gs_can *gs_make_candev(unsigned int channel,
790797
struct net_device *netdev;
791798
int rc;
792799
struct gs_device_bt_const *bt_const;
800+
u32 feature;
793801

794802
bt_const = kmalloc(sizeof(*bt_const), GFP_KERNEL);
795803
if (!bt_const)
@@ -830,14 +838,14 @@ static struct gs_can *gs_make_candev(unsigned int channel,
830838

831839
/* dev setup */
832840
strcpy(dev->bt_const.name, "gs_usb");
833-
dev->bt_const.tseg1_min = bt_const->tseg1_min;
834-
dev->bt_const.tseg1_max = bt_const->tseg1_max;
835-
dev->bt_const.tseg2_min = bt_const->tseg2_min;
836-
dev->bt_const.tseg2_max = bt_const->tseg2_max;
837-
dev->bt_const.sjw_max = bt_const->sjw_max;
838-
dev->bt_const.brp_min = bt_const->brp_min;
839-
dev->bt_const.brp_max = bt_const->brp_max;
840-
dev->bt_const.brp_inc = bt_const->brp_inc;
841+
dev->bt_const.tseg1_min = le32_to_cpu(bt_const->tseg1_min);
842+
dev->bt_const.tseg1_max = le32_to_cpu(bt_const->tseg1_max);
843+
dev->bt_const.tseg2_min = le32_to_cpu(bt_const->tseg2_min);
844+
dev->bt_const.tseg2_max = le32_to_cpu(bt_const->tseg2_max);
845+
dev->bt_const.sjw_max = le32_to_cpu(bt_const->sjw_max);
846+
dev->bt_const.brp_min = le32_to_cpu(bt_const->brp_min);
847+
dev->bt_const.brp_max = le32_to_cpu(bt_const->brp_max);
848+
dev->bt_const.brp_inc = le32_to_cpu(bt_const->brp_inc);
841849

842850
dev->udev = interface_to_usbdev(intf);
843851
dev->iface = intf;
@@ -854,28 +862,29 @@ static struct gs_can *gs_make_candev(unsigned int channel,
854862

855863
/* can setup */
856864
dev->can.state = CAN_STATE_STOPPED;
857-
dev->can.clock.freq = bt_const->fclk_can;
865+
dev->can.clock.freq = le32_to_cpu(bt_const->fclk_can);
858866
dev->can.bittiming_const = &dev->bt_const;
859867
dev->can.do_set_bittiming = gs_usb_set_bittiming;
860868

861869
dev->can.ctrlmode_supported = 0;
862870

863-
if (bt_const->feature & GS_CAN_FEATURE_LISTEN_ONLY)
871+
feature = le32_to_cpu(bt_const->feature);
872+
if (feature & GS_CAN_FEATURE_LISTEN_ONLY)
864873
dev->can.ctrlmode_supported |= CAN_CTRLMODE_LISTENONLY;
865874

866-
if (bt_const->feature & GS_CAN_FEATURE_LOOP_BACK)
875+
if (feature & GS_CAN_FEATURE_LOOP_BACK)
867876
dev->can.ctrlmode_supported |= CAN_CTRLMODE_LOOPBACK;
868877

869-
if (bt_const->feature & GS_CAN_FEATURE_TRIPLE_SAMPLE)
878+
if (feature & GS_CAN_FEATURE_TRIPLE_SAMPLE)
870879
dev->can.ctrlmode_supported |= CAN_CTRLMODE_3_SAMPLES;
871880

872-
if (bt_const->feature & GS_CAN_FEATURE_ONE_SHOT)
881+
if (feature & GS_CAN_FEATURE_ONE_SHOT)
873882
dev->can.ctrlmode_supported |= CAN_CTRLMODE_ONE_SHOT;
874883

875884
SET_NETDEV_DEV(netdev, &intf->dev);
876885

877-
if (dconf->sw_version > 1)
878-
if (bt_const->feature & GS_CAN_FEATURE_IDENTIFY)
886+
if (le32_to_cpu(dconf->sw_version) > 1)
887+
if (feature & GS_CAN_FEATURE_IDENTIFY)
879888
netdev->ethtool_ops = &gs_usb_ethtool_ops;
880889

881890
kfree(bt_const);
@@ -910,7 +919,7 @@ static int gs_usb_probe(struct usb_interface *intf,
910919
if (!hconf)
911920
return -ENOMEM;
912921

913-
hconf->byte_order = 0x0000beef;
922+
hconf->byte_order = cpu_to_le32(0x0000beef);
914923

915924
/* send host config */
916925
rc = usb_control_msg(interface_to_usbdev(intf),

net/can/af_can.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,13 @@ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id,
541541

542542
/* Check for bugs in CAN protocol implementations using af_can.c:
543543
* 'rcv' will be NULL if no matching list item was found for removal.
544+
* As this case may potentially happen when closing a socket while
545+
* the notifier for removing the CAN netdev is running we just print
546+
* a warning here.
544547
*/
545548
if (!rcv) {
546-
WARN(1, "BUG: receive list entry not found for dev %s, id %03X, mask %03X\n",
547-
DNAME(dev), can_id, mask);
549+
pr_warn("can: receive list entry not found for dev %s, id %03X, mask %03X\n",
550+
DNAME(dev), can_id, mask);
548551
goto out;
549552
}
550553

0 commit comments

Comments
 (0)