Re: [PATCH v2 1/2] pinctrl: ocelot: Fix pincfg for lan966x
From: Andy Shevchenko
Date: Mon Jul 11 2022 - 04:32:47 EST
On Mon, Jul 11, 2022 at 8:45 AM Horatiu Vultur
<horatiu.vultur@xxxxxxxxxxxxx> wrote:
> The 07/08/2022 23:58, Andy Shevchenko wrote:
> > On Fri, Jul 8, 2022 at 10:10 PM Horatiu Vultur
> > <horatiu.vultur@xxxxxxxxxxxxx> wrote:
Please, remove unneeded context when replying!
...
> > > + struct ocelot_match_data *data;
> >
> > Any specific reason why this is not const?
> >
> > > + data = (struct ocelot_match_data *)device_get_match_data(dev);
> >
> > And here you drop the qualifier...
> >
> > I would recommend making it const and dropping the cast completely.
>
> If I make this const, but then few lines after I will get the following
> warnings:
>
> drivers/pinctrl/pinctrl-ocelot.c:1983:13: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
> 1983 | info->desc = &data->desc;
> | ^
> drivers/pinctrl/pinctrl-ocelot.c:1984:20: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
> 1984 | info->pincfg_data = &data->pincfg_data;
> | ^
>
> Of course I can make also info->desc and info->pincfg_data const but
> then I will get the following warning:
>
> drivers/pinctrl/pinctrl-ocelot.c: In function ‘ocelot_pinctrl_register’:
> drivers/pinctrl/pinctrl-ocelot.c:1723:53: warning: passing argument 2 of ‘devm_pinctrl_register’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
> 1723 | info->pctl = devm_pinctrl_register(&pdev->dev, info->desc, info);
> | ~~~~^~~~~~
> In file included from include/linux/gpio/driver.h:10,
> from drivers/pinctrl/pinctrl-ocelot.c:10:
> include/linux/pinctrl/pinctrl.h:166:26: note: expected ‘struct pinctrl_desc *’ but argument is of type ‘const struct pinctrl_desc *’
> 166 | struct pinctrl_desc *pctldesc,
> | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
>
> > > + if (!data)
> > > + return -EINVAL;
This is not good. Any chances to make it const?
One way is to copy data in a newly allocated buffer (devm_kmemdup() for that).
--
With Best Regards,
Andy Shevchenko