Skip to content

Commit c757fc9

Browse files
committed
Merge tag 'spi-fix-v6.2-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
Pull spi fixes from Mark Brown: - Fixes for long standing issues with accesses to spidev->spi during teardown in the spidev userspace driver. - Rename the newly added spi-cs-setup-ns DT property to be more in line with our other delay properties before it becomes ABI. - A few driver specific fixes. * tag 'spi-fix-v6.2-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: spi: spidev: remove debug messages that access spidev->spi without locking spi: spidev: fix a race condition when accessing spidev->spi spi: Rename spi-cs-setup-ns property to spi-cs-setup-delay-ns spi: dt-bindings: Rename spi-cs-setup-ns to spi-cs-setup-delay-ns spi: cadence: Fix busy cycles calculation spi: mediatek: Enable irq before the spi registration
2 parents cf9668a + b442990 commit c757fc9

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ properties:
4444
description:
4545
Maximum SPI clocking speed of the device in Hz.
4646

47-
spi-cs-setup-ns:
47+
spi-cs-setup-delay-ns:
4848
description:
49-
Delay in nanosecods to be introduced by the controller after CS is
49+
Delay in nanoseconds to be introduced by the controller after CS is
5050
asserted.
5151

5252
spi-rx-bus-width:

drivers/spi/spi-cadence-xspi.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@
177177
#define CDNS_XSPI_CMD_FLD_DSEQ_CMD_3(op) ( \
178178
FIELD_PREP(CDNS_XSPI_CMD_DSEQ_R3_DCNT_H, \
179179
((op)->data.nbytes >> 16) & 0xffff) | \
180-
FIELD_PREP(CDNS_XSPI_CMD_DSEQ_R3_NUM_OF_DUMMY, (op)->dummy.nbytes * 8))
180+
FIELD_PREP(CDNS_XSPI_CMD_DSEQ_R3_NUM_OF_DUMMY, \
181+
(op)->dummy.buswidth != 0 ? \
182+
(((op)->dummy.nbytes * 8) / (op)->dummy.buswidth) : \
183+
0))
181184

182185
#define CDNS_XSPI_CMD_FLD_DSEQ_CMD_4(op, chipsel) ( \
183186
FIELD_PREP(CDNS_XSPI_CMD_DSEQ_R4_BANK, chipsel) | \

drivers/spi/spi-mt65xx.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,11 @@ static int mtk_spi_probe(struct platform_device *pdev)
12531253
dev_notice(dev, "SPI dma_set_mask(%d) failed, ret:%d\n",
12541254
addr_bits, ret);
12551255

1256+
ret = devm_request_irq(dev, irq, mtk_spi_interrupt,
1257+
IRQF_TRIGGER_NONE, dev_name(dev), master);
1258+
if (ret)
1259+
return dev_err_probe(dev, ret, "failed to register irq\n");
1260+
12561261
pm_runtime_enable(dev);
12571262

12581263
ret = devm_spi_register_master(dev, master);
@@ -1261,13 +1266,6 @@ static int mtk_spi_probe(struct platform_device *pdev)
12611266
return dev_err_probe(dev, ret, "failed to register master\n");
12621267
}
12631268

1264-
ret = devm_request_irq(dev, irq, mtk_spi_interrupt,
1265-
IRQF_TRIGGER_NONE, dev_name(dev), master);
1266-
if (ret) {
1267-
pm_runtime_disable(dev);
1268-
return dev_err_probe(dev, ret, "failed to register irq\n");
1269-
}
1270-
12711269
return 0;
12721270
}
12731271

drivers/spi/spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2310,7 +2310,7 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
23102310
if (!of_property_read_u32(nc, "spi-max-frequency", &value))
23112311
spi->max_speed_hz = value;
23122312

2313-
if (!of_property_read_u16(nc, "spi-cs-setup-ns", &cs_setup)) {
2313+
if (!of_property_read_u16(nc, "spi-cs-setup-delay-ns", &cs_setup)) {
23142314
spi->cs_setup.value = cs_setup;
23152315
spi->cs_setup.unit = SPI_DELAY_UNIT_NSECS;
23162316
}

drivers/spi/spidev.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static_assert(N_SPI_MINORS > 0 && N_SPI_MINORS <= 256);
6868

6969
struct spidev_data {
7070
dev_t devt;
71-
spinlock_t spi_lock;
71+
struct mutex spi_lock;
7272
struct spi_device *spi;
7373
struct list_head device_entry;
7474

@@ -95,9 +95,8 @@ spidev_sync(struct spidev_data *spidev, struct spi_message *message)
9595
int status;
9696
struct spi_device *spi;
9797

98-
spin_lock_irq(&spidev->spi_lock);
98+
mutex_lock(&spidev->spi_lock);
9999
spi = spidev->spi;
100-
spin_unlock_irq(&spidev->spi_lock);
101100

102101
if (spi == NULL)
103102
status = -ESHUTDOWN;
@@ -107,6 +106,7 @@ spidev_sync(struct spidev_data *spidev, struct spi_message *message)
107106
if (status == 0)
108107
status = message->actual_length;
109108

109+
mutex_unlock(&spidev->spi_lock);
110110
return status;
111111
}
112112

@@ -359,12 +359,12 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
359359
* we issue this ioctl.
360360
*/
361361
spidev = filp->private_data;
362-
spin_lock_irq(&spidev->spi_lock);
362+
mutex_lock(&spidev->spi_lock);
363363
spi = spi_dev_get(spidev->spi);
364-
spin_unlock_irq(&spidev->spi_lock);
365-
366-
if (spi == NULL)
364+
if (spi == NULL) {
365+
mutex_unlock(&spidev->spi_lock);
367366
return -ESHUTDOWN;
367+
}
368368

369369
/* use the buffer lock here for triple duty:
370370
* - prevent I/O (from us) so calling spi_setup() is safe;
@@ -508,6 +508,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
508508

509509
mutex_unlock(&spidev->buf_lock);
510510
spi_dev_put(spi);
511+
mutex_unlock(&spidev->spi_lock);
511512
return retval;
512513
}
513514

@@ -529,12 +530,12 @@ spidev_compat_ioc_message(struct file *filp, unsigned int cmd,
529530
* we issue this ioctl.
530531
*/
531532
spidev = filp->private_data;
532-
spin_lock_irq(&spidev->spi_lock);
533+
mutex_lock(&spidev->spi_lock);
533534
spi = spi_dev_get(spidev->spi);
534-
spin_unlock_irq(&spidev->spi_lock);
535-
536-
if (spi == NULL)
535+
if (spi == NULL) {
536+
mutex_unlock(&spidev->spi_lock);
537537
return -ESHUTDOWN;
538+
}
538539

539540
/* SPI_IOC_MESSAGE needs the buffer locked "normally" */
540541
mutex_lock(&spidev->buf_lock);
@@ -561,6 +562,7 @@ spidev_compat_ioc_message(struct file *filp, unsigned int cmd,
561562
done:
562563
mutex_unlock(&spidev->buf_lock);
563564
spi_dev_put(spi);
565+
mutex_unlock(&spidev->spi_lock);
564566
return retval;
565567
}
566568

@@ -601,7 +603,6 @@ static int spidev_open(struct inode *inode, struct file *filp)
601603
if (!spidev->tx_buffer) {
602604
spidev->tx_buffer = kmalloc(bufsiz, GFP_KERNEL);
603605
if (!spidev->tx_buffer) {
604-
dev_dbg(&spidev->spi->dev, "open/ENOMEM\n");
605606
status = -ENOMEM;
606607
goto err_find_dev;
607608
}
@@ -610,7 +611,6 @@ static int spidev_open(struct inode *inode, struct file *filp)
610611
if (!spidev->rx_buffer) {
611612
spidev->rx_buffer = kmalloc(bufsiz, GFP_KERNEL);
612613
if (!spidev->rx_buffer) {
613-
dev_dbg(&spidev->spi->dev, "open/ENOMEM\n");
614614
status = -ENOMEM;
615615
goto err_alloc_rx_buf;
616616
}
@@ -640,10 +640,10 @@ static int spidev_release(struct inode *inode, struct file *filp)
640640
spidev = filp->private_data;
641641
filp->private_data = NULL;
642642

643-
spin_lock_irq(&spidev->spi_lock);
643+
mutex_lock(&spidev->spi_lock);
644644
/* ... after we unbound from the underlying device? */
645645
dofree = (spidev->spi == NULL);
646-
spin_unlock_irq(&spidev->spi_lock);
646+
mutex_unlock(&spidev->spi_lock);
647647

648648
/* last close? */
649649
spidev->users--;
@@ -776,7 +776,7 @@ static int spidev_probe(struct spi_device *spi)
776776

777777
/* Initialize the driver data */
778778
spidev->spi = spi;
779-
spin_lock_init(&spidev->spi_lock);
779+
mutex_init(&spidev->spi_lock);
780780
mutex_init(&spidev->buf_lock);
781781

782782
INIT_LIST_HEAD(&spidev->device_entry);
@@ -821,9 +821,9 @@ static void spidev_remove(struct spi_device *spi)
821821
/* prevent new opens */
822822
mutex_lock(&device_list_lock);
823823
/* make sure ops on existing fds can abort cleanly */
824-
spin_lock_irq(&spidev->spi_lock);
824+
mutex_lock(&spidev->spi_lock);
825825
spidev->spi = NULL;
826-
spin_unlock_irq(&spidev->spi_lock);
826+
mutex_unlock(&spidev->spi_lock);
827827

828828
list_del(&spidev->device_entry);
829829
device_destroy(spidev_class, spidev->devt);

0 commit comments

Comments
 (0)