Skip to contentSkip to conversation

mfd: mc13xxx-spi: Reject devices without match data

PATCH In review Jiale Yao 3 participants 3 messages Sep 25 – Oct 15 Multifunction devices (MFD)

lore
Share & tools
lore

Jiale Yao

author
#0 lore raw

PATCH 1/1 mfd: mc13xxx-spi: Reject devices without match data

A device bound through driver_override need not match an entry in the driver tables. In that case spi_get_device_match_data() returns NULL, but mc13xxx_common_init() later uses the missing variant data.

Reject devices without match data before entering the common probe path.

Fixes 15d71e678ec1 ("mfd: mc13xxx-spi/wm831x-spi: Use spi_get_device_match_data()")
---
 drivers/mfd/mc13xxx-spi.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mfd/mc13xxx-spi.c +2 -0
index 56d2e57b7d73..d1523321152a 100644
@@ -150,6 +150,8 @@ static int mc13xxx_spi_probe(struct spi_device *spi)
 	}
 
 	mc13xxx->variant = spi_get_device_match_data(spi);
+	if (!mc13xxx->variant)
+		return -ENODATA;
 
 	return mc13xxx_common_init(&spi->dev);
 }
Signature · 1 line
2.34.1
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

A device bound through driver_override need not match an entry in the driver tables. In that case spi_get_device_match_data() returns NULL, but mc13xxx_common_init() later uses the missing variant data.

Reject devices without match data before entering the common probe path.

Fixes 15d71e678ec1 ("mfd: mc13xxx-spi/wm831x-spi: Use spi_get_device_match_data()")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to Jiale Yao
Quoted 17 lines · Jiale Yao

A device bound through driver_override need not match an entry in the driver tables. In that case spi_get_device_match_data() returns NULL, but mc13xxx_common_init() later uses the missing variant data.

Reject devices without match data before entering the common probe path.

Fixes 15d71e678ec1 ("mfd: mc13xxx-spi/wm831x-spi: Use spi_get_device_match_data()")
---
 drivers/mfd/mc13xxx-spi.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mfd/mc13xxx-spi.c +0 -0
index 56d2e57b7d73..d1523321152a 100644

drivers/mfd/mc13xxx-spi.c static int mc13xxx_spi_probe(struct spi_device *spi) · line 154

Quoted 5 lines
drivers/mfd/mc13xxx-spi.c +2 -0
@@ -150,6 +150,8 @@ static int mc13xxx_spi_probe(struct spi_device *spi)
 	}
 
 	mc13xxx->variant = spi_get_device_match_data(spi);
+	if (!mc13xxx->variant)
+		return -ENODATA;

Shouldn't this check happen at the start of 'mc13xxx_spi_probe()', before we allocate memory, configure the SPI bus and initialise 'regmap'? Also, we generally return '-ENODEV' when match data is missing.

Quoted 6 lines
drivers/mfd/mc13xxx-spi.c +0 -0
 	return mc13xxx_common_init(&spi->dev);
 }
Signature · 1 line
2.34.1
Signature · 1 line
Lee Jones