在 2021/3/30 20:36, Fabio Estevam 写道:
On Tue, Mar 30, 2021 at 9:30 AM Tian Tao <tiantao6@xxxxxxxxxxxxx> wrote:
- match = of_match_device(davinci_spi_of_match, &pdev->dev);
- if (!match)
+ spi_data = of_device_get_match_data(&pdev->dev);
+ if (!spi_data)
No need to check against NULL here because all compatible strings
provide .data and DT is the only mechanism to probe.
Also, this could be device_get_match_data().
.
What about doing it like this?
diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index 7453a1d..e114e6fe 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -817,18 +817,13 @@ static int spi_davinci_get_pdata(struct
platform_device *pdev,
struct davinci_spi *dspi)
{
struct device_node *node = pdev->dev.of_node;
- struct davinci_spi_of_data *spi_data;
+ const struct davinci_spi_of_data *spi_data;
struct davinci_spi_platform_data *pdata;
unsigned int num_cs, intr_line = 0;
- const struct of_device_id *match;
pdata = &dspi->pdata;
- match = of_match_device(davinci_spi_of_match, &pdev->dev);
- if (!match)
- return -ENODEV;
-
- spi_data = (struct davinci_spi_of_data *)match->data;
+ spi_data = device_get_match_data(&pdev->dev);
pdata->version = spi_data->version;
pdata->prescaler_limit = spi_data->prescaler_limit;