Re: [GIT PULL] MFD fixes for v5.12

From: Linus Torvalds
Date: Thu Mar 25 2021 - 14:24:22 EST


On Thu, Mar 25, 2021 at 9:34 AM Lee Jones <lee.jones@xxxxxxxxxx> 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).

Linus