Commit c98f17fe authored by Nathan Chancellor's avatar Nathan Chancellor Committed by Tzung-Bi Shih

power: supply: cros_charge-control: Avoid accessing attributes out of bounds

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: c6ed48ef ("power: supply: add ChromeOS EC based charge control driver")
Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
Acked-by: default avatarThomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20240702-cros_charge-control-fix-clang-array-bounds-warning-v1-1-ae04d995cd1d@kernel.orgSigned-off-by: default avatarTzung-Bi Shih <tzungbi@kernel.org>
parent 3664706e
...@@ -316,7 +316,6 @@ static int cros_chctl_probe(struct platform_device *pdev) ...@@ -316,7 +316,6 @@ static int cros_chctl_probe(struct platform_device *pdev)
sysfs_attr_init(&priv->device_attrs[i].attr); sysfs_attr_init(&priv->device_attrs[i].attr);
priv->attributes[i] = &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.is_visible = cros_chtl_attr_is_visible;
priv->group.attrs = priv->attributes; priv->group.attrs = priv->attributes;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment