Skip to content

Commit 2a62df3

Browse files
committed
Merge tag 'linux-can-fixes-for-5.16-20211207' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says: ==================== can 2021-12-07 The 1st patch is by Vincent Mailhol and fixes a use after free in the pch_can driver. Dan Carpenter fixes a use after free in the ems_pcmcia sja1000 driver. The remaining 7 patches target the m_can driver. Brian Silverman contributes a patch to disable and ignore the ELO interrupt, which is currently not handled in the driver and may lead to an interrupt storm. Vincent Mailhol's patch fixes a memory leak in the error path of the m_can_read_fifo() function. The remaining patches are contributed by Matthias Schiffer, first a iomap_read_fifo() and iomap_write_fifo() functions are fixed in the PCI glue driver, then the clock rate for the Intel Ekhart Lake platform is fixed, the last 3 patches add support for the custom bit timings on the Elkhart Lake platform. * tag 'linux-can-fixes-for-5.16-20211207' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can: can: m_can: pci: use custom bit timings for Elkhart Lake can: m_can: make custom bittiming fields const Revert "can: m_can: remove support for custom bit timing" can: m_can: pci: fix incorrect reference clock rate can: m_can: pci: fix iomap_read_fifo() and iomap_write_fifo() can: m_can: m_can_read_fifo: fix memory leak in error branch can: m_can: Disable and ignore ELO interrupt can: sja1000: fix use after free in ems_pcmcia_add_card() can: pch_can: pch_can_rx_normal: fix use after free ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 4dbb0da + ea4c178 commit 2a62df3

File tree

5 files changed

+93
-23
lines changed

5 files changed

+93
-23
lines changed

drivers/net/can/m_can/m_can.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,16 @@ enum m_can_reg {
204204

205205
/* Interrupts for version 3.0.x */
206206
#define IR_ERR_LEC_30X (IR_STE | IR_FOE | IR_ACKE | IR_BE | IR_CRCE)
207-
#define IR_ERR_BUS_30X (IR_ERR_LEC_30X | IR_WDI | IR_ELO | IR_BEU | \
208-
IR_BEC | IR_TOO | IR_MRAF | IR_TSW | IR_TEFL | \
209-
IR_RF1L | IR_RF0L)
207+
#define IR_ERR_BUS_30X (IR_ERR_LEC_30X | IR_WDI | IR_BEU | IR_BEC | \
208+
IR_TOO | IR_MRAF | IR_TSW | IR_TEFL | IR_RF1L | \
209+
IR_RF0L)
210210
#define IR_ERR_ALL_30X (IR_ERR_STATE | IR_ERR_BUS_30X)
211211

212212
/* Interrupts for version >= 3.1.x */
213213
#define IR_ERR_LEC_31X (IR_PED | IR_PEA)
214-
#define IR_ERR_BUS_31X (IR_ERR_LEC_31X | IR_WDI | IR_ELO | IR_BEU | \
215-
IR_BEC | IR_TOO | IR_MRAF | IR_TSW | IR_TEFL | \
216-
IR_RF1L | IR_RF0L)
214+
#define IR_ERR_BUS_31X (IR_ERR_LEC_31X | IR_WDI | IR_BEU | IR_BEC | \
215+
IR_TOO | IR_MRAF | IR_TSW | IR_TEFL | IR_RF1L | \
216+
IR_RF0L)
217217
#define IR_ERR_ALL_31X (IR_ERR_STATE | IR_ERR_BUS_31X)
218218

219219
/* Interrupt Line Select (ILS) */
@@ -517,7 +517,7 @@ static int m_can_read_fifo(struct net_device *dev, u32 rxfs)
517517
err = m_can_fifo_read(cdev, fgi, M_CAN_FIFO_DATA,
518518
cf->data, DIV_ROUND_UP(cf->len, 4));
519519
if (err)
520-
goto out_fail;
520+
goto out_free_skb;
521521
}
522522

523523
/* acknowledge rx fifo 0 */
@@ -532,6 +532,8 @@ static int m_can_read_fifo(struct net_device *dev, u32 rxfs)
532532

533533
return 0;
534534

535+
out_free_skb:
536+
kfree_skb(skb);
535537
out_fail:
536538
netdev_err(dev, "FIFO read returned %d\n", err);
537539
return err;
@@ -810,8 +812,6 @@ static void m_can_handle_other_err(struct net_device *dev, u32 irqstatus)
810812
{
811813
if (irqstatus & IR_WDI)
812814
netdev_err(dev, "Message RAM Watchdog event due to missing READY\n");
813-
if (irqstatus & IR_ELO)
814-
netdev_err(dev, "Error Logging Overflow\n");
815815
if (irqstatus & IR_BEU)
816816
netdev_err(dev, "Bit Error Uncorrected\n");
817817
if (irqstatus & IR_BEC)
@@ -1494,20 +1494,32 @@ static int m_can_dev_setup(struct m_can_classdev *cdev)
14941494
case 30:
14951495
/* CAN_CTRLMODE_FD_NON_ISO is fixed with M_CAN IP v3.0.x */
14961496
can_set_static_ctrlmode(dev, CAN_CTRLMODE_FD_NON_ISO);
1497-
cdev->can.bittiming_const = &m_can_bittiming_const_30X;
1498-
cdev->can.data_bittiming_const = &m_can_data_bittiming_const_30X;
1497+
cdev->can.bittiming_const = cdev->bit_timing ?
1498+
cdev->bit_timing : &m_can_bittiming_const_30X;
1499+
1500+
cdev->can.data_bittiming_const = cdev->data_timing ?
1501+
cdev->data_timing :
1502+
&m_can_data_bittiming_const_30X;
14991503
break;
15001504
case 31:
15011505
/* CAN_CTRLMODE_FD_NON_ISO is fixed with M_CAN IP v3.1.x */
15021506
can_set_static_ctrlmode(dev, CAN_CTRLMODE_FD_NON_ISO);
1503-
cdev->can.bittiming_const = &m_can_bittiming_const_31X;
1504-
cdev->can.data_bittiming_const = &m_can_data_bittiming_const_31X;
1507+
cdev->can.bittiming_const = cdev->bit_timing ?
1508+
cdev->bit_timing : &m_can_bittiming_const_31X;
1509+
1510+
cdev->can.data_bittiming_const = cdev->data_timing ?
1511+
cdev->data_timing :
1512+
&m_can_data_bittiming_const_31X;
15051513
break;
15061514
case 32:
15071515
case 33:
15081516
/* Support both MCAN version v3.2.x and v3.3.0 */
1509-
cdev->can.bittiming_const = &m_can_bittiming_const_31X;
1510-
cdev->can.data_bittiming_const = &m_can_data_bittiming_const_31X;
1517+
cdev->can.bittiming_const = cdev->bit_timing ?
1518+
cdev->bit_timing : &m_can_bittiming_const_31X;
1519+
1520+
cdev->can.data_bittiming_const = cdev->data_timing ?
1521+
cdev->data_timing :
1522+
&m_can_data_bittiming_const_31X;
15111523

15121524
cdev->can.ctrlmode_supported |=
15131525
(m_can_niso_supported(cdev) ?

drivers/net/can/m_can/m_can.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ struct m_can_classdev {
8585
struct sk_buff *tx_skb;
8686
struct phy *transceiver;
8787

88+
const struct can_bittiming_const *bit_timing;
89+
const struct can_bittiming_const *data_timing;
90+
8891
struct m_can_ops *ops;
8992

9093
int version;

drivers/net/can/m_can/m_can_pci.c

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818

1919
#define M_CAN_PCI_MMIO_BAR 0
2020

21-
#define M_CAN_CLOCK_FREQ_EHL 100000000
2221
#define CTL_CSR_INT_CTL_OFFSET 0x508
2322

23+
struct m_can_pci_config {
24+
const struct can_bittiming_const *bit_timing;
25+
const struct can_bittiming_const *data_timing;
26+
unsigned int clock_freq;
27+
};
28+
2429
struct m_can_pci_priv {
2530
struct m_can_classdev cdev;
2631

@@ -42,8 +47,13 @@ static u32 iomap_read_reg(struct m_can_classdev *cdev, int reg)
4247
static int iomap_read_fifo(struct m_can_classdev *cdev, int offset, void *val, size_t val_count)
4348
{
4449
struct m_can_pci_priv *priv = cdev_to_priv(cdev);
50+
void __iomem *src = priv->base + offset;
4551

46-
ioread32_rep(priv->base + offset, val, val_count);
52+
while (val_count--) {
53+
*(unsigned int *)val = ioread32(src);
54+
val += 4;
55+
src += 4;
56+
}
4757

4858
return 0;
4959
}
@@ -61,8 +71,13 @@ static int iomap_write_fifo(struct m_can_classdev *cdev, int offset,
6171
const void *val, size_t val_count)
6272
{
6373
struct m_can_pci_priv *priv = cdev_to_priv(cdev);
74+
void __iomem *dst = priv->base + offset;
6475

65-
iowrite32_rep(priv->base + offset, val, val_count);
76+
while (val_count--) {
77+
iowrite32(*(unsigned int *)val, dst);
78+
val += 4;
79+
dst += 4;
80+
}
6681

6782
return 0;
6883
}
@@ -74,9 +89,40 @@ static struct m_can_ops m_can_pci_ops = {
7489
.read_fifo = iomap_read_fifo,
7590
};
7691

92+
static const struct can_bittiming_const m_can_bittiming_const_ehl = {
93+
.name = KBUILD_MODNAME,
94+
.tseg1_min = 2, /* Time segment 1 = prop_seg + phase_seg1 */
95+
.tseg1_max = 64,
96+
.tseg2_min = 1, /* Time segment 2 = phase_seg2 */
97+
.tseg2_max = 128,
98+
.sjw_max = 128,
99+
.brp_min = 1,
100+
.brp_max = 512,
101+
.brp_inc = 1,
102+
};
103+
104+
static const struct can_bittiming_const m_can_data_bittiming_const_ehl = {
105+
.name = KBUILD_MODNAME,
106+
.tseg1_min = 2, /* Time segment 1 = prop_seg + phase_seg1 */
107+
.tseg1_max = 16,
108+
.tseg2_min = 1, /* Time segment 2 = phase_seg2 */
109+
.tseg2_max = 8,
110+
.sjw_max = 4,
111+
.brp_min = 1,
112+
.brp_max = 32,
113+
.brp_inc = 1,
114+
};
115+
116+
static const struct m_can_pci_config m_can_pci_ehl = {
117+
.bit_timing = &m_can_bittiming_const_ehl,
118+
.data_timing = &m_can_data_bittiming_const_ehl,
119+
.clock_freq = 200000000,
120+
};
121+
77122
static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
78123
{
79124
struct device *dev = &pci->dev;
125+
const struct m_can_pci_config *cfg;
80126
struct m_can_classdev *mcan_class;
81127
struct m_can_pci_priv *priv;
82128
void __iomem *base;
@@ -104,6 +150,8 @@ static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
104150
if (!mcan_class)
105151
return -ENOMEM;
106152

153+
cfg = (const struct m_can_pci_config *)id->driver_data;
154+
107155
priv = cdev_to_priv(mcan_class);
108156

109157
priv->base = base;
@@ -115,7 +163,9 @@ static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
115163
mcan_class->dev = &pci->dev;
116164
mcan_class->net->irq = pci_irq_vector(pci, 0);
117165
mcan_class->pm_clock_support = 1;
118-
mcan_class->can.clock.freq = id->driver_data;
166+
mcan_class->bit_timing = cfg->bit_timing;
167+
mcan_class->data_timing = cfg->data_timing;
168+
mcan_class->can.clock.freq = cfg->clock_freq;
119169
mcan_class->ops = &m_can_pci_ops;
120170

121171
pci_set_drvdata(pci, mcan_class);
@@ -168,8 +218,8 @@ static SIMPLE_DEV_PM_OPS(m_can_pci_pm_ops,
168218
m_can_pci_suspend, m_can_pci_resume);
169219

170220
static const struct pci_device_id m_can_pci_id_table[] = {
171-
{ PCI_VDEVICE(INTEL, 0x4bc1), M_CAN_CLOCK_FREQ_EHL, },
172-
{ PCI_VDEVICE(INTEL, 0x4bc2), M_CAN_CLOCK_FREQ_EHL, },
221+
{ PCI_VDEVICE(INTEL, 0x4bc1), (kernel_ulong_t)&m_can_pci_ehl, },
222+
{ PCI_VDEVICE(INTEL, 0x4bc2), (kernel_ulong_t)&m_can_pci_ehl, },
173223
{ } /* Terminating Entry */
174224
};
175225
MODULE_DEVICE_TABLE(pci, m_can_pci_id_table);

drivers/net/can/pch_can.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,11 +692,11 @@ static int pch_can_rx_normal(struct net_device *ndev, u32 obj_num, int quota)
692692
cf->data[i + 1] = data_reg >> 8;
693693
}
694694

695-
netif_receive_skb(skb);
696695
rcv_pkts++;
697696
stats->rx_packets++;
698697
quota--;
699698
stats->rx_bytes += cf->len;
699+
netif_receive_skb(skb);
700700

701701
pch_fifo_thresh(priv, obj_num);
702702
obj_num++;

drivers/net/can/sja1000/ems_pcmcia.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,12 @@ static int ems_pcmcia_add_card(struct pcmcia_device *pdev, unsigned long base)
234234
free_sja1000dev(dev);
235235
}
236236

237-
err = request_irq(dev->irq, &ems_pcmcia_interrupt, IRQF_SHARED,
237+
if (!card->channels) {
238+
err = -ENODEV;
239+
goto failure_cleanup;
240+
}
241+
242+
err = request_irq(pdev->irq, &ems_pcmcia_interrupt, IRQF_SHARED,
238243
DRV_NAME, card);
239244
if (!err)
240245
return 0;

0 commit comments

Comments
 (0)