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>
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",
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);
/* 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);
}