Mailing List Archive

[PATCH v2 1/4] pinctrl: s32: use of_device_get_match_data() to get device data
Instead of relying on of_match_device(), using of_device_get_match_data()
can simplify implementation and avoid code duplication.

Signed-off-by: Chester Lin <clin@suse.com>
---
(An initial version since v2)

drivers/pinctrl/nxp/pinctrl-s32g2.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/pinctrl/nxp/pinctrl-s32g2.c b/drivers/pinctrl/nxp/pinctrl-s32g2.c
index 5028f4adc389..f99f88615ef6 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32g2.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32g2.c
@@ -740,14 +740,12 @@ MODULE_DEVICE_TABLE(of, s32_pinctrl_of_match);

static int s32g_pinctrl_probe(struct platform_device *pdev)
{
- const struct of_device_id *of_id =
- of_match_device(s32_pinctrl_of_match, &pdev->dev);
+ struct s32_pinctrl_soc_info *soc_info;

- if (!of_id)
- return -ENODEV;
+ soc_info = (struct s32_pinctrl_soc_info *)
+ of_device_get_match_data(&pdev->dev);

- return s32_pinctrl_probe
- (pdev, (struct s32_pinctrl_soc_info *) of_id->data);
+ return s32_pinctrl_probe(pdev, soc_info);
}

static const struct dev_pm_ops s32g_pinctrl_pm_ops = {
--
2.37.3
Re: [PATCH v2 1/4] pinctrl: s32: use of_device_get_match_data() to get device data [ In reply to ]
On Mon, Mar 20, 2023 at 6:39?PM Chester Lin <clin@suse.com> wrote:
>
> Instead of relying on of_match_device(), using of_device_get_match_data()
> can simplify implementation and avoid code duplication.

Suggested-by?

> Signed-off-by: Chester Lin <clin@suse.com>

...

> + soc_info = (struct s32_pinctrl_soc_info *)
> + of_device_get_match_data(&pdev->dev);

Drop the ugly casting, it's not needed.

--
With Best Regards,
Andy Shevchenko
Re: [PATCH v2 1/4] pinctrl: s32: use of_device_get_match_data() to get device data [ In reply to ]
Hi Andy,

Thank you for reviewing this series!

On Mon, Mar 20, 2023 at 06:59:41PM +0200, Andy Shevchenko wrote:
> On Mon, Mar 20, 2023 at 6:39?PM Chester Lin <clin@suse.com> wrote:
> >
> > Instead of relying on of_match_device(), using of_device_get_match_data()
> > can simplify implementation and avoid code duplication.
>
> Suggested-by?
>

Sorry for the miss. I will fix it in v3.

> > Signed-off-by: Chester Lin <clin@suse.com>
>
> ...
>
> > + soc_info = (struct s32_pinctrl_soc_info *)
> > + of_device_get_match_data(&pdev->dev);
>
> Drop the ugly casting, it's not needed.
>

Actually it's used for suppressing the compiler warning since some members in
this soc_info need to be filled by pinctrl-s32cc.

drivers/pinctrl/nxp/pinctrl-s32g2.c:745:18: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]


I am thinking of allocating & copying a dedicate struct in pinctrl-s32cc.c rather
than reusing the .data attached on of_device_id in order to solve this warning
properly. Here is an example based on this v2:

diff --git a/drivers/pinctrl/nxp/pinctrl-s32.h b/drivers/pinctrl/nxp/pinctrl-s32.h
index 2f7aecd462e4..f3a0b579757c 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32.h
+++ b/drivers/pinctrl/nxp/pinctrl-s32.h
@@ -51,7 +51,7 @@ struct s32_pinctrl_soc_info {
#define S32_PIN_RANGE(_start, _end) { .start = _start, .end = _end }

int s32_pinctrl_probe(struct platform_device *pdev,
- struct s32_pinctrl_soc_info *info);
+ const struct s32_pinctrl_soc_info *soc_data);
int s32_pinctrl_resume(struct device *dev);
int s32_pinctrl_suspend(struct device *dev);
#endif /* __DRIVERS_PINCTRL_S32_H */
diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c
index 4ed0cc905232..4c70ab753d15 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32cc.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c
@@ -899,20 +899,28 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
}

int s32_pinctrl_probe(struct platform_device *pdev,
- struct s32_pinctrl_soc_info *info)
+ const struct s32_pinctrl_soc_info *soc_data)
{
struct s32_pinctrl *ipctl;
int ret;
struct pinctrl_desc *s32_pinctrl_desc;
+ struct s32_pinctrl_soc_info *info;
#ifdef CONFIG_PM_SLEEP
struct s32_pinctrl_context *saved_context;
#endif

- if (!info || !info->pins || !info->npins) {
+ if (!soc_data || !soc_data->pins || !soc_data->npins) {
dev_err(&pdev->dev, "wrong pinctrl info\n");
return -EINVAL;
}

+
+ info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
+ if (!info)
+ return -ENOMEM;
+
+ memcpy(info, soc_data, sizeof(*info));
+
info->dev = &pdev->dev;

/* Create state holders etc for this driver */
diff --git a/drivers/pinctrl/nxp/pinctrl-s32g2.c b/drivers/pinctrl/nxp/pinctrl-s32g2.c
index 9f521312f768..0a49205414eb 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32g2.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32g2.c
@@ -740,10 +740,9 @@ MODULE_DEVICE_TABLE(of, s32_pinctrl_of_match);

static int s32g_pinctrl_probe(struct platform_device *pdev)
{
- struct s32_pinctrl_soc_info *soc_info;
+ const struct s32_pinctrl_soc_info *soc_info;

- soc_info = (struct s32_pinctrl_soc_info *)
- of_device_get_match_data(&pdev->dev);
+ soc_info = of_device_get_match_data(&pdev->dev);

return s32_pinctrl_probe(pdev, soc_info);
}

> --
> With Best Regards,
> Andy Shevchenko
Re: [PATCH v2 1/4] pinctrl: s32: use of_device_get_match_data() to get device data [ In reply to ]
On Tue, Mar 21, 2023 at 6:44?AM Chester Lin <clin@suse.com> wrote:
> On Mon, Mar 20, 2023 at 06:59:41PM +0200, Andy Shevchenko wrote:
> > On Mon, Mar 20, 2023 at 6:39?PM Chester Lin <clin@suse.com> wrote:

...

> > > + soc_info = (struct s32_pinctrl_soc_info *)
> > > + of_device_get_match_data(&pdev->dev);
> >
> > Drop the ugly casting, it's not needed.
>
> Actually it's used for suppressing the compiler warning since some members in
> this soc_info need to be filled by pinctrl-s32cc.

Yes, that's one way to solve this.

...

> + info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
> + if (!info)
> + return -ENOMEM;
> +
> + memcpy(info, soc_data, sizeof(*info));

Right, but use devm_kmemdup() instead.

--
With Best Regards,
Andy Shevchenko