diff mbox series

[01/12] Kconfig: Add error path in conf_value_to_yaml

Message ID 20241218-jag-bringup_fixes-v1-1-0bf2e07c640c@kernel.org (mailing list archive)
State New
Headers show
Series kdevops: Various fixes | expand

Commit Message

Joel Granados Dec. 18, 2024, 10:29 a.m. UTC
The asprintf call returns -1 on error. In this case the value of
yaml_value is undefined. Return NULL, so the caller can handle the
error.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
---
 scripts/kconfig/confdata.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 0156b38..49a5729 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -669,14 +669,14 @@  static char *conf_value_to_yaml(struct symbol *sym, const char *val)
 		yaml_value = strdup(val);
 		break;
 	case S_HEX:
-            asprintf(&yaml_value, "0x%s", val);
-            break;
-        case S_STRING:
-	    /* Wrap strings in quotes */
-            asprintf(&yaml_value, "\"%s\"", val);
-            break;
-        case S_BOOLEAN:
-        case S_TRISTATE:
+		if (asprintf(&yaml_value, "0x%s", val) < 0)
+			return NULL;
+	case S_STRING:
+		/* Wrap strings in quotes */
+		if (asprintf(&yaml_value, "\"%s\"", val) < 0)
+			return NULL;
+	case S_BOOLEAN:
+	case S_TRISTATE:
 		if (strcmp(val, "y") == 0)
 			yaml_value = strdup("True");
 		else if (strcmp(val, "n") == 0)