[PATCH 06/18] serial: sc16is7xx: use spi_get_device_match_data()

Hugo Villeneuve posted 18 patches 1 year, 12 months ago
There is a newer version of this series
[PATCH 06/18] serial: sc16is7xx: use spi_get_device_match_data()
Posted by Hugo Villeneuve 1 year, 12 months ago
From: Hugo Villeneuve <hvilleneuve@dimonoff.com>

Use preferred spi_get_device_match_data() instead of
device_get_match_data() and spi_get_device_id() to get the driver match
data.

Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
 drivers/tty/serial/sc16is7xx.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
index 597280a5d0f3..8cbf54d0a16c 100644
--- a/drivers/tty/serial/sc16is7xx.c
+++ b/drivers/tty/serial/sc16is7xx.c
@@ -1742,14 +1742,10 @@ static int sc16is7xx_spi_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	if (spi->dev.of_node) {
-		devtype = device_get_match_data(&spi->dev);
-		if (!devtype)
-			return -ENODEV;
-	} else {
-		const struct spi_device_id *id_entry = spi_get_device_id(spi);
-
-		devtype = (struct sc16is7xx_devtype *)id_entry->driver_data;
+	devtype = (struct sc16is7xx_devtype *)spi_get_device_match_data(spi);
+	if (!devtype) {
+		dev_err(&spi->dev, "Failed to match device\n");
+		return -ENODEV;
 	}
 
 	for (i = 0; i < devtype->nr_uart; i++) {
-- 
2.39.2
Re: [PATCH 06/18] serial: sc16is7xx: use spi_get_device_match_data()
Posted by Andy Shevchenko 1 year, 12 months ago
On Tue, Dec 19, 2023 at 12:18:50PM -0500, Hugo Villeneuve wrote:
> From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> 
> Use preferred spi_get_device_match_data() instead of
> device_get_match_data() and spi_get_device_id() to get the driver match
> data.

...

> +	devtype = (struct sc16is7xx_devtype *)spi_get_device_match_data(spi);

Nice one, but drop the casting. (Yes, make sure the assignee is const. It might
require an additional change.)

> +	if (!devtype) {
> +		dev_err(&spi->dev, "Failed to match device\n");
> +		return -ENODEV;

		return dev_err_probe(...);

?

>  	}

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH 06/18] serial: sc16is7xx: use spi_get_device_match_data()
Posted by Hugo Villeneuve 1 year, 12 months ago
On Wed, 20 Dec 2023 17:44:52 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Tue, Dec 19, 2023 at 12:18:50PM -0500, Hugo Villeneuve wrote:
> > From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> > 
> > Use preferred spi_get_device_match_data() instead of
> > device_get_match_data() and spi_get_device_id() to get the driver match
> > data.
> 
> ...
> 
> > +	devtype = (struct sc16is7xx_devtype *)spi_get_device_match_data(spi);
> 
> Nice one, but drop the casting. (Yes, make sure the assignee is const. It might
> require an additional change.)

Done, devtype was already const.

> 
> > +	if (!devtype) {
> > +		dev_err(&spi->dev, "Failed to match device\n");
> > +		return -ENODEV;
> 
> 		return dev_err_probe(...);
> 
> ?

Yes, done for V2.

Also done the same two changes for the I2C part.

Hugo.