1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00

spi: deduplicate spi_match_id() in __spi_register_driver()

The same logic is used in spi_match_id() and in the __spi_register_driver().
By switching the former from taking struct spi_device * to const char * as
the second parameter we may deduplicate the code.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20211119173718.52938-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Andy Shevchenko 2021-11-19 19:37:17 +02:00 committed by Mark Brown
parent d94758b344
commit 3f07657506
No known key found for this signature in database
GPG key ID: 24D68B725D5487D0

View file

@ -315,11 +315,10 @@ static void spi_statistics_add_transfer_stats(struct spi_statistics *stats,
* and the sysfs version makes coldplug work too. * and the sysfs version makes coldplug work too.
*/ */
static const struct spi_device_id *spi_match_id(const struct spi_device_id *id, static const struct spi_device_id *spi_match_id(const struct spi_device_id *id, const char *name)
const struct spi_device *sdev)
{ {
while (id->name[0]) { while (id->name[0]) {
if (!strcmp(sdev->modalias, id->name)) if (!strcmp(name, id->name))
return id; return id;
id++; id++;
} }
@ -330,7 +329,7 @@ const struct spi_device_id *spi_get_device_id(const struct spi_device *sdev)
{ {
const struct spi_driver *sdrv = to_spi_driver(sdev->dev.driver); const struct spi_driver *sdrv = to_spi_driver(sdev->dev.driver);
return spi_match_id(sdrv->id_table, sdev); return spi_match_id(sdrv->id_table, sdev->modalias);
} }
EXPORT_SYMBOL_GPL(spi_get_device_id); EXPORT_SYMBOL_GPL(spi_get_device_id);
@ -352,7 +351,7 @@ static int spi_match_device(struct device *dev, struct device_driver *drv)
return 1; return 1;
if (sdrv->id_table) if (sdrv->id_table)
return !!spi_match_id(sdrv->id_table, spi); return !!spi_match_id(sdrv->id_table, spi->modalias);
return strcmp(spi->modalias, drv->name) == 0; return strcmp(spi->modalias, drv->name) == 0;
} }
@ -474,12 +473,8 @@ int __spi_register_driver(struct module *owner, struct spi_driver *sdrv)
if (sdrv->id_table) { if (sdrv->id_table) {
const struct spi_device_id *spi_id; const struct spi_device_id *spi_id;
for (spi_id = sdrv->id_table; spi_id->name[0]; spi_id = spi_match_id(sdrv->id_table, of_name);
spi_id++) if (!spi_id)
if (strcmp(spi_id->name, of_name) == 0)
break;
if (spi_id->name[0])
continue; continue;
} else { } else {
if (strcmp(sdrv->driver.name, of_name) == 0) if (strcmp(sdrv->driver.name, of_name) == 0)