dtoverlay: Short-circuit empty parameter handling
authorPhil Elwell <phil@raspberrypi.org>
Wed, 31 May 2017 09:21:16 +0000 (10:21 +0100)
committerpopcornmix <popcornmix@gmail.com>
Tue, 13 Jun 2017 16:51:50 +0000 (17:51 +0100)
Return success early if a parameter declaration has an empty body,
to avoid mallocing a zero-length block and save time.

helpers/dtoverlay/dtoverlay.c

index 7a79db01f6e6dce985e0f00166f293aa5e3b2a43..29e1195eef132b012f6b58be961c0369decef892 100644 (file)
@@ -1328,6 +1328,11 @@ int dtoverlay_foreach_override_target(DTBLOB_T *dtb, const char *override_name,
    int target_phandle = 0;
    char *data;
 
+   /* Short-circuit the degenerate case of an empty parameter, avoiding an
+      apparent memory allocation failure. */
+   if (!data_len)
+      return 0;
+
    /* Copy the override data in case it moves */
    data = malloc(data_len);
    if (!data)