mfd: arizona: Fix undefined behavior [Linux 4.9.187]

This Linux kernel change "mfd: arizona: Fix undefined behavior" is included in the Linux 4.9.187 release. This change is authored by Arnd Bergmann <arnd [at]> on Mon May 20 10:06:25 2019 +0100. The commit for this change in Linux stable tree is a3727b0 (patch) which is from upstream commit 5da6cbc. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 5da6cbc.

mfd: arizona: Fix undefined behavior

[ Upstream commit 5da6cbcd2f395981aa9bfc571ace99f1c786c985 ]

When the driver is used with a subdevice that is disabled in the
kernel configuration, clang gets a little confused about the
control flow and fails to notice that n_subdevs is only
uninitialized when subdevs is NULL, and we check for that,
leading to a false-positive warning:

drivers/mfd/arizona-core.c:1423:19: error: variable 'n_subdevs' is uninitialized when used here
                              subdevs, n_subdevs, NULL, 0, NULL);
drivers/mfd/arizona-core.c:999:15: note: initialize the variable 'n_subdevs' to silence this warning
        int n_subdevs, ret, i;
                      = 0

Ideally, we would rearrange the code to avoid all those early
initializations and have an explicit exit in each disabled case,
but it's much easier to chicken out and add one more initialization
here to shut up the warning.

Signed-off-by: Arnd Bergmann <>
Reviewed-by: Nathan Chancellor <>
Signed-off-by: Charles Keepax <>
Signed-off-by: Lee Jones <>
Signed-off-by: Sasha Levin <>

There are 2 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/mfd/arizona-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c
index 41767f7..0556a97 100644
--- a/drivers/mfd/arizona-core.c
+++ b/drivers/mfd/arizona-core.c
@@ -1038,7 +1038,7 @@ int arizona_dev_init(struct arizona *arizona)
    unsigned int reg, val, mask;
    int (*apply_patch)(struct arizona *) = NULL;
    const struct mfd_cell *subdevs = NULL;
-   int n_subdevs, ret, i;
+   int n_subdevs = 0, ret, i;

    dev_set_drvdata(arizona->dev, arizona);

Leave a Reply

Your email address will not be published. Required fields are marked *