Message ID | 20240125145007.748295-4-tudor.ambarus@linaro.org (mailing list archive) |
---|---|
State | Accepted |
Commit | a336d41bbea51e11e3e4f56bd3877a535c077129 |
Headers | show |
Series | spi: s3c64xx: winter cleanup and gs101 support | expand |
On Thu, Jan 25, 2024 at 8:50 AM Tudor Ambarus <tudor.ambarus@linaro.org> wrote: > > The platform id is used as an index into the fifo_lvl_mask array. > Platforms can come with a negative device ID, PLATFORM_DEVID_NONE (-1), > thus we risked a negative array index. Catch such cases and fail to > probe. > > Fixes: 2b90807549e5 ("spi: s3c64xx: add device tree support") > Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org> > --- > drivers/spi/spi-s3c64xx.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c > index 2b5bb7604526..c3176a510643 100644 > --- a/drivers/spi/spi-s3c64xx.c > +++ b/drivers/spi/spi-s3c64xx.c > @@ -1189,6 +1189,9 @@ static int s3c64xx_spi_probe(struct platform_device *pdev) > "Failed to get alias id\n"); > sdd->port_id = ret; > } else { > + if (pdev->id < 0) I'd add { } braces around this block, but that's a matter of taste. Also, I'm not sure why do we still want to handle !of_node case for drivers like these at all: there is no mfd case for this driver, and board files are long gone; it seems to be OF only driver in a sense, from its users POV. Anyways, LGTM: Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org> > + return dev_err_probe(&pdev->dev, -EINVAL, > + "Negative platform ID is not allowed\n"); > sdd->port_id = pdev->id; > } > > -- > 2.43.0.429.g432eaa2c6b-goog >
diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 2b5bb7604526..c3176a510643 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -1189,6 +1189,9 @@ static int s3c64xx_spi_probe(struct platform_device *pdev) "Failed to get alias id\n"); sdd->port_id = ret; } else { + if (pdev->id < 0) + return dev_err_probe(&pdev->dev, -EINVAL, + "Negative platform ID is not allowed\n"); sdd->port_id = pdev->id; }
The platform id is used as an index into the fifo_lvl_mask array. Platforms can come with a negative device ID, PLATFORM_DEVID_NONE (-1), thus we risked a negative array index. Catch such cases and fail to probe. Fixes: 2b90807549e5 ("spi: s3c64xx: add device tree support") Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org> --- drivers/spi/spi-s3c64xx.c | 3 +++ 1 file changed, 3 insertions(+)