On Thu, Mar 25, 2021 at 11:23:06AM -0700, Linus Torvalds wrote:
> On Thu, Mar 25, 2021 at 9:34 AM Lee Jones <[email protected]> wrote:
> >
> >    - Unconstify editable placeholder structures
> 
> Hmm. This does show a real issue with that gpio driver.
> 
> It does garbage things:
> 
>   static int intel_quark_gpio_setup(struct pci_dev *pdev, struct mfd_cell 
> *cell)
>   {
>         struct dwapb_platform_data *pdata;
>         struct resource *res = (struct resource *)cell->resources;
> 
> where that cast is exactly because "cell->resources" _is_ const, and
> the driver violates that.
> 
> This horrible mis-use of a const pointer is why the original patch
> that got reverted didn't cause build-time warnings.
> 
> Honestly, I think the right thing to do is to get rid of that cast, and do
> 
>         struct resource *res = intel_quark_mfd_cells;
> 
> instead, so that you clearly edit somethign that isn't const, and so
> that the compiler would have warned about the whole constification in
> the first place.
> 
> This broken pattern shows up for both intel_quark_i2c_setup() and
> intel_quark_gpio_setup().
> 
> I've pulled this, but I really want this kind of "take a const pointer
> and violate it" crap removed. It is *only* correct if you know exactly
> which pointer it is, and then you should just have used that original
> pointer in the first place (ie use that intel_quark_mfd_cells[]
> directly like suggested above).

Thanks for pointing this out! I'll take it in my TODO list.

Hmm... I missed the above b/c I have seen the pattern of supplying non-const
data structures via .driver_data field and thought that here is something
similar without looking into the actual approach.

-- 
With Best Regards,
Andy Shevchenko


Reply via email to