Skip to content

Commit 1ce9d6c

Browse files
Santhosh Kumar Kgregkh
authored andcommitted
spi: cadence-quadspi: Fix cqspi_setup_flash()
commit 858d4d9 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a3a7b74 commit 1ce9d6c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

drivers/spi/spi-cadence-quadspi.c

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

16741674
static int cqspi_setup_flash(struct cqspi_st *cqspi)
16751675
{
1676-
unsigned int max_cs = cqspi->num_chipselect - 1;
16771676
struct platform_device *pdev = cqspi->pdev;
16781677
struct device *dev = &pdev->dev;
16791678
struct cqspi_flash_pdata *f_pdata;
1680-
unsigned int cs;
1681-
int ret;
1679+
int ret, cs, max_cs = -1;
16821680

16831681
/* Get flash device data */
16841682
for_each_available_child_of_node_scoped(dev->of_node, np) {
@@ -1691,10 +1689,10 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
16911689
if (cs >= cqspi->num_chipselect) {
16921690
dev_err(dev, "Chip select %d out of range.\n", cs);
16931691
return -EINVAL;
1694-
} else if (cs < max_cs) {
1695-
max_cs = cs;
16961692
}
16971693

1694+
max_cs = max_t(int, cs, max_cs);
1695+
16981696
f_pdata = &cqspi->f_pdata[cs];
16991697
f_pdata->cqspi = cqspi;
17001698
f_pdata->cs = cs;
@@ -1704,6 +1702,11 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
17041702
return ret;
17051703
}
17061704

1705+
if (max_cs < 0) {
1706+
dev_err(dev, "No flash device declared\n");
1707+
return -ENODEV;
1708+
}
1709+
17071710
cqspi->num_chipselect = max_cs + 1;
17081711
return 0;
17091712
}

0 commit comments

Comments
 (0)