From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Lee Jones <lee@kernel.org>
Cc: Peter Tyser <ptyser@xes-inc.com>,
Purva Yeshi <purvayeshi550@gmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: (subset) [PATCH] mfd: lpc_ich: Fix ARRAY_SIZE usage for apl_gpio_resources
Date: Thu, 24 Apr 2025 22:01:06 +0300 [thread overview]
Message-ID: <aAqKcn25bkrjIiLF@black.fi.intel.com> (raw)
In-Reply-To: <174377238828.330559.7652024137546009839.b4-ty@kernel.org>
On Fri, Apr 04, 2025 at 02:13:08PM +0100, Lee Jones wrote:
> On Sat, 22 Mar 2025 18:48:41 +0530, Purva Yeshi wrote:
> > Fix warning detected by smatch tool:
> > drivers/mfd/lpc_ich.c:194:34: error: strange non-value function or array
> > drivers/mfd/lpc_ich.c:194:34: error: missing type information
> > drivers/mfd/lpc_ich.c:201:34: error: strange non-value function or array
> > drivers/mfd/lpc_ich.c:201:34: error: missing type information
> > drivers/mfd/lpc_ich.c:208:34: error: strange non-value function or array
> > drivers/mfd/lpc_ich.c:208:34: error: missing type information
> > drivers/mfd/lpc_ich.c:215:34: error: strange non-value function or array
> > drivers/mfd/lpc_ich.c:215:34: error: missing type information
[...]
> Applied, thanks!
>
> [1/1] mfd: lpc_ich: Fix ARRAY_SIZE usage for apl_gpio_resources
> commit: 87e172b0fdd3aa4e3d099884e608dbc70ee3e663
Can this be reverted ASAP, please? See below why.
There is no problem with the code. The original author of the change
haven't proved otherwise.
The change made it much worse to read and maintain. By the way, it actually
_added_ the problem as far as I can see with my small test program.
Let's just calculate based on the sizeof(struct foo) taken as 10 for
simplicity and array size as 4x2. The full size of the array is
4 * 2 * 10 bytes. The size of the entry in outer array will be 2 * 10 bytes.
Now, what ARRAY2D_SIZE do is (4 * 2 * 10 / 10 / (2 * 10 / 10) == 4, and
that's WRONG! This will make a out-of-boundary accesses possible.
If smatch can't parse something, it's problem of smatch. No need to "fix"
the working and robust code. The original code even allows (in theory) to have
different amount of resources per entry, however it's quite unlikely to happen.
But at bare minimum it shows the entry taken along with _its_ ARRAY_SIZE()
and not something common over the outer array.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-04-24 19:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-22 13:18 [PATCH] mfd: lpc_ich: Fix ARRAY_SIZE usage for apl_gpio_resources Purva Yeshi
2025-04-04 13:13 ` (subset) " Lee Jones
2025-04-24 19:01 ` Andy Shevchenko [this message]
2025-05-01 12:07 ` Lee Jones
2025-05-02 4:35 ` Andy Shevchenko
2025-05-02 7:27 ` Lee Jones
2025-05-02 9:01 ` Andy Shevchenko
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=aAqKcn25bkrjIiLF@black.fi.intel.com \
--to=andriy.shevchenko@intel.com \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ptyser@xes-inc.com \
--cc=purvayeshi550@gmail.com \
/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