From: Purva Yeshi <purvayeshi550@gmail.com>
To: Peter Tyser <ptyser@xes-inc.com>, Lee Jones <lee@kernel.org>
Cc: linux-kernel@vger.kernel.org, Purva Yeshi <purvayeshi550@gmail.com>
Subject: [PATCH] mfd: lpc_ich: Fix ARRAY_SIZE usage for apl_gpio_resources
Date: Sat, 22 Mar 2025 18:48:41 +0530 [thread overview]
Message-ID: <20250322131841.31711-1-purvayeshi550@gmail.com> (raw)
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
Use of the ARRAY_SIZE macro on the two-dimensional array apl_gpio_resources
led to incorrect calculations of num_resources, as ARRAY_SIZE only works
for one-dimensional arrays. It attempts to determine the size of the inner
array but does not correctly compute the total number of elements, leading
to incorrect indexing and potential out-of-bounds access.
This resulted in incorrect resource allocation, causing errors.
Replace ARRAY_SIZE(apl_gpio_resources[APL_GPIO_NORTH]) with ARRAY2D_SIZE,
which correctly calculates the number of elements in a 2D array by
considering both rows and columns, ensuring num_resources is assigned the
correct value.
Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
---
drivers/mfd/lpc_ich.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/mfd/lpc_ich.c b/drivers/mfd/lpc_ich.c
index 4b7d0cb9340f..f0b8ff9ed177 100644
--- a/drivers/mfd/lpc_ich.c
+++ b/drivers/mfd/lpc_ich.c
@@ -187,32 +187,34 @@ static struct resource *apl_gpio_mem_resources[APL_GPIO_NR_RESOURCES] = {
[APL_GPIO_SOUTHWEST] = &apl_gpio_resources[APL_GPIO_SOUTHWEST][0],
};
+#define ARRAY2D_SIZE(arr) (sizeof(arr) / sizeof((arr)[0][0]) / (sizeof((arr)[0]) / sizeof((arr)[0][0])))
+
static const struct mfd_cell apl_gpio_devices[APL_GPIO_NR_DEVICES] = {
[APL_GPIO_NORTH] = {
.name = "apollolake-pinctrl",
.id = APL_GPIO_NORTH,
- .num_resources = ARRAY_SIZE(apl_gpio_resources[APL_GPIO_NORTH]),
+ .num_resources = ARRAY2D_SIZE(apl_gpio_resources),
.resources = apl_gpio_resources[APL_GPIO_NORTH],
.ignore_resource_conflicts = true,
},
[APL_GPIO_NORTHWEST] = {
.name = "apollolake-pinctrl",
.id = APL_GPIO_NORTHWEST,
- .num_resources = ARRAY_SIZE(apl_gpio_resources[APL_GPIO_NORTHWEST]),
+ .num_resources = ARRAY2D_SIZE(apl_gpio_resources),
.resources = apl_gpio_resources[APL_GPIO_NORTHWEST],
.ignore_resource_conflicts = true,
},
[APL_GPIO_WEST] = {
.name = "apollolake-pinctrl",
.id = APL_GPIO_WEST,
- .num_resources = ARRAY_SIZE(apl_gpio_resources[APL_GPIO_WEST]),
+ .num_resources = ARRAY2D_SIZE(apl_gpio_resources),
.resources = apl_gpio_resources[APL_GPIO_WEST],
.ignore_resource_conflicts = true,
},
[APL_GPIO_SOUTHWEST] = {
.name = "apollolake-pinctrl",
.id = APL_GPIO_SOUTHWEST,
- .num_resources = ARRAY_SIZE(apl_gpio_resources[APL_GPIO_SOUTHWEST]),
+ .num_resources = ARRAY2D_SIZE(apl_gpio_resources),
.resources = apl_gpio_resources[APL_GPIO_SOUTHWEST],
.ignore_resource_conflicts = true,
},
--
2.34.1
next reply other threads:[~2025-03-22 13:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-22 13:18 Purva Yeshi [this message]
2025-04-04 13:13 ` (subset) [PATCH] mfd: lpc_ich: Fix ARRAY_SIZE usage for apl_gpio_resources Lee Jones
2025-04-24 19:01 ` Andy Shevchenko
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=20250322131841.31711-1-purvayeshi550@gmail.com \
--to=purvayeshi550@gmail.com \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ptyser@xes-inc.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