public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Lee Jones <lee.jones@linaro.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [GIT PULL] MFD fixes for v5.12
Date: Thu, 25 Mar 2021 20:37:11 +0200	[thread overview]
Message-ID: <YFzYVxZQ9WWkhfRA@smile.fi.intel.com> (raw)
In-Reply-To: <CAHk-=wjJxziChniE2zmkbFxEpizYFg=XaKyq_O_Rfh_Lr_idkw@mail.gmail.com>

On Thu, Mar 25, 2021 at 11:23:06AM -0700, Linus Torvalds wrote:
> On Thu, Mar 25, 2021 at 9:34 AM Lee Jones <lee.jones@linaro.org> 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	other threads:[~2021-03-25 18:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-25 16:33 [GIT PULL] MFD fixes for v5.12 Lee Jones
2021-03-25 18:23 ` Linus Torvalds
2021-03-25 18:37   ` Andy Shevchenko [this message]
2021-03-25 19:13 ` pr-tracker-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YFzYVxZQ9WWkhfRA@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox