Skip to content

Commit 858d4d9

Browse files
Santhosh Kumar Kbroonie
authored andcommitted
spi: cadence-quadspi: Fix cqspi_setup_flash()
The 'max_cs' stores the largest chip select number. It should only be updated when the current 'cs' is greater than existing 'max_cs'. So, fix the condition accordingly. Also, return failure if there are no flash device declared. Fixes: 0f3841a ("spi: cadence-qspi: report correct number of chip-select") CC: stable@vger.kernel.org Reviewed-by: Pratyush Yadav <pratyush@kernel.org> Reviewed-by: Théo Lebrun <theo.lebrun@bootlin.com> Signed-off-by: Santhosh Kumar K <s-k6@ti.com> Message-ID: <20250905185958.3575037-4-s-k6@ti.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 1ad5576 commit 858d4d9

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

drivers/spi/spi-cadence-quadspi.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,12 +1722,10 @@ static const struct spi_controller_mem_caps cqspi_mem_caps = {
17221722

17231723
static int cqspi_setup_flash(struct cqspi_st *cqspi)
17241724
{
1725-
unsigned int max_cs = cqspi->num_chipselect - 1;
17261725
struct platform_device *pdev = cqspi->pdev;
17271726
struct device *dev = &pdev->dev;
17281727
struct cqspi_flash_pdata *f_pdata;
1729-
unsigned int cs;
1730-
int ret;
1728+
int ret, cs, max_cs = -1;
17311729

17321730
/* Get flash device data */
17331731
for_each_available_child_of_node_scoped(dev->of_node, np) {
@@ -1740,10 +1738,10 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
17401738
if (cs >= cqspi->num_chipselect) {
17411739
dev_err(dev, "Chip select %d out of range.\n", cs);
17421740
return -EINVAL;
1743-
} else if (cs < max_cs) {
1744-
max_cs = cs;
17451741
}
17461742

1743+
max_cs = max_t(int, cs, max_cs);
1744+
17471745
f_pdata = &cqspi->f_pdata[cs];
17481746
f_pdata->cqspi = cqspi;
17491747
f_pdata->cs = cs;
@@ -1753,6 +1751,11 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
17531751
return ret;
17541752
}
17551753

1754+
if (max_cs < 0) {
1755+
dev_err(dev, "No flash device declared\n");
1756+
return -ENODEV;
1757+
}
1758+
17561759
cqspi->num_chipselect = max_cs + 1;
17571760
return 0;
17581761
}

0 commit comments

Comments
 (0)