Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: altera: Change to dynamic allocation of spi id

The spi-altera driver has two flavors: platform and dfl. I'm seeing
a case where I have both device types in the same machine, and they
are conflicting on the SPI ID:

... kernel: couldn't get idr
... kernel: WARNING: CPU: 28 PID: 912 at drivers/spi/spi.c:2920 spi_register_controller.cold+0x84/0xc0a

Both the platform and dfl drivers use the parent's driver ID as the SPI
ID. In the error case, the parent devices are dfl_dev.4 and
subdev_spi_altera.4.auto. When the second spi-master is created, the
failure occurs because the SPI ID of 4 has already been allocated.

Change the ID allocation to dynamic (by initializing bus_num to -1) to
avoid duplicate SPI IDs.

Signed-off-by: Russ Weight <russell.h.weight@intel.com>
Link: https://lore.kernel.org/r/20211019002401.24041-1-russell.h.weight@intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Russ Weight and committed by
Mark Brown
f09f6dfe 16a8e2fb

+2 -2
+1 -1
drivers/spi/spi-altera-dfl.c
··· 134 134 if (!master) 135 135 return -ENOMEM; 136 136 137 - master->bus_num = dfl_dev->id; 137 + master->bus_num = -1; 138 138 139 139 hw = spi_master_get_devdata(master); 140 140
+1 -1
drivers/spi/spi-altera-platform.c
··· 48 48 return err; 49 49 50 50 /* setup the master state. */ 51 - master->bus_num = pdev->id; 51 + master->bus_num = -1; 52 52 53 53 if (pdata) { 54 54 if (pdata->num_chipselect > ALTERA_SPI_MAX_CS) {