pinctrl: fix buffer size for pinctrl_generic_set_state_prefix()
authorJohn Keeping <john@metanate.com>
Wed, 7 Sep 2022 11:11:42 +0000 (12:11 +0100)
committerTom Rini <trini@konsulko.com>
Tue, 11 Oct 2022 19:40:48 +0000 (15:40 -0400)
This buffer has the concatenated prefix and name written into it, so it
must be large enough to cover both strings plus the terminating NUL.

Fixes: 92c4a95ec7 ("pinctrl: Add new function pinctrl_generic_set_state_prefix()")
Signed-off-by: John Keeping <john@metanate.com>
Reviewed-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/pinctrl/pinctrl-generic.c

index ec21d4f..8909b57 100644 (file)
@@ -237,7 +237,7 @@ enum pinmux_subnode_type {
 static const char *alloc_name_with_prefix(const char *name, const char *prefix)
 {
        if (prefix) {
-               char *name_with_prefix = malloc(strlen(prefix) + sizeof("pins"));
+               char *name_with_prefix = malloc(strlen(prefix) + strlen(name) + 1);
                if (name_with_prefix)
                        sprintf(name_with_prefix, "%s%s", prefix, name);
                return name_with_prefix;