dtoverlay: Short-circuit empty parameter handling

Return success early if a parameter declaration has an empty body,
to avoid mallocing a zero-length block and save time.
This commit is contained in:
Phil Elwell
2017-05-31 10:21:16 +01:00
committed by popcornmix
parent 126f3de96f
commit 70239d863c

View File

@@ -1328,6 +1328,11 @@ int dtoverlay_foreach_override_target(DTBLOB_T *dtb, const char *override_name,
int target_phandle = 0; int target_phandle = 0;
char *data; 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 */ /* Copy the override data in case it moves */
data = malloc(data_len); data = malloc(data_len);
if (!data) if (!data)