[PATCH v2 1/4] pinctrl: s32: use of_device_get_match_data() to get device data
Chester Lin
clin at suse.com
Mon Mar 20 21:44:18 PDT 2023
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 at 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 at 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
More information about the linux-arm-kernel
mailing list