[PATCH v2 2/5] spi: expand device name to include all CS lines for multi-CS devices
Jonathan Santos <[email protected]> Mon, 3 Aug 2026 00:02:02 -0300
| Newsgroups | org.kernel.vger.linux-spi,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <897e40907207bf151f0f33937d48ac11a30a024c.1785725359.git.Jonathan.Santos@analog.com> |
The device name for SPI devices was formatted as <controller>.<cs0>, always using only the first chip-select index, ignoring the remaining CS lines. Change the naming format to <controller>.<cs0>+<cs1>+... so that all active chip-selects are reflected in the device name. Single-CS devices are not affected since the loop only appends extra indices when num_chipselect is greater than one. Signed-off-by: Jonathan Santos <[email protected]> --- Changes in v2: * New patch. --- drivers/spi/spi.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 55fb96fea243..61423aee1525 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -594,6 +594,8 @@ static void spi_dev_set_name(struct spi_device *spi) { struct device *dev = &spi->dev; struct fwnode_handle *fwnode = dev_fwnode(dev); + char cs_str[32]; + int cs_len; if (is_acpi_device_node(fwnode)) { dev_set_name(dev, "spi-%s", acpi_dev_name(to_acpi_device_node(fwnode))); @@ -605,8 +607,12 @@ static void spi_dev_set_name(struct spi_device *spi) return; } - dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->controller->dev), - spi_get_chipselect(spi, 0)); + cs_len = scnprintf(cs_str, sizeof(cs_str), "%u", spi_get_chipselect(spi, 0)); + for (int idx = 1; idx < spi->num_chipselect; idx++) + cs_len += scnprintf(cs_str + cs_len, sizeof(cs_str) - cs_len, + "+%u", spi_get_chipselect(spi, idx)); + + dev_set_name(&spi->dev, "%s.%s", dev_name(&spi->controller->dev), cs_str); } /* -- 2.34.1