diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/xen | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | linux-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz linux-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.bz2 linux-69050f8d6d075dc01af7a5f2f550a8067510366f.zip | |
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:
Single allocations: kmalloc(sizeof(TYPE), ...)
are replaced with: kmalloc_obj(TYPE, ...)
Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with: kmalloc_objs(TYPE, COUNT, ...)
Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...)
(where TYPE may also be *VAR)
The resulting allocations no longer return "void *", instead returning
"TYPE *".
Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'drivers/xen')
33 files changed, 108 insertions, 119 deletions
diff --git a/drivers/xen/arm-device.c b/drivers/xen/arm-device.c index 87493f92291f..009c76546d85 100644 --- a/drivers/xen/arm-device.c +++ b/drivers/xen/arm-device.c @@ -59,9 +59,9 @@ static int xen_map_device_mmio(const struct resource *resources, if ((resource_type(r) != IORESOURCE_MEM) || (nr == 0)) continue; - gpfns = kcalloc(nr, sizeof(xen_pfn_t), GFP_KERNEL); - idxs = kcalloc(nr, sizeof(xen_ulong_t), GFP_KERNEL); - errs = kcalloc(nr, sizeof(int), GFP_KERNEL); + gpfns = kzalloc_objs(xen_pfn_t, nr, GFP_KERNEL); + idxs = kzalloc_objs(xen_ulong_t, nr, GFP_KERNEL); + errs = kzalloc_objs(int, nr, GFP_KERNEL); if (!gpfns || !idxs || !errs) { kfree(gpfns); kfree(idxs); diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 9b6531eb28b6..6cbff7e90947 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -242,7 +242,7 @@ static struct resource *additional_memory_resource(phys_addr_t size) struct resource *res; int ret; - res = kzalloc(sizeof(*res), GFP_KERNEL); + res = kzalloc_obj(*res, GFP_KERNEL); if (!res) return NULL; diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c index 663df17776fd..515bb5708e7f 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -714,7 +714,7 @@ static struct irq_info *xen_irq_init(unsigned int irq) { struct irq_info *info; - info = kzalloc(sizeof(*info), GFP_KERNEL); + info = kzalloc_obj(*info, GFP_KERNEL); if (info) { info->irq = irq; info->type = IRQT_UNBOUND; @@ -2292,8 +2292,9 @@ void __init xen_init_IRQ(void) "xen/evtchn:prepare", xen_evtchn_cpu_prepare, xen_evtchn_cpu_dead); - evtchn_to_irq = kcalloc(EVTCHN_ROW(xen_evtchn_max_channels()), - sizeof(*evtchn_to_irq), GFP_KERNEL); + evtchn_to_irq = kzalloc_objs(*evtchn_to_irq, + EVTCHN_ROW(xen_evtchn_max_channels()), + GFP_KERNEL); BUG_ON(!evtchn_to_irq); /* No event channels are 'live' right now. */ diff --git a/drivers/xen/evtchn.c b/drivers/xen/evtchn.c index 7e4a13e632dc..568f1830f3a3 100644 --- a/drivers/xen/evtchn.c +++ b/drivers/xen/evtchn.c @@ -332,7 +332,7 @@ static int evtchn_resize_ring(struct per_user_data *u) else new_size = 2 * u->ring_size; - new_ring = kvmalloc_array(new_size, sizeof(*new_ring), GFP_KERNEL); + new_ring = kvmalloc_objs(*new_ring, new_size, GFP_KERNEL); if (!new_ring) return -ENOMEM; @@ -386,7 +386,7 @@ static int evtchn_bind_to_user(struct per_user_data *u, evtchn_port_t port, * serialized bind operations.) */ - evtchn = kzalloc(sizeof(*evtchn), GFP_KERNEL); + evtchn = kzalloc_obj(*evtchn, GFP_KERNEL); if (!evtchn) return -ENOMEM; @@ -642,7 +642,7 @@ static int evtchn_open(struct inode *inode, struct file *filp) { struct per_user_data *u; - u = kzalloc(sizeof(*u), GFP_KERNEL); + u = kzalloc_obj(*u, GFP_KERNEL); if (u == NULL) return -ENOMEM; diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c index f93f73ecefee..8204135c31f9 100644 --- a/drivers/xen/gntalloc.c +++ b/drivers/xen/gntalloc.c @@ -128,7 +128,7 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op, readonly = !(op->flags & GNTALLOC_FLAG_WRITABLE); for (i = 0; i < op->count; i++) { - gref = kzalloc(sizeof(*gref), GFP_KERNEL); + gref = kzalloc_obj(*gref, GFP_KERNEL); if (!gref) { rc = -ENOMEM; goto undo; @@ -229,7 +229,7 @@ static int gntalloc_open(struct inode *inode, struct file *filp) { struct gntalloc_file_private_data *priv; - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = kzalloc_obj(*priv, GFP_KERNEL); if (!priv) goto out_nomem; INIT_LIST_HEAD(&priv->list); @@ -501,7 +501,7 @@ static int gntalloc_mmap(struct file *filp, struct vm_area_struct *vma) return -EINVAL; } - vm_priv = kmalloc(sizeof(*vm_priv), GFP_KERNEL); + vm_priv = kmalloc_obj(*vm_priv, GFP_KERNEL); if (!vm_priv) return -ENOMEM; diff --git a/drivers/xen/gntdev-dmabuf.c b/drivers/xen/gntdev-dmabuf.c index 550980dd3b0b..649d3a912d20 100644 --- a/drivers/xen/gntdev-dmabuf.c +++ b/drivers/xen/gntdev-dmabuf.c @@ -95,7 +95,7 @@ dmabuf_exp_wait_obj_new(struct gntdev_dmabuf_priv *priv, { struct gntdev_dmabuf_wait_obj *obj; - obj = kzalloc(sizeof(*obj), GFP_KERNEL); + obj = kzalloc_obj(*obj, GFP_KERNEL); if (!obj) return ERR_PTR(-ENOMEM); @@ -198,7 +198,7 @@ dmabuf_pages_to_sgt(struct page **pages, unsigned int nr_pages) struct sg_table *sgt; int ret; - sgt = kmalloc(sizeof(*sgt), GFP_KERNEL); + sgt = kmalloc_obj(*sgt, GFP_KERNEL); if (!sgt) { ret = -ENOMEM; goto out; @@ -222,8 +222,7 @@ static int dmabuf_exp_ops_attach(struct dma_buf *dma_buf, { struct gntdev_dmabuf_attachment *gntdev_dmabuf_attach; - gntdev_dmabuf_attach = kzalloc(sizeof(*gntdev_dmabuf_attach), - GFP_KERNEL); + gntdev_dmabuf_attach = kzalloc_obj(*gntdev_dmabuf_attach, GFP_KERNEL); if (!gntdev_dmabuf_attach) return -ENOMEM; @@ -363,7 +362,7 @@ static int dmabuf_exp_from_pages(struct gntdev_dmabuf_export_args *args) if (ret < 0) return ret; - gntdev_dmabuf = kzalloc(sizeof(*gntdev_dmabuf), GFP_KERNEL); + gntdev_dmabuf = kzalloc_obj(*gntdev_dmabuf, GFP_KERNEL); if (!gntdev_dmabuf) return -ENOMEM; @@ -531,13 +530,12 @@ static struct gntdev_dmabuf *dmabuf_imp_alloc_storage(int count) struct gntdev_dmabuf *gntdev_dmabuf; int i; - gntdev_dmabuf = kzalloc(sizeof(*gntdev_dmabuf), GFP_KERNEL); + gntdev_dmabuf = kzalloc_obj(*gntdev_dmabuf, GFP_KERNEL); if (!gntdev_dmabuf) goto fail_no_free; - gntdev_dmabuf->u.imp.refs = kcalloc(count, - sizeof(gntdev_dmabuf->u.imp.refs[0]), - GFP_KERNEL); + gntdev_dmabuf->u.imp.refs = kzalloc_objs(gntdev_dmabuf->u.imp.refs[0], + count, GFP_KERNEL); if (!gntdev_dmabuf->u.imp.refs) goto fail; @@ -818,7 +816,7 @@ struct gntdev_dmabuf_priv *gntdev_dmabuf_init(struct file *filp) { struct gntdev_dmabuf_priv *priv; - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = kzalloc_obj(*priv, GFP_KERNEL); if (!priv) return ERR_PTR(-ENOMEM); diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index 2c960f187f7c..1a986cb7324a 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -141,19 +141,16 @@ struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count, struct gntdev_grant_map *add; int i; - add = kzalloc(sizeof(*add), GFP_KERNEL); + add = kzalloc_obj(*add, GFP_KERNEL); if (NULL == add) return NULL; - add->grants = kvmalloc_array(count, sizeof(add->grants[0]), - GFP_KERNEL); - add->map_ops = kvmalloc_array(count, sizeof(add->map_ops[0]), - GFP_KERNEL); - add->unmap_ops = kvmalloc_array(count, sizeof(add->unmap_ops[0]), - GFP_KERNEL); - add->pages = kvcalloc(count, sizeof(add->pages[0]), GFP_KERNEL); + add->grants = kvmalloc_objs(add->grants[0], count, GFP_KERNEL); + add->map_ops = kvmalloc_objs(add->map_ops[0], count, GFP_KERNEL); + add->unmap_ops = kvmalloc_objs(add->unmap_ops[0], count, GFP_KERNEL); + add->pages = kvzalloc_objs(add->pages[0], count, GFP_KERNEL); add->being_removed = - kvcalloc(count, sizeof(add->being_removed[0]), GFP_KERNEL); + kvzalloc_objs(add->being_removed[0], count, GFP_KERNEL); if (NULL == add->grants || NULL == add->map_ops || NULL == add->unmap_ops || @@ -161,10 +158,10 @@ struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count, NULL == add->being_removed) goto err; if (xen_pv_domain()) { - add->kmap_ops = kvmalloc_array(count, sizeof(add->kmap_ops[0]), - GFP_KERNEL); - add->kunmap_ops = kvmalloc_array(count, sizeof(add->kunmap_ops[0]), - GFP_KERNEL); + add->kmap_ops = kvmalloc_objs(add->kmap_ops[0], count, + GFP_KERNEL); + add->kunmap_ops = kvmalloc_objs(add->kunmap_ops[0], count, + GFP_KERNEL); if (NULL == add->kmap_ops || NULL == add->kunmap_ops) goto err; } @@ -179,8 +176,7 @@ struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count, if (dma_flags & (GNTDEV_DMA_FLAG_WC | GNTDEV_DMA_FLAG_COHERENT)) { struct gnttab_dma_alloc_args args; - add->frames = kvcalloc(count, sizeof(add->frames[0]), - GFP_KERNEL); + add->frames = kvzalloc_objs(add->frames[0], count, GFP_KERNEL); if (!add->frames) goto err; @@ -587,7 +583,7 @@ static int gntdev_open(struct inode *inode, struct file *flip) { struct gntdev_priv *priv; - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = kzalloc_obj(*priv, GFP_KERNEL); if (!priv) return -ENOMEM; @@ -972,7 +968,7 @@ static long gntdev_ioctl_grant_copy(struct gntdev_priv *priv, void __user *u) mutex_lock(&priv->batch_lock); if (!priv->batch) { - batch = kmalloc(sizeof(*batch), GFP_KERNEL); + batch = kmalloc_obj(*batch, GFP_KERNEL); } else { batch = priv->batch; priv->batch = batch->next; diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index 3e76e33f6e08..6fcd5a7f6605 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -556,7 +556,7 @@ static void gnttab_add_deferred(grant_ref_t ref, struct page *page) gfp_t gfp = (in_atomic() || irqs_disabled()) ? GFP_ATOMIC : GFP_KERNEL; uint64_t leaked, deferred; - entry = kmalloc(sizeof(*entry), gfp); + entry = kmalloc_obj(*entry, gfp); if (!page) { unsigned long gfn = gnttab_interface->read_frame(ref); @@ -831,7 +831,7 @@ int gnttab_setup_auto_xlat_frames(phys_addr_t addr) &addr); return -ENOMEM; } - pfn = kcalloc(max_nr_gframes, sizeof(pfn[0]), GFP_KERNEL); + pfn = kzalloc_objs(pfn[0], max_nr_gframes, GFP_KERNEL); if (!pfn) { memunmap(vaddr); return -ENOMEM; @@ -868,7 +868,7 @@ int gnttab_pages_set_private(int nr_pages, struct page **pages) #if BITS_PER_LONG < 64 struct xen_page_foreign *foreign; - foreign = kzalloc(sizeof(*foreign), GFP_KERNEL); + foreign = kzalloc_obj(*foreign, GFP_KERNEL); if (!foreign) return -ENOMEM; @@ -1635,9 +1635,8 @@ int gnttab_init(void) */ max_nr_glist_frames = max_nr_grefs / RPP; - gnttab_list = kmalloc_array(max_nr_glist_frames, - sizeof(grant_ref_t *), - GFP_KERNEL); + gnttab_list = kmalloc_objs(grant_ref_t *, max_nr_glist_frames, + GFP_KERNEL); if (gnttab_list == NULL) return -ENOMEM; diff --git a/drivers/xen/mcelog.c b/drivers/xen/mcelog.c index abe658c73b7b..ca8dbb9be419 100644 --- a/drivers/xen/mcelog.c +++ b/drivers/xen/mcelog.c @@ -373,8 +373,7 @@ static int bind_virq_for_mce(void) /* Fetch each CPU Physical Info for later reference*/ ncpus = mc_op.u.mc_physcpuinfo.ncpus; - g_physinfo = kcalloc(ncpus, sizeof(struct mcinfo_logical_cpu), - GFP_KERNEL); + g_physinfo = kzalloc_objs(struct mcinfo_logical_cpu, ncpus, GFP_KERNEL); if (!g_physinfo) return -ENOMEM; set_xen_guest_handle(mc_op.u.mc_physcpuinfo.info, g_physinfo); diff --git a/drivers/xen/pci.c b/drivers/xen/pci.c index bfe07adb3e3a..07e6b811c9d3 100644 --- a/drivers/xen/pci.c +++ b/drivers/xen/pci.c @@ -336,7 +336,7 @@ int xen_register_device_domain_owner(struct pci_dev *dev, uint16_t domain) { struct xen_device_domain_owner *owner; - owner = kzalloc(sizeof(struct xen_device_domain_owner), GFP_KERNEL); + owner = kzalloc_obj(struct xen_device_domain_owner, GFP_KERNEL); if (!owner) return -ENODEV; diff --git a/drivers/xen/pcpu.c b/drivers/xen/pcpu.c index 093ad4a08672..1d9f3874d099 100644 --- a/drivers/xen/pcpu.c +++ b/drivers/xen/pcpu.c @@ -247,7 +247,7 @@ static struct pcpu *create_and_register_pcpu(struct xenpf_pcpuinfo *info) if (info->flags & XEN_PCPU_FLAGS_INVALID) return ERR_PTR(-ENODEV); - pcpu = kzalloc(sizeof(struct pcpu), GFP_KERNEL); + pcpu = kzalloc_obj(struct pcpu, GFP_KERNEL); if (!pcpu) return ERR_PTR(-ENOMEM); diff --git a/drivers/xen/privcmd-buf.c b/drivers/xen/privcmd-buf.c index 0f0dad427d7e..95d2d5ca5e4f 100644 --- a/drivers/xen/privcmd-buf.c +++ b/drivers/xen/privcmd-buf.c @@ -39,7 +39,7 @@ static int privcmd_buf_open(struct inode *ino, struct file *file) { struct privcmd_buf_private *file_priv; - file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL); + file_priv = kzalloc_obj(*file_priv, GFP_KERNEL); if (!file_priv) return -ENOMEM; @@ -141,7 +141,7 @@ static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma) if (!(vma->vm_flags & VM_SHARED)) return -EINVAL; - vma_priv = kzalloc(struct_size(vma_priv, pages, count), GFP_KERNEL); + vma_priv = kzalloc_flex(*vma_priv, pages, count, GFP_KERNEL); if (!vma_priv) return -ENOMEM; diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 402be080ad2c..a5d9211f36c3 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -433,7 +433,7 @@ static int alloc_empty_pages(struct vm_area_struct *vma, int numpgs) int rc; struct page **pages; - pages = kvcalloc(numpgs, sizeof(pages[0]), GFP_KERNEL); + pages = kvzalloc_objs(pages[0], numpgs, GFP_KERNEL); if (pages == NULL) return -ENOMEM; @@ -653,7 +653,7 @@ static long privcmd_ioctl_dm_op(struct file *file, void __user *udata) if (kdata.num > privcmd_dm_op_max_num) return -E2BIG; - kbufs = kcalloc(kdata.num, sizeof(*kbufs), GFP_KERNEL); + kbufs = kzalloc_objs(*kbufs, kdata.num, GFP_KERNEL); if (!kbufs) return -ENOMEM; @@ -680,13 +680,13 @@ static long privcmd_ioctl_dm_op(struct file *file, void __user *udata) PAGE_SIZE); } - pages = kcalloc(nr_pages, sizeof(*pages), GFP_KERNEL); + pages = kzalloc_objs(*pages, nr_pages, GFP_KERNEL); if (!pages) { rc = -ENOMEM; goto out; } - xbufs = kcalloc(kdata.num, sizeof(*xbufs), GFP_KERNEL); + xbufs = kzalloc_objs(*xbufs, kdata.num, GFP_KERNEL); if (!xbufs) { rc = -ENOMEM; goto out; @@ -773,7 +773,7 @@ static long privcmd_ioctl_mmap_resource(struct file *file, goto out; } - pfns = kcalloc(kdata.num, sizeof(*pfns), GFP_KERNEL | __GFP_NOWARN); + pfns = kzalloc_objs(*pfns, kdata.num, GFP_KERNEL | __GFP_NOWARN); if (!pfns) { rc = -ENOMEM; goto out; @@ -1355,7 +1355,7 @@ static int privcmd_ioeventfd_assign(struct privcmd_ioeventfd *ioeventfd) if (!ioeventfd->vcpus || ioeventfd->vcpus > 4096) return -EINVAL; - kioeventfd = kzalloc(sizeof(*kioeventfd), GFP_KERNEL); + kioeventfd = kzalloc_obj(*kioeventfd, GFP_KERNEL); if (!kioeventfd) return -ENOMEM; @@ -1563,7 +1563,7 @@ static long privcmd_ioctl(struct file *file, static int privcmd_open(struct inode *ino, struct file *file) { - struct privcmd_data *data = kzalloc(sizeof(*data), GFP_KERNEL); + struct privcmd_data *data = kzalloc_obj(*data, GFP_KERNEL); if (!data) return -ENOMEM; diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c index c5b6f6fa11eb..8a5dafcaab03 100644 --- a/drivers/xen/pvcalls-back.c +++ b/drivers/xen/pvcalls-back.c @@ -324,7 +324,7 @@ static struct sock_mapping *pvcalls_new_active_socket( struct sock_mapping *map; void *page; - map = kzalloc(sizeof(*map), GFP_KERNEL); + map = kzalloc_obj(*map, GFP_KERNEL); if (map == NULL) { sock_release(sock); return NULL; @@ -632,7 +632,7 @@ static int pvcalls_back_bind(struct xenbus_device *dev, fedata = dev_get_drvdata(&dev->dev); - map = kzalloc(sizeof(*map), GFP_KERNEL); + map = kzalloc_obj(*map, GFP_KERNEL); if (map == NULL) { ret = -ENOMEM; goto out; @@ -934,7 +934,7 @@ static int backend_connect(struct xenbus_device *dev) grant_ref_t ring_ref; struct pvcalls_fedata *fedata = NULL; - fedata = kzalloc(sizeof(struct pvcalls_fedata), GFP_KERNEL); + fedata = kzalloc_obj(struct pvcalls_fedata, GFP_KERNEL); if (!fedata) return -ENOMEM; diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c index 4926d4badc57..c32fd69482e9 100644 --- a/drivers/xen/pvcalls-front.c +++ b/drivers/xen/pvcalls-front.c @@ -291,7 +291,7 @@ int pvcalls_front_socket(struct socket *sock) } bedata = dev_get_drvdata(&pvcalls_front_dev->dev); - map = kzalloc(sizeof(*map), GFP_KERNEL); + map = kzalloc_obj(*map, GFP_KERNEL); if (map == NULL) { pvcalls_exit(); return -ENOMEM; @@ -820,7 +820,7 @@ int pvcalls_front_accept(struct socket *sock, struct socket *newsock, } } - map2 = kzalloc(sizeof(*map2), GFP_KERNEL); + map2 = kzalloc_obj(*map2, GFP_KERNEL); if (map2 == NULL) { clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, (void *)&map->passive.flags); @@ -1179,7 +1179,7 @@ static int pvcalls_front_probe(struct xenbus_device *dev, return -ENODEV; pr_info("%s max-page-order is %u\n", __func__, max_page_order); - bedata = kzalloc(sizeof(struct pvcalls_bedata), GFP_KERNEL); + bedata = kzalloc_obj(struct pvcalls_bedata, GFP_KERNEL); if (!bedata) return -ENOMEM; diff --git a/drivers/xen/sys-hypervisor.c b/drivers/xen/sys-hypervisor.c index 2f880374b463..25f4e1ff13f6 100644 --- a/drivers/xen/sys-hypervisor.c +++ b/drivers/xen/sys-hypervisor.c @@ -182,7 +182,7 @@ static ssize_t compiler_show(struct hyp_sysfs_attr *attr, char *buffer) int ret = -ENOMEM; struct xen_compile_info *info; - info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL); + info = kmalloc_obj(struct xen_compile_info, GFP_KERNEL); if (info) { ret = HYPERVISOR_xen_version(XENVER_compile_info, info); if (!ret) @@ -200,7 +200,7 @@ static ssize_t compiled_by_show(struct hyp_sysfs_attr *attr, char *buffer) int ret = -ENOMEM; struct xen_compile_info *info; - info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL); + info = kmalloc_obj(struct xen_compile_info, GFP_KERNEL); if (info) { ret = HYPERVISOR_xen_version(XENVER_compile_info, info); if (!ret) @@ -218,7 +218,7 @@ static ssize_t compile_date_show(struct hyp_sysfs_attr *attr, char *buffer) int ret = -ENOMEM; struct xen_compile_info *info; - info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL); + info = kmalloc_obj(struct xen_compile_info, GFP_KERNEL); if (info) { ret = HYPERVISOR_xen_version(XENVER_compile_info, info); if (!ret) @@ -291,7 +291,7 @@ static ssize_t virtual_start_show(struct hyp_sysfs_attr *attr, char *buffer) int ret = -ENOMEM; struct xen_platform_parameters *parms; - parms = kmalloc(sizeof(struct xen_platform_parameters), GFP_KERNEL); + parms = kmalloc_obj(struct xen_platform_parameters, GFP_KERNEL); if (parms) { ret = HYPERVISOR_xen_version(XENVER_platform_parameters, parms); diff --git a/drivers/xen/time.c b/drivers/xen/time.c index 0b18d8a5a2dd..a2be0a4d45b0 100644 --- a/drivers/xen/time.c +++ b/drivers/xen/time.c @@ -94,9 +94,8 @@ void xen_manage_runstate_time(int action) pr_warn_once("%s: memory leak as runstate_delta is not NULL\n", __func__); - runstate_delta = kmalloc_array(num_possible_cpus(), - sizeof(*runstate_delta), - GFP_ATOMIC); + runstate_delta = kmalloc_objs(*runstate_delta, + num_possible_cpus(), GFP_ATOMIC); if (unlikely(!runstate_delta)) { pr_warn("%s: failed to allocate runstate_delta\n", __func__); diff --git a/drivers/xen/unpopulated-alloc.c b/drivers/xen/unpopulated-alloc.c index 1dc0b495c8e5..4cfb6abdc3d8 100644 --- a/drivers/xen/unpopulated-alloc.c +++ b/drivers/xen/unpopulated-alloc.c @@ -43,7 +43,7 @@ static int fill_list(unsigned int nr_pages) struct range mhp_range; int ret; - res = kzalloc(sizeof(*res), GFP_KERNEL); + res = kzalloc_obj(*res, GFP_KERNEL); if (!res) return -ENOMEM; @@ -65,7 +65,7 @@ static int fill_list(unsigned int nr_pages) * re-using it by someone else. */ if (target_resource != &iomem_resource) { - tmp_res = kzalloc(sizeof(*tmp_res), GFP_KERNEL); + tmp_res = kzalloc_obj(*tmp_res, GFP_KERNEL); if (!tmp_res) { ret = -ENOMEM; goto err_insert; @@ -84,7 +84,7 @@ static int fill_list(unsigned int nr_pages) } } - pgmap = kzalloc(sizeof(*pgmap), GFP_KERNEL); + pgmap = kzalloc_obj(*pgmap, GFP_KERNEL); if (!pgmap) { ret = -ENOMEM; goto err_pgmap; diff --git a/drivers/xen/xen-acpi-processor.c b/drivers/xen/xen-acpi-processor.c index f2e8eaf684ba..d7effbaf8948 100644 --- a/drivers/xen/xen-acpi-processor.c +++ b/drivers/xen/xen-acpi-processor.c @@ -61,8 +61,8 @@ static int push_cxx_to_hypervisor(struct acpi_processor *_pr) unsigned int i, ok; int ret = 0; - dst_cx_states = kcalloc(_pr->power.count, - sizeof(struct xen_processor_cx), GFP_KERNEL); + dst_cx_states = kzalloc_objs(struct xen_processor_cx, _pr->power.count, + GFP_KERNEL); if (!dst_cx_states) return -ENOMEM; @@ -142,8 +142,8 @@ xen_copy_pss_data(struct acpi_processor *_pr, BUILD_BUG_ON(sizeof(struct xen_processor_px) != sizeof(struct acpi_processor_px)); - dst_states = kcalloc(_pr->performance->state_count, - sizeof(struct xen_processor_px), GFP_KERNEL); + dst_states = kzalloc_objs(struct xen_processor_px, + _pr->performance->state_count, GFP_KERNEL); if (!dst_states) return ERR_PTR(-ENOMEM); @@ -412,8 +412,8 @@ static int check_acpi_ids(struct acpi_processor *pr_backup) return -ENOMEM; } - acpi_psd = kcalloc(nr_acpi_bits, sizeof(struct acpi_psd_package), - GFP_KERNEL); + acpi_psd = kzalloc_objs(struct acpi_psd_package, nr_acpi_bits, + GFP_KERNEL); if (!acpi_psd) { bitmap_free(acpi_id_present); bitmap_free(acpi_id_cst_present); diff --git a/drivers/xen/xen-front-pgdir-shbuf.c b/drivers/xen/xen-front-pgdir-shbuf.c index 223870a0111b..32e28f044b33 100644 --- a/drivers/xen/xen-front-pgdir-shbuf.c +++ b/drivers/xen/xen-front-pgdir-shbuf.c @@ -205,8 +205,7 @@ static int backend_unmap(struct xen_front_pgdir_shbuf *buf) if (!buf->pages || !buf->backend_map_handles || !buf->grefs) return 0; - unmap_ops = kcalloc(buf->num_pages, sizeof(*unmap_ops), - GFP_KERNEL); + unmap_ops = kzalloc_objs(*unmap_ops, buf->num_pages, GFP_KERNEL); if (!unmap_ops) return -ENOMEM; @@ -250,13 +249,12 @@ static int backend_map(struct xen_front_pgdir_shbuf *buf) unsigned char *ptr; int ret, cur_gref, cur_dir_page, cur_page, grefs_left; - map_ops = kcalloc(buf->num_pages, sizeof(*map_ops), GFP_KERNEL); + map_ops = kzalloc_objs(*map_ops, buf->num_pages, GFP_KERNEL); if (!map_ops) return -ENOMEM; - buf->backend_map_handles = kcalloc(buf->num_pages, - sizeof(*buf->backend_map_handles), - GFP_KERNEL); + buf->backend_map_handles = kzalloc_objs(*buf->backend_map_handles, + buf->num_pages, GFP_KERNEL); if (!buf->backend_map_handles) { kfree(map_ops); return -ENOMEM; @@ -474,7 +472,7 @@ static int grant_references(struct xen_front_pgdir_shbuf *buf) */ static int alloc_storage(struct xen_front_pgdir_shbuf *buf) { - buf->grefs = kcalloc(buf->num_grefs, sizeof(*buf->grefs), GFP_KERNEL); + buf->grefs = kzalloc_objs(*buf->grefs, buf->num_grefs, GFP_KERNEL); if (!buf->grefs) return -ENOMEM; diff --git a/drivers/xen/xen-pciback/conf_space.c b/drivers/xen/xen-pciback/conf_space.c index d47eee6c5143..fbc40acd593f 100644 --- a/drivers/xen/xen-pciback/conf_space.c +++ b/drivers/xen/xen-pciback/conf_space.c @@ -401,7 +401,7 @@ int xen_pcibk_config_add_field_offset(struct pci_dev *dev, struct config_field_entry *cfg_entry; void *tmp; - cfg_entry = kmalloc(sizeof(*cfg_entry), GFP_KERNEL); + cfg_entry = kmalloc_obj(*cfg_entry, GFP_KERNEL); if (!cfg_entry) { err = -ENOMEM; goto out; diff --git a/drivers/xen/xen-pciback/conf_space_header.c b/drivers/xen/xen-pciback/conf_space_header.c index fc0332645966..0efbd85cf7e1 100644 |
