diff options
| author | Rasmus Villemoes <[email protected]> | 2026-04-21 09:54:38 +0200 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-05-12 15:38:00 -0600 |
| commit | 4ef201e607ebed2432ee929446e3fb9b57c53a54 (patch) | |
| tree | e619ebada0b2c2595fc52f4a88acc94b3a13b696 | |
| parent | 11168813bf9c088e1fce8a96f4b493ee815c966b (diff) | |
drivers/core: use memdup() instead of malloc()+memcpy()
Use memdup() instead of open-coding it.
In the dm_setup_inst() case, there was never any reason to use
calloc(), as the whole allocation is definitely initialized via the
immediately following memcpy().
Reviewed-by: Simon Glass <[email protected]>
Signed-off-by: Rasmus Villemoes <[email protected]>
| -rw-r--r-- | drivers/core/acpi.c | 3 | ||||
| -rw-r--r-- | drivers/core/ofnode.c | 3 | ||||
| -rw-r--r-- | drivers/core/root.c | 3 |
3 files changed, 3 insertions, 6 deletions
diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c index 4763963914b..6a431171c8d 100644 --- a/drivers/core/acpi.c +++ b/drivers/core/acpi.c @@ -154,10 +154,9 @@ static int add_item(struct acpi_ctx *ctx, struct udevice *dev, if (!item->size) return 0; if (type != TYPE_OTHER) { - item->buf = malloc(item->size); + item->buf = memdup(start, item->size); if (!item->buf) return log_msg_ret("mem", -ENOMEM); - memcpy(item->buf, start, item->size); } item_count++; log_debug("* %s: Added type %d, %p, size %x\n", diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 3a36b6fdd03..12511f10aa9 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -1750,10 +1750,9 @@ int ofnode_write_prop(ofnode node, const char *propname, const void *value, void *newval; if (copy) { - newval = malloc(len); + newval = memdup(value, len); if (!newval) return log_ret(-ENOMEM); - memcpy(newval, value, len); value = newval; } ret = of_write_prop(ofnode_to_np(node), propname, len, value); diff --git a/drivers/core/root.c b/drivers/core/root.c index d43645f34dd..1f32f33b295 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -81,10 +81,9 @@ static int dm_setup_inst(void) /* Now allocate space for the priv/plat data, and copy it in */ size = __priv_data_end - __priv_data_start; - base = calloc(1, size); + base = memdup(__priv_data_start, size); if (!base) return log_msg_ret("priv", -ENOMEM); - memcpy(base, __priv_data_start, size); gd_set_dm_priv_base(base); } |
