[PATCH 2/4] gpio: aspeed: Simplify with of_device_get_match_data()

Krzysztof Kozlowski posted 4 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH 2/4] gpio: aspeed: Simplify with of_device_get_match_data()
Posted by Krzysztof Kozlowski 1 month, 1 week ago
Driver's probe function matches against driver's of_device_id table,
where each entry has non-NULL match data, so of_match_node() can be
simplified with of_device_get_match_data().

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/gpio/gpio-aspeed.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
index 2e0ae953dd99..3d675b63936c 100644
--- a/drivers/gpio/gpio-aspeed.c
+++ b/drivers/gpio/gpio-aspeed.c
@@ -1305,7 +1305,6 @@ MODULE_DEVICE_TABLE(of, aspeed_gpio_of_table);
 
 static int aspeed_gpio_probe(struct platform_device *pdev)
 {
-	const struct of_device_id *gpio_id;
 	struct gpio_irq_chip *girq;
 	struct aspeed_gpio *gpio;
 	int rc, irq, i, banks, err;
@@ -1323,8 +1322,8 @@ static int aspeed_gpio_probe(struct platform_device *pdev)
 
 	raw_spin_lock_init(&gpio->lock);
 
-	gpio_id = of_match_node(aspeed_gpio_of_table, pdev->dev.of_node);
-	if (!gpio_id)
+	gpio->config = of_device_get_match_data(&pdev->dev);
+	if (!gpio->config)
 		return -EINVAL;
 
 	gpio->clk = devm_clk_get_enabled(&pdev->dev, NULL);
@@ -1334,8 +1333,6 @@ static int aspeed_gpio_probe(struct platform_device *pdev)
 		gpio->clk = NULL;
 	}
 
-	gpio->config = gpio_id->data;
-
 	if (!gpio->config->llops->reg_bit_set || !gpio->config->llops->reg_bit_get ||
 	    !gpio->config->llops->reg_bank_get)
 		return -EINVAL;

-- 
2.48.1
Re: [PATCH 2/4] gpio: aspeed: Simplify with of_device_get_match_data()
Posted by Bartosz Golaszewski 1 month, 1 week ago
On Thu, Nov 6, 2025 at 5:16 PM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
>
> Driver's probe function matches against driver's of_device_id table,
> where each entry has non-NULL match data, so of_match_node() can be
> simplified with of_device_get_match_data().
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  drivers/gpio/gpio-aspeed.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
> index 2e0ae953dd99..3d675b63936c 100644
> --- a/drivers/gpio/gpio-aspeed.c
> +++ b/drivers/gpio/gpio-aspeed.c
> @@ -1305,7 +1305,6 @@ MODULE_DEVICE_TABLE(of, aspeed_gpio_of_table);
>
>  static int aspeed_gpio_probe(struct platform_device *pdev)
>  {
> -       const struct of_device_id *gpio_id;
>         struct gpio_irq_chip *girq;
>         struct aspeed_gpio *gpio;
>         int rc, irq, i, banks, err;
> @@ -1323,8 +1322,8 @@ static int aspeed_gpio_probe(struct platform_device *pdev)
>
>         raw_spin_lock_init(&gpio->lock);
>
> -       gpio_id = of_match_node(aspeed_gpio_of_table, pdev->dev.of_node);
> -       if (!gpio_id)
> +       gpio->config = of_device_get_match_data(&pdev->dev);

If you're already doing it, just use device_get_match_data() here and
elsewhere in the series.

Bart

> +       if (!gpio->config)
>                 return -EINVAL;
>
>         gpio->clk = devm_clk_get_enabled(&pdev->dev, NULL);
> @@ -1334,8 +1333,6 @@ static int aspeed_gpio_probe(struct platform_device *pdev)
>                 gpio->clk = NULL;
>         }
>
> -       gpio->config = gpio_id->data;
> -
>         if (!gpio->config->llops->reg_bit_set || !gpio->config->llops->reg_bit_get ||
>             !gpio->config->llops->reg_bank_get)
>                 return -EINVAL;
>
> --
> 2.48.1
>
Re: [PATCH 2/4] gpio: aspeed: Simplify with of_device_get_match_data()
Posted by Krzysztof Kozlowski 1 month, 1 week ago
On 06/11/2025 17:23, Bartosz Golaszewski wrote:
> On Thu, Nov 6, 2025 at 5:16 PM Krzysztof Kozlowski
> <krzysztof.kozlowski@linaro.org> wrote:
>>
>> Driver's probe function matches against driver's of_device_id table,
>> where each entry has non-NULL match data, so of_match_node() can be
>> simplified with of_device_get_match_data().
>>
>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>> ---
>>  drivers/gpio/gpio-aspeed.c | 7 ++-----
>>  1 file changed, 2 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
>> index 2e0ae953dd99..3d675b63936c 100644
>> --- a/drivers/gpio/gpio-aspeed.c
>> +++ b/drivers/gpio/gpio-aspeed.c
>> @@ -1305,7 +1305,6 @@ MODULE_DEVICE_TABLE(of, aspeed_gpio_of_table);
>>
>>  static int aspeed_gpio_probe(struct platform_device *pdev)
>>  {
>> -       const struct of_device_id *gpio_id;
>>         struct gpio_irq_chip *girq;
>>         struct aspeed_gpio *gpio;
>>         int rc, irq, i, banks, err;
>> @@ -1323,8 +1322,8 @@ static int aspeed_gpio_probe(struct platform_device *pdev)
>>
>>         raw_spin_lock_init(&gpio->lock);
>>
>> -       gpio_id = of_match_node(aspeed_gpio_of_table, pdev->dev.of_node);
>> -       if (!gpio_id)
>> +       gpio->config = of_device_get_match_data(&pdev->dev);
> 
> If you're already doing it, just use device_get_match_data() here and
> elsewhere in the series.

That's not exactly equivalent, but I guess it does not matter if driver
probes only via OF. Sure, I'll change it.


Best regards,
Krzysztof
Re: [PATCH 2/4] gpio: aspeed: Simplify with of_device_get_match_data()
Posted by Bartosz Golaszewski 1 month, 1 week ago
On Thu, Nov 6, 2025 at 8:13 PM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
>
> On 06/11/2025 17:23, Bartosz Golaszewski wrote:
> > On Thu, Nov 6, 2025 at 5:16 PM Krzysztof Kozlowski
> > <krzysztof.kozlowski@linaro.org> wrote:
> >>
> >> Driver's probe function matches against driver's of_device_id table,
> >> where each entry has non-NULL match data, so of_match_node() can be
> >> simplified with of_device_get_match_data().
> >>
> >> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> >> ---
> >>  drivers/gpio/gpio-aspeed.c | 7 ++-----
> >>  1 file changed, 2 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
> >> index 2e0ae953dd99..3d675b63936c 100644
> >> --- a/drivers/gpio/gpio-aspeed.c
> >> +++ b/drivers/gpio/gpio-aspeed.c
> >> @@ -1305,7 +1305,6 @@ MODULE_DEVICE_TABLE(of, aspeed_gpio_of_table);
> >>
> >>  static int aspeed_gpio_probe(struct platform_device *pdev)
> >>  {
> >> -       const struct of_device_id *gpio_id;
> >>         struct gpio_irq_chip *girq;
> >>         struct aspeed_gpio *gpio;
> >>         int rc, irq, i, banks, err;
> >> @@ -1323,8 +1322,8 @@ static int aspeed_gpio_probe(struct platform_device *pdev)
> >>
> >>         raw_spin_lock_init(&gpio->lock);
> >>
> >> -       gpio_id = of_match_node(aspeed_gpio_of_table, pdev->dev.of_node);
> >> -       if (!gpio_id)
> >> +       gpio->config = of_device_get_match_data(&pdev->dev);
> >
> > If you're already doing it, just use device_get_match_data() here and
> > elsewhere in the series.
>
> That's not exactly equivalent, but I guess it does not matter if driver
> probes only via OF. Sure, I'll change it.
>

In this case, it probably doesn't matter but in almost all cases it's
better to go through the fwnode path, as it also checks potential
secondary nodes when retrieving properties. Not to mention better
portability of the driver if needed in the future.

Bart