return -EINVAL;
}
- mc_amd->mpb = xmalloc_bytes(mpbuf->len);
+ mc_amd->mpb = xmemdup_bytes(mpbuf->data, mpbuf->len);
if ( !mc_amd->mpb )
return -ENOMEM;
mc_amd->mpb_size = mpbuf->len;
- memcpy(mc_amd->mpb, mpbuf->data, mpbuf->len);
pr_debug("microcode: CPU%d size %zu, block size %u offset %zu equivID %#x rev %#x\n",
smp_processor_id(), bufsize, mpbuf->len, *offset,
return -EINVAL;
}
- mc_amd->equiv_cpu_table = xmalloc_bytes(mpbuf->len);
+ mc_amd->equiv_cpu_table = xmemdup_bytes(mpbuf->data, mpbuf->len);
if ( !mc_amd->equiv_cpu_table )
- {
- printk(KERN_ERR "microcode: Cannot allocate memory for equivalent cpu table\n");
return -ENOMEM;
- }
- memcpy(mc_amd->equiv_cpu_table, mpbuf->data, mpbuf->len);
mc_amd->equiv_cpu_table_size = mpbuf->len;
return 0;
return -EINVAL;
}
- *mc = xmalloc_bytes(total_size);
+ *mc = xmemdup_bytes(mc_header, total_size);
if ( *mc == NULL )
- {
- printk(KERN_ERR "microcode: error! Can not allocate memory\n");
return -ENOMEM;
- }
- memcpy(*mc, (const void *)(buf + offset), total_size);
+
return offset + total_size;
}
#define xmalloc_bytes(_bytes) _xmalloc(_bytes, SMP_CACHE_BYTES)
#define xzalloc_bytes(_bytes) _xzalloc(_bytes, SMP_CACHE_BYTES)
+/* Allocate untyped storage and copying an existing instance. */
+#define xmemdup_bytes(_src, _nr) \
+ ({ \
+ unsigned long nr_ = (_nr); \
+ void *dst_ = xmalloc_bytes(nr_); \
+ \
+ if ( dst_ ) \
+ memcpy(dst_, _src, nr_); \
+ dst_; \
+ })
+
/* Free any of the above. */
extern void xfree(void *);