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 <sjg@chromium.org> Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
This commit is contained in:
committed by
Tom Rini
parent
11168813bf
commit
4ef201e607
+1
-2
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
|
||||
+1
-2
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user