* [PATCH] power: supply: cros_charge-control: Avoid accessing attributes out of bounds
@ 2024-07-02 14:48 Nathan Chancellor
2024-07-02 19:09 ` Thomas Weißschuh
2024-07-03 5:59 ` Tzung-Bi Shih
0 siblings, 2 replies; 3+ messages in thread
From: Nathan Chancellor @ 2024-07-02 14:48 UTC (permalink / raw)
To: Thomas Weißschuh, Tzung-Bi Shih, Benson Leung
Cc: Guenter Roeck, Sebastian Reichel, chrome-platform, linux-pm, llvm,
patches, Nathan Chancellor
Clang warns (or errors with CONFIG_WERROR=y):
drivers/power/supply/cros_charge-control.c:319:2: error: array index 3 is past the end of the array (that has type 'struct attribute *[3]') [-Werror,-Warray-bounds]
319 | priv->attributes[_CROS_CHCTL_ATTR_COUNT] = NULL;
| ^ ~~~~~~~~~~~~~~~~~~~~~~
drivers/power/supply/cros_charge-control.c:49:2: note: array 'attributes' declared here
49 | struct attribute *attributes[_CROS_CHCTL_ATTR_COUNT];
| ^
1 error generated.
In earlier revisions of the driver, the attributes array in
cros_chctl_priv had four elements with four distinct assignments but
during review, the number of elements was changed to three through use
of an enum and the assignments became a for loop, except for this one,
which is now out of bounds. This assignment is no longer necessary
because the size of the attributes array no longer accounts for it, so
just remove it to clear up the warning.
Fixes: c6ed48ef5259 ("power: supply: add ChromeOS EC based charge control driver")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
drivers/power/supply/cros_charge-control.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/power/supply/cros_charge-control.c b/drivers/power/supply/cros_charge-control.c
index 73d7f2dc0fa3..2dd8ddbd56bc 100644
--- a/drivers/power/supply/cros_charge-control.c
+++ b/drivers/power/supply/cros_charge-control.c
@@ -316,7 +316,6 @@ static int cros_chctl_probe(struct platform_device *pdev)
sysfs_attr_init(&priv->device_attrs[i].attr);
priv->attributes[i] = &priv->device_attrs[i].attr;
}
- priv->attributes[_CROS_CHCTL_ATTR_COUNT] = NULL;
priv->group.is_visible = cros_chtl_attr_is_visible;
priv->group.attrs = priv->attributes;
---
base-commit: 3664706e875f84bd4e3fa25ed1c6e46934cb32cd
change-id: 20240702-cros_charge-control-fix-clang-array-bounds-warning-b84fd0f642a0
Best regards,
--
Nathan Chancellor <nathan@kernel.org>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] power: supply: cros_charge-control: Avoid accessing attributes out of bounds
2024-07-02 14:48 [PATCH] power: supply: cros_charge-control: Avoid accessing attributes out of bounds Nathan Chancellor
@ 2024-07-02 19:09 ` Thomas Weißschuh
2024-07-03 5:59 ` Tzung-Bi Shih
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Weißschuh @ 2024-07-02 19:09 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Tzung-Bi Shih, Benson Leung, Guenter Roeck, Sebastian Reichel,
chrome-platform, linux-pm, llvm, patches
Hi Nathan,
Thanks!
On 2024-07-02 07:48:48+0000, Nathan Chancellor wrote:
> Clang warns (or errors with CONFIG_WERROR=y):
>
> drivers/power/supply/cros_charge-control.c:319:2: error: array index 3 is past the end of the array (that has type 'struct attribute *[3]') [-Werror,-Warray-bounds]
> 319 | priv->attributes[_CROS_CHCTL_ATTR_COUNT] = NULL;
> | ^ ~~~~~~~~~~~~~~~~~~~~~~
> drivers/power/supply/cros_charge-control.c:49:2: note: array 'attributes' declared here
> 49 | struct attribute *attributes[_CROS_CHCTL_ATTR_COUNT];
> | ^
> 1 error generated.
>
> In earlier revisions of the driver, the attributes array in
> cros_chctl_priv had four elements with four distinct assignments but
> during review, the number of elements was changed to three through use
> of an enum and the assignments became a for loop, except for this one,
> which is now out of bounds. This assignment is no longer necessary
> because the size of the attributes array no longer accounts for it, so
> just remove it to clear up the warning.
>
> Fixes: c6ed48ef5259 ("power: supply: add ChromeOS EC based charge control driver")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Acked-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> drivers/power/supply/cros_charge-control.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/drivers/power/supply/cros_charge-control.c b/drivers/power/supply/cros_charge-control.c
> index 73d7f2dc0fa3..2dd8ddbd56bc 100644
> --- a/drivers/power/supply/cros_charge-control.c
> +++ b/drivers/power/supply/cros_charge-control.c
> @@ -316,7 +316,6 @@ static int cros_chctl_probe(struct platform_device *pdev)
> sysfs_attr_init(&priv->device_attrs[i].attr);
> priv->attributes[i] = &priv->device_attrs[i].attr;
> }
> - priv->attributes[_CROS_CHCTL_ATTR_COUNT] = NULL;
> priv->group.is_visible = cros_chtl_attr_is_visible;
> priv->group.attrs = priv->attributes;
>
>
> ---
> base-commit: 3664706e875f84bd4e3fa25ed1c6e46934cb32cd
> change-id: 20240702-cros_charge-control-fix-clang-array-bounds-warning-b84fd0f642a0
>
> Best regards,
> --
> Nathan Chancellor <nathan@kernel.org>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] power: supply: cros_charge-control: Avoid accessing attributes out of bounds
2024-07-02 14:48 [PATCH] power: supply: cros_charge-control: Avoid accessing attributes out of bounds Nathan Chancellor
2024-07-02 19:09 ` Thomas Weißschuh
@ 2024-07-03 5:59 ` Tzung-Bi Shih
1 sibling, 0 replies; 3+ messages in thread
From: Tzung-Bi Shih @ 2024-07-03 5:59 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Thomas Weißschuh, Benson Leung, Guenter Roeck,
Sebastian Reichel, chrome-platform, linux-pm, llvm, patches
On Tue, Jul 02, 2024 at 07:48:48AM -0700, Nathan Chancellor wrote:
> Clang warns (or errors with CONFIG_WERROR=y):
>
> drivers/power/supply/cros_charge-control.c:319:2: error: array index 3 is past the end of the array (that has type 'struct attribute *[3]') [-Werror,-Warray-bounds]
> 319 | priv->attributes[_CROS_CHCTL_ATTR_COUNT] = NULL;
> | ^ ~~~~~~~~~~~~~~~~~~~~~~
> drivers/power/supply/cros_charge-control.c:49:2: note: array 'attributes' declared here
> 49 | struct attribute *attributes[_CROS_CHCTL_ATTR_COUNT];
> | ^
> 1 error generated.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next
Thanks!
[1/1] power: supply: cros_charge-control: Avoid accessing attributes out of bounds
commit: c98f17fec35e46629272226a898ebb0a653ee270
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-07-03 5:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-02 14:48 [PATCH] power: supply: cros_charge-control: Avoid accessing attributes out of bounds Nathan Chancellor
2024-07-02 19:09 ` Thomas Weißschuh
2024-07-03 5:59 ` Tzung-Bi Shih
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).