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/misc | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
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/misc')
65 files changed, 129 insertions, 139 deletions
diff --git a/drivers/misc/ad525x_dpot.c b/drivers/misc/ad525x_dpot.c index 04683b981e54..8024378b4e61 100644 --- a/drivers/misc/ad525x_dpot.c +++ b/drivers/misc/ad525x_dpot.c @@ -686,7 +686,7 @@ int ad_dpot_probe(struct device *dev, struct dpot_data *data; int i, err = 0; - data = kzalloc(sizeof(struct dpot_data), GFP_KERNEL); + data = kzalloc_obj(struct dpot_data, GFP_KERNEL); if (!data) { err = -ENOMEM; goto exit; diff --git a/drivers/misc/altera-stapl/altera.c b/drivers/misc/altera-stapl/altera.c index bbe3967c3a4c..334117d3a214 100644 --- a/drivers/misc/altera-stapl/altera.c +++ b/drivers/misc/altera-stapl/altera.c @@ -290,13 +290,13 @@ static int altera_execute(struct altera_state *astate, if (sym_count <= 0) goto exit_done; - vars = kcalloc(sym_count, sizeof(long), GFP_KERNEL); + vars = kzalloc_objs(long, sym_count, GFP_KERNEL); if (vars == NULL) status = -ENOMEM; if (status == 0) { - var_size = kcalloc(sym_count, sizeof(s32), GFP_KERNEL); + var_size = kzalloc_objs(s32, sym_count, GFP_KERNEL); if (var_size == NULL) status = -ENOMEM; @@ -1098,8 +1098,8 @@ exit_done: /* Allocate a writable buffer for this array */ count = var_size[variable_id]; long_tmp = vars[variable_id]; - longptr_tmp = kcalloc(count, sizeof(long), - GFP_KERNEL); + longptr_tmp = kzalloc_objs(long, count, + GFP_KERNEL); vars[variable_id] = (long)longptr_tmp; if (vars[variable_id] == 0) { @@ -2342,8 +2342,7 @@ static int altera_get_act_info(u8 *p, (p[proc_table + (13 * act_proc_id) + 8] & 0x03); procptr = - kzalloc(sizeof(struct altera_procinfo), - GFP_KERNEL); + kzalloc_obj(struct altera_procinfo, GFP_KERNEL); if (procptr == NULL) status = -ENOMEM; @@ -2399,7 +2398,7 @@ int altera_init(struct altera_config *config, const struct firmware *fw) retval = -ENOMEM; goto free_key; } - astate = kzalloc(sizeof(struct altera_state), GFP_KERNEL); + astate = kzalloc_obj(struct altera_state, GFP_KERNEL); if (!astate) { retval = -ENOMEM; goto free_value; diff --git a/drivers/misc/apds9802als.c b/drivers/misc/apds9802als.c index 6db4db975b9a..26d5e002dfa4 100644 --- a/drivers/misc/apds9802als.c +++ b/drivers/misc/apds9802als.c @@ -217,7 +217,7 @@ static int apds9802als_probe(struct i2c_client *client) int res; struct als_data *data; - data = kzalloc(sizeof(struct als_data), GFP_KERNEL); + data = kzalloc_obj(struct als_data, GFP_KERNEL); if (data == NULL) { dev_err(&client->dev, "Memory allocation failed\n"); return -ENOMEM; diff --git a/drivers/misc/apds990x.c b/drivers/misc/apds990x.c index 58946c4ff1a5..b057e659135f 100644 --- a/drivers/misc/apds990x.c +++ b/drivers/misc/apds990x.c @@ -1055,7 +1055,7 @@ static int apds990x_probe(struct i2c_client *client) struct apds990x_chip *chip; int err; - chip = kzalloc(sizeof *chip, GFP_KERNEL); + chip = kzalloc_obj(*chip, GFP_KERNEL); if (!chip) return -ENOMEM; diff --git a/drivers/misc/bcm-vk/bcm_vk_dev.c b/drivers/misc/bcm-vk/bcm_vk_dev.c index d4a96137728d..cdcf334f0ede 100644 --- a/drivers/misc/bcm-vk/bcm_vk_dev.c +++ b/drivers/misc/bcm-vk/bcm_vk_dev.c @@ -1289,7 +1289,7 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent) u32 boot_status; /* allocate vk structure which is tied to kref for freeing */ - vk = kzalloc(sizeof(*vk), GFP_KERNEL); + vk = kzalloc_obj(*vk, GFP_KERNEL); if (!vk) return -ENOMEM; diff --git a/drivers/misc/bcm-vk/bcm_vk_msg.c b/drivers/misc/bcm-vk/bcm_vk_msg.c index 665a3888708a..8537c76e2541 100644 --- a/drivers/misc/bcm-vk/bcm_vk_msg.c +++ b/drivers/misc/bcm-vk/bcm_vk_msg.c @@ -700,7 +700,7 @@ int bcm_vk_send_shutdown_msg(struct bcm_vk *vk, u32 shut_type, return -EINVAL; } - entry = kzalloc(struct_size(entry, to_v_msg, 1), GFP_KERNEL); + entry = kzalloc_flex(*entry, to_v_msg, 1, GFP_KERNEL); if (!entry) return -ENOMEM; entry->to_v_blks = 1; /* always 1 block */ diff --git a/drivers/misc/bcm-vk/bcm_vk_sg.c b/drivers/misc/bcm-vk/bcm_vk_sg.c index d309216ee181..bd8c726fdc0f 100644 --- a/drivers/misc/bcm-vk/bcm_vk_sg.c +++ b/drivers/misc/bcm-vk/bcm_vk_sg.c @@ -60,9 +60,7 @@ static int bcm_vk_dma_alloc(struct device *dev, dma->nr_pages = last - first + 1; /* Allocate DMA pages */ - dma->pages = kmalloc_array(dma->nr_pages, - sizeof(struct page *), - GFP_KERNEL); + dma->pages = kmalloc_objs(struct page *, dma->nr_pages, GFP_KERNEL); if (!dma->pages) return -ENOMEM; diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c index babdb60cc46c..707871bc4a50 100644 --- a/drivers/misc/c2port/core.c +++ b/drivers/misc/c2port/core.c @@ -912,7 +912,7 @@ struct c2port_device *c2port_device_register(char *name, unlikely(!ops->c2d_get) || unlikely(!ops->c2d_set)) return ERR_PTR(-EINVAL); - c2dev = kzalloc(sizeof(struct c2port_device), GFP_KERNEL); + c2dev = kzalloc_obj(struct c2port_device, GFP_KERNEL); if (unlikely(!c2dev)) return ERR_PTR(-ENOMEM); diff --git a/drivers/misc/cardreader/rtsx_pcr.c b/drivers/misc/cardreader/rtsx_pcr.c index f9952d76d6ed..d7211b305918 100644 --- a/drivers/misc/cardreader/rtsx_pcr.c +++ b/drivers/misc/cardreader/rtsx_pcr.c @@ -1385,8 +1385,7 @@ static int rtsx_pci_init_chip(struct rtsx_pcr *pcr) pcr_dbg(pcr, "PID: 0x%04x, IC version: 0x%02x\n", PCI_PID(pcr), pcr->ic_version); - pcr->slots = kcalloc(pcr->num_slots, sizeof(struct rtsx_slot), - GFP_KERNEL); + pcr->slots = kzalloc_objs(struct rtsx_slot, pcr->num_slots, GFP_KERNEL); if (!pcr->slots) return -ENOMEM; @@ -1494,13 +1493,13 @@ static int rtsx_pci_probe(struct pci_dev *pcidev, if (ret) goto disable; - pcr = kzalloc(sizeof(*pcr), GFP_KERNEL); + pcr = kzalloc_obj(*pcr, GFP_KERNEL); if (!pcr) { ret = -ENOMEM; goto release_pci; } - handle = kzalloc(sizeof(*handle), GFP_KERNEL); + handle = kzalloc_obj(*handle, GFP_KERNEL); if (!handle) { ret = -ENOMEM; goto free_pcr; diff --git a/drivers/misc/cs5535-mfgpt.c b/drivers/misc/cs5535-mfgpt.c index 2b6778d8d166..f0bfc6210dab 100644 --- a/drivers/misc/cs5535-mfgpt.c +++ b/drivers/misc/cs5535-mfgpt.c @@ -187,7 +187,7 @@ struct cs5535_mfgpt_timer *cs5535_mfgpt_alloc_timer(int timer_nr, int domain) if (timer_nr < 0) goto done; - timer = kmalloc(sizeof(*timer), GFP_KERNEL); + timer = kmalloc_obj(*timer, GFP_KERNEL); if (!timer) { /* aw hell */ spin_lock_irqsave(&mfgpt->lock, flags); diff --git a/drivers/misc/eeprom/max6875.c b/drivers/misc/eeprom/max6875.c index a3e4cada3b51..dae682d8c4a7 100644 --- a/drivers/misc/eeprom/max6875.c +++ b/drivers/misc/eeprom/max6875.c @@ -144,7 +144,7 @@ static int max6875_probe(struct i2c_client *client) if (client->addr & 1) return -ENODEV; - data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL); + data = kzalloc_obj(struct max6875_data, GFP_KERNEL); if (!data) return -ENOMEM; diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c index ca4c420e4a2f..7c2964762ef0 100644 --- a/drivers/misc/enclosure.c +++ b/drivers/misc/enclosure.c @@ -117,7 +117,7 @@ enclosure_register(struct device *dev, const char *name, int components, struct enclosure_component_callbacks *cb) { struct enclosure_device *edev = - kzalloc(struct_size(edev, component, components), GFP_KERNEL); + kzalloc_flex(*edev, component, components, GFP_KERNEL); int err, i; BUG_ON(!cb); diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 4f5a79c50f58..d212649fe7f9 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -424,7 +424,7 @@ static int __fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev, { struct fastrpc_buf *buf; - buf = kzalloc(sizeof(*buf), GFP_KERNEL); + buf = kzalloc_obj(*buf, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -600,7 +600,7 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( unsigned long flags; int ret; - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); + ctx = kzalloc_obj(*ctx, GFP_KERNEL); if (!ctx) return ERR_PTR(-ENOMEM); @@ -611,14 +611,13 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( REMOTE_SCALARS_OUTBUFS(sc); if (ctx->nscalars) { - ctx->maps = kcalloc(ctx->nscalars, - sizeof(*ctx->maps), GFP_KERNEL); + ctx->maps = kzalloc_objs(*ctx->maps, ctx->nscalars, GFP_KERNEL); if (!ctx->maps) { kfree(ctx); return ERR_PTR(-ENOMEM); } - ctx->olaps = kcalloc(ctx->nscalars, - sizeof(*ctx->olaps), GFP_KERNEL); + ctx->olaps = kzalloc_objs(*ctx->olaps, ctx->nscalars, + GFP_KERNEL); if (!ctx->olaps) { kfree(ctx->maps); kfree(ctx); @@ -705,7 +704,7 @@ static int fastrpc_dma_buf_attach(struct dma_buf *dmabuf, struct fastrpc_buf *buffer = dmabuf->priv; int ret; - a = kzalloc(sizeof(*a), GFP_KERNEL); + a = kzalloc_obj(*a, GFP_KERNEL); if (!a) return -ENOMEM; @@ -787,7 +786,7 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd, struct scatterlist *sgl = NULL; int err = 0, sgl_index = 0; - map = kzalloc(sizeof(*map), GFP_KERNEL); + map = kzalloc_obj(*map, GFP_KERNEL); if (!map) return -ENOMEM; @@ -1307,7 +1306,8 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, } inbuf; u32 sc; - args = kcalloc(FASTRPC_CREATE_STATIC_PROCESS_NARGS, sizeof(*args), GFP_KERNEL); + args = kzalloc_objs(*args, FASTRPC_CREATE_STATIC_PROCESS_NARGS, + GFP_KERNEL); if (!args) return -ENOMEM; @@ -1432,7 +1432,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, u32 sc; bool unsigned_module = false; - args = kcalloc(FASTRPC_CREATE_PROCESS_NARGS, sizeof(*args), GFP_KERNEL); + args = kzalloc_objs(*args, FASTRPC_CREATE_PROCESS_NARGS, GFP_KERNEL); if (!args) return -ENOMEM; @@ -1627,7 +1627,7 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp) fdevice = miscdev_to_fdevice(filp->private_data); cctx = fdevice->cctx; - fl = kzalloc(sizeof(*fl), GFP_KERNEL); + fl = kzalloc_obj(*fl, GFP_KERNEL); if (!fl) return -ENOMEM; @@ -1734,7 +1734,7 @@ static int fastrpc_invoke(struct fastrpc_user *fl, char __user *argp) /* nscalars is truncated here to max supported value */ nscalars = REMOTE_SCALARS_LENGTH(inv.sc); if (nscalars) { - args = kcalloc(nscalars, sizeof(*args), GFP_KERNEL); + args = kzalloc_objs(*args, nscalars, GFP_KERNEL); if (!args) return -ENOMEM; @@ -2371,7 +2371,7 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) else if (!qcom_scm_is_available()) return -EPROBE_DEFER; - data = kzalloc(sizeof(*data), GFP_KERNEL); + data = kzalloc_obj(*data, GFP_KERNEL); if (!data) return -ENOMEM; diff --git a/drivers/misc/genwqe/card_base.c b/drivers/misc/genwqe/card_base.c index 224a7e97cbea..75b970d1012e 100644 --- a/drivers/misc/genwqe/card_base.c +++ b/drivers/misc/genwqe/card_base.c @@ -141,7 +141,7 @@ static struct genwqe_dev *genwqe_dev_alloc(void) if (i >= GENWQE_CARD_NO_MAX) return ERR_PTR(-ENODEV); - cd = kzalloc(sizeof(struct genwqe_dev), GFP_KERNEL); + cd = kzalloc_obj(struct genwqe_dev, GFP_KERNEL); if (!cd) return ERR_PTR(-ENOMEM); @@ -403,8 +403,7 @@ static int genwqe_ffdc_buffs_alloc(struct genwqe_dev *cd) /* currently support only the debug units mentioned here */ cd->ffdc[type].entries = e; cd->ffdc[type].regs = - kmalloc_array(e, sizeof(struct genwqe_reg), - GFP_KERNEL); + kmalloc_objs(struct genwqe_reg, e, GFP_KERNEL); /* * regs == NULL is ok, the using code treats this as no regs, * Printing warning is ok in this case. diff --git a/drivers/misc/genwqe/card_ddcb.c b/drivers/misc/genwqe/card_ddcb.c index fd7d5cd50d39..87286ad04a4b 100644 --- a/drivers/misc/genwqe/card_ddcb.c +++ b/drivers/misc/genwqe/card_ddcb.c @@ -194,7 +194,7 @@ struct genwqe_ddcb_cmd *ddcb_requ_alloc(void) { struct ddcb_requ *req; - req = kzalloc(sizeof(*req), GFP_KERNEL); + req = kzalloc_obj(*req, GFP_KERNEL); if (!req) return NULL; @@ -1046,16 +1046,15 @@ static int setup_ddcb_queue(struct genwqe_dev *cd, struct ddcb_queue *queue) "[%s] **err: could not allocate DDCB **\n", __func__); return -ENOMEM; } - queue->ddcb_req = kcalloc(queue->ddcb_max, sizeof(struct ddcb_requ *), - GFP_KERNEL); + queue->ddcb_req = kzalloc_objs(struct ddcb_requ *, queue->ddcb_max, + GFP_KERNEL); if (!queue->ddcb_req) { rc = -ENOMEM; goto free_ddcbs; } - queue->ddcb_waitqs = kcalloc(queue->ddcb_max, - sizeof(wait_queue_head_t), - GFP_KERNEL); + queue->ddcb_waitqs = kzalloc_objs(wait_queue_head_t, queue->ddcb_max, + GFP_KERNEL); if (!queue->ddcb_waitqs) { rc = -ENOMEM; goto free_requs; diff --git a/drivers/misc/genwqe/card_debugfs.c b/drivers/misc/genwqe/card_debugfs.c index 491fb4482da2..7fc0dce42aa7 100644 --- a/drivers/misc/genwqe/card_debugfs.c +++ b/drivers/misc/genwqe/card_debugfs.c @@ -53,7 +53,7 @@ static int curr_dbg_uidn_show(struct seq_file *s, void *unused, int uid) if (entries == 0) return 0; - regs = kcalloc(entries, sizeof(*regs), GFP_KERNEL); + regs = kzalloc_objs(*regs, entries, GFP_KERNEL); if (regs == NULL) return -ENOMEM; @@ -122,7 +122,7 @@ static int curr_regs_show(struct seq_file *s, void *unused) unsigned int i; struct genwqe_reg *regs; - regs = kcalloc(GENWQE_FFDC_REGS, sizeof(*regs), GFP_KERNEL); + regs = kzalloc_objs(*regs, GENWQE_FFDC_REGS, GFP_KERNEL); if (regs == NULL) return -ENOMEM; diff --git a/drivers/misc/genwqe/card_dev.c b/drivers/misc/genwqe/card_dev.c index 4441aca2280a..9b5458c10053 100644 --- a/drivers/misc/genwqe/card_dev.c +++ b/drivers/misc/genwqe/card_dev.c @@ -301,7 +301,7 @@ static int genwqe_open(struct inode *inode, struct file *filp) struct genwqe_dev *cd; struct genwqe_file *cfile; - cfile = kzalloc(sizeof(*cfile), GFP_KERNEL); + cfile = kzalloc_obj(*cfile, GFP_KERNEL); if (cfile == NULL) return -ENOMEM; @@ -446,7 +446,7 @@ static int genwqe_mmap(struct file *filp, struct vm_area_struct *vma) if (get_order(vsize) > MAX_PAGE_ORDER) return -ENOMEM; - dma_map = kzalloc(sizeof(struct dma_mapping), GFP_KERNEL); + dma_map = kzalloc_obj(struct dma_mapping, GFP_KERNEL); if (dma_map == NULL) return -ENOMEM; @@ -783,7 +783,7 @@ static int genwqe_pin_mem(struct genwqe_file *cfile, struct genwqe_mem *m) map_addr = (m->addr & PAGE_MASK); map_size = round_up(m->size + (m->addr & ~PAGE_MASK), PAGE_SIZE); - dma_map = kzalloc(sizeof(struct dma_mapping), GFP_KERNEL); + dma_map = kzalloc_obj(struct dma_mapping, GFP_KERNEL); if (dma_map == NULL) return -ENOMEM; diff --git a/drivers/misc/hpilo.c b/drivers/misc/hpilo.c index 04bd34c8c506..174cabc7307f 100644 --- a/drivers/misc/hpilo.c +++ b/drivers/misc/hpilo.c @@ -570,7 +570,7 @@ static int ilo_open(struct inode *ip, struct file *fp) hw = container_of(ip->i_cdev, struct ilo_hwinfo, cdev); /* new ccb allocation */ - data = kzalloc(sizeof(*data), GFP_KERNEL); + data = kzalloc_obj(*data, GFP_KERNEL); if (!data) return -ENOMEM; @@ -798,7 +798,7 @@ static int ilo_probe(struct pci_dev *pdev, /* track global allocations for this device */ error = -ENOMEM; - ilo_hw = kzalloc(sizeof(*ilo_hw), GFP_KERNEL); + ilo_hw = kzalloc_obj(*ilo_hw, GFP_KERNEL); if (!ilo_hw) goto out; diff --git a/drivers/misc/ibmasm/command.c b/drivers/misc/ibmasm/command.c index 733dd30fbacc..9e4f45be78d7 100644 --- a/drivers/misc/ibmasm/command.c +++ b/drivers/misc/ibmasm/command.c @@ -24,7 +24,7 @@ struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_s if (buffer_size > IBMASM_CMD_MAX_BUFFER_SIZE) return NULL; - cmd = kzalloc(sizeof(struct command), GFP_KERNEL); + cmd = kzalloc_obj(struct command, GFP_KERNEL); if (cmd == NULL) return NULL; diff --git a/drivers/misc/ibmasm/event.c b/drivers/misc/ibmasm/event.c index 40ce75f8970c..41aabfcd256f 100644 --- a/drivers/misc/ibmasm/event.c +++ b/drivers/misc/ibmasm/event.c @@ -139,7 +139,7 @@ int ibmasm_event_buffer_init(struct service_processor *sp) struct ibmasm_event *event; int i; - buffer = kmalloc(sizeof(struct event_buffer), GFP_KERNEL); + buffer = kmalloc_obj(struct event_buffer, GFP_KERNEL); if (!buffer) return -ENOMEM; diff --git a/drivers/misc/ibmasm/ibmasmfs.c b/drivers/misc/ibmasm/ibmasmfs.c index 824c5b664985..f203bc3e8068 100644 --- a/drivers/misc/ibmasm/ibmasmfs.c +++ b/drivers/misc/ibmasm/ibmasmfs.c @@ -235,7 +235,7 @@ static int command_file_open(struct inode *inode, struct file *file) if (!inode->i_private) return -ENODEV; - command_data = kmalloc(sizeof(struct ibmasmfs_command_data), GFP_KERNEL); + command_data = kmalloc_obj(struct ibmasmfs_command_data, GFP_KERNEL); if (!command_data) return -ENOMEM; @@ -344,7 +344,7 @@ static int event_file_open(struct inode *inode, struct file *file) sp = inode->i_private; - event_data = kmalloc(sizeof(struct ibmasmfs_event_data), GFP_KERNEL); + event_data = kmalloc_obj(struct ibmasmfs_event_data, GFP_KERNEL); if (!event_data) return -ENOMEM; @@ -430,7 +430,7 @@ static int r_heartbeat_file_open(struct inode *inode, struct file *file) if (!inode->i_private) return -ENODEV; - rhbeat = kmalloc(sizeof(struct ibmasmfs_heartbeat_data), GFP_KERNEL); + rhbeat = kmalloc_obj(struct ibmasmfs_heartbeat_data, GFP_KERNEL); if (!rhbeat) return -ENOMEM; diff --git a/drivers/misc/ibmasm/module.c b/drivers/misc/ibmasm/module.c index dc8a06c06c63..ea625673826b 100644 --- a/drivers/misc/ibmasm/module.c +++ b/drivers/misc/ibmasm/module.c @@ -64,7 +64,7 @@ static int ibmasm_init_one(struct pci_dev *pdev, const struct pci_device_id *id) /* vnc client won't work without bus-mastering */ pci_set_master(pdev); - sp = kzalloc(sizeof(struct service_processor), GFP_KERNEL); + sp = kzalloc_obj(struct service_processor, GFP_KERNEL); if (sp == NULL) { dev_err(&pdev->dev, "Failed to allocate memory\n"); result = -ENOMEM; diff --git a/drivers/misc/ibmvmc.c b/drivers/misc/ibmvmc.c index e5f935b5249d..78ecc28f00fb 100644 --- a/drivers/misc/ibmvmc.c +++ b/drivers/misc/ibmvmc.c @@ -830,7 +830,7 @@ static int ibmvmc_open(struct inode *inode, struct file *file) (unsigned long)inode, (unsigned long)file, ibmvmc.state); - session = kzalloc(sizeof(*session), GFP_KERNEL); + session = kzalloc_obj(*session, GFP_KERNEL); if (!session) return -ENOMEM; diff --git a/drivers/misc/ics932s401.c b/drivers/misc/ics932s401.c index 4cdb1087838f..df4d36fe46ac 100644 --- a/drivers/misc/ics932s401.c +++ b/drivers/misc/ics932s401.c @@ -433,7 +433,7 @@ static int ics932s401_probe(struct i2c_client *client) struct ics932s401_data *data; int err; - data = kzalloc(sizeof(struct ics932s401_data), GFP_KERNEL); + data = kzalloc_obj(struct ics932s401_data, GFP_KERNEL); if (!data) { err = -ENOMEM; goto exit; diff --git a/drivers/misc/isl29003.c b/drivers/misc/isl29003.c index 9f26db467a81..ea56dde9183d 100644 --- a/drivers/misc/isl29003.c +++ b/drivers/misc/isl29003.c @@ -383,7 +383,7 @@ static int isl29003_probe(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) return -EIO; - data = kzalloc(sizeof(struct isl29003_data), GFP_KERNEL); + data = kzalloc_obj(struct isl29003_data, GFP_KERNEL); if (!data) return -ENOMEM; diff --git a/drivers/misc/keba/cp500.c b/drivers/misc/keba/cp500.c index d0c6113dcff3..6039a718d92f 100644 --- a/drivers/misc/keba/cp500.c +++ b/drivers/misc/keba/cp500.c @@ -335,7 +335,7 @@ static int cp500_register_i2c(struct cp500 *cp500) { int ret; - cp500->i2c = kzalloc(sizeof(*cp500->i2c), GFP_KERNEL); + cp500->i2c = kzalloc_obj(*cp500->i2c, GFP_KERNEL); if (!cp500->i2c) return -ENOMEM; @@ -386,7 +386,7 @@ static int cp500_register_spi(struct cp500 *cp500, u8 esc_type) int info_size; int ret; - cp500->spi = kzalloc(sizeof(*cp500->spi), GFP_KERNEL); + cp500->spi = kzalloc_obj(*cp500->spi, GFP_KERNEL); if (!cp500->spi) return -ENOMEM; @@ -443,7 +443,7 @@ static int cp500_register_fan(struct cp500 *cp500) { int ret; - cp500->fan = kzalloc(sizeof(*cp500->fan), GFP_KERNEL); + cp500->fan = kzalloc_obj(*cp500->fan, GFP_KERNEL); if (!cp500->fan) return -ENOMEM; @@ -491,7 +491,7 @@ static int cp500_register_batt(struct cp500 *cp500) { int ret; - cp500->batt = kzalloc(sizeof(*cp500->batt), GFP_KERNEL); + cp500->batt = kzalloc_obj(*cp500->batt, GFP_KERNEL); if (!cp500->batt) return -ENOMEM; @@ -541,7 +541,7 @@ static int cp500_register_uart(struct cp500 *cp500, { int ret; - *uart = kzalloc(sizeof(**uart), GFP_KERNEL); + *uart = kzalloc_obj(**uart, GFP_KERNEL); if (!*uart) return -ENOMEM; diff --git a/drivers/misc/lan966x_pci.c b/drivers/misc/lan966x_pci.c index 9c79b58137e5..6245ea993d1b 100644 --- a/drivers/misc/lan966x_pci.c +++ b/drivers/misc/lan966x_pci.c @@ -58,7 +58,7 @@ static struct pci_dev_intr_ctrl *pci_dev_create_intr_ctrl(struct pci_dev *pdev) if (!fwnode) return ERR_PTR(-ENODEV); - intr_ctrl = kmalloc(sizeof(*intr_ctrl), GFP_KERNEL); + intr_ctrl = kmalloc_obj(*intr_ctrl, GFP_KERNEL); if (!intr_ctrl) return ERR_PTR(-ENOMEM); diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c index 1a634ac1a241..f5adec86ca28 100644 --- a/drivers/misc/lis3lv02d/lis3lv02d.c +++ b/drivers/misc/lis3lv02d/lis3lv02d.c @@ -952,7 +952,7 @@ int lis3lv02d_init_dt(struct lis3lv02d *lis3) if (!lis3->of_node) return 0; - pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); + pdata = kzalloc_obj(*pdata, GFP_KERNEL); if (!pdata) return -ENOMEM; diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c index b2aee36b956d..6de369f0ccd2 100644 --- a/drivers/misc/lkdtm/bugs.c +++ b/drivers/misc/lkdtm/bugs.c @@ -477,7 +477,7 @@ static void lkdtm_FAM_BOUNDS(void) { struct lkdtm_cb_fam *inst; - inst = kzalloc(struct_size(inst, array, element_count + 1), GFP_KERNEL); + inst = kzalloc_flex(*inst, array, element_count + 1, GFP_KERNEL); if (!inst) { pr_err("FAIL: could not allocate test struct!\n"); return; @@ -533,7 +533,7 @@ static void lkdtm_PTR_BOUNDS(void) { struct lkdtm_cb_ptr *inst; - inst = kzalloc(sizeof(*inst), GFP_KERNEL); + inst = kzalloc_obj(*inst, GFP_KERNEL); if (!inst) { pr_err("FAIL: could not allocate struct lkdtm_cb_ptr!\n"); return; @@ -547,7 +547,7 @@ static void lkdtm_PTR_BOUNDS(void) inst->len = element_count; /* Double element_count */ - inst->extra = kcalloc(element_count * 2, sizeof(*inst->extra), GFP_KERNEL); + inst->extra = kzalloc_objs(*inst->extra, element_count * 2, GFP_KERNEL); inst->nr_extra = element_count * 2; pr_info("Pointer access within bounds ...\n"); diff --git a/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c b/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c index 34c9be437432..30c24a3e728f 100644 --- a/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c +++ b/drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c @@ -42,8 +42,8 @@ static int gp_aux_bus_probe(struct pci_dev *pdev, const struct pci_device_id *id if (!aux_bus) return -ENOMEM; - aux_bus->aux_device_wrapper[0] = kzalloc(sizeof(*aux_bus->aux_device_wrapper[0]), - GFP_KERNEL); + aux_bus->aux_device_wrapper[0] = kzalloc_obj(*aux_bus->aux_device_wrapper[0], + GFP_KERNEL); if (!aux_bus->aux_device_wrapper[0]) return -ENOMEM; @@ -67,8 +67,8 @@ static int gp_aux_bus_probe(struct pci_dev *pdev, const struct pci_device_id *id if (retval) goto err_aux_dev_add_0; - aux_bus->aux_device_wrapper[1] = kzalloc(sizeof(*aux_bus->aux_device_wrapper[1]), - GFP_KERNEL); + aux_bus->aux_device_wrapper[1] = kzalloc_obj(*aux_bus->aux_device_wrapper[1], + GFP_KERNEL); if (!aux_bus->aux_device_wrapper[1]) { retval = -ENOMEM; goto err_aux_dev_add_0; diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c index 2c810ab12e62..fb311b6633d6 100644 --- a/drivers/misc/mei/bus.c +++ b/drivers/misc/mei/bus.c @@ -1363,7 +1363,7 @@ static struct mei_cl_device *mei_cl_bus_dev_alloc(struct mei_device *bus, struct mei_cl_device *cldev; struct mei_cl *cl; - cldev = kzalloc(sizeof(*cldev), GFP_KERNEL); + cldev = kzalloc_obj(*cldev, GFP_KERNEL); if (!cldev) return NULL; diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c index 5dc665515263..2ad20921ffb7 100644 --- a/drivers/misc/mei/client.c +++ b/drivers/misc/mei/client.c @@ -370,7 +370,7 @@ static struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, { struct mei_cl_cb *cb; - cb = kzalloc(sizeof(*cb), GFP_KERNEL); + cb = kzalloc_obj(*cb, GFP_KERNEL); if (!cb) return NULL; @@ -605,7 +605,7 @@ struct mei_cl *mei_cl_allocate(struct mei_device *dev) { struct mei_cl *cl; - cl = kmalloc(sizeof(*cl), GFP_KERNEL); + cl = kmalloc_obj(*cl, GFP_KERNEL); if (!cl) return NULL; @@ -1273,7 +1273,7 @@ struct mei_cl_vtag *mei_cl_vtag_alloc(struct file *fp, u8 vtag) { struct mei_cl_vtag *cl_vtag; - cl_vtag = kzalloc(sizeof(*cl_vtag), GFP_KERNEL); + cl_vtag = kzalloc_obj(*cl_vtag, GFP_KERNEL); if (!cl_vtag) return ERR_PTR(-ENOMEM); diff --git a/drivers/misc/mei/gsc_proxy/mei_gsc_proxy.c b/drivers/misc/mei/gsc_proxy/mei_gsc_proxy.c index f52fe23a6c0b..00467dc56b9b 100644 --- a/drivers/misc/mei/gsc_proxy/mei_gsc_proxy.c +++ b/drivers/misc/mei/gsc_proxy/mei_gsc_proxy.c @@ -141,7 +141,7 @@ static int mei_gsc_proxy_probe(struct mei_cl_device *cldev, goto enable_err_exit; } - comp_master = kzalloc(sizeof(*comp_master), GFP_KERNEL); + comp_master = kzalloc_obj(*comp_master, GFP_KERNEL); if (!comp_master) { ret = -ENOMEM; goto err_exit; diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c index ccd9df5d1c7d..19db57456f2c 100644 --- a/drivers/misc/mei/hbm.c +++ b/drivers/misc/mei/hbm.c @@ -409,7 +409,7 @@ static int mei_hbm_me_cl_add(struct mei_device *dev, mei_me_cl_rm_by_uuid(dev, uuid); - me_cl = kzalloc(sizeof(*me_cl), GFP_KERNEL); + me_cl = kzalloc_obj(*me_cl, GFP_KERNEL); if (!me_cl) return -ENOMEM; diff --git a/drivers/misc/mei/hdcp/mei_hdcp.c b/drivers/misc/mei/hdcp/mei_hdcp.c index 323f10620d90..68cb4da376f9 100644 --- a/drivers/misc/mei/hdcp/mei_hdcp.c +++ b/drivers/misc/mei/hdcp/mei_hdcp.c @@ -819,7 +819,7 @@ static int mei_hdcp_probe(struct mei_cl_device *cldev, goto enable_err_exit; } - comp_arbiter = kzalloc(sizeof(*comp_arbiter), GFP_KERNEL); + comp_arbiter = kzalloc_obj(*comp_arbiter, GFP_KERNEL); if (!comp_arbiter) { ret = -ENOMEM; goto err_exit; diff --git a/drivers/misc/mei/interrupt.c b/drivers/misc/mei/interrupt.c index 3f210413fd32..d11d19e75726 100644 --- a/drivers/misc/mei/interrupt.c +++ b/drivers/misc/mei/interrupt.c @@ -133,7 +133,8 @@ static int mei_cl_irq_read_msg(struct mei_cl *cl, break; case MEI_EXT_HDR_GSC: gsc_f2h = (struct mei_ext_hdr_gsc_f2h *)ext; - cb->ext_hdr = (struct mei_ext_hdr *)kzalloc(sizeof(*gsc_f2h), GFP_KERNEL); + cb->ext_hdr = (struct mei_ext_hdr *) kzalloc_obj(*gsc_f2h, + GFP_KERNEL); if (!cb->ext_hdr) { cb->status = -ENOMEM; goto discard; diff --git a/drivers/misc/mei/pxp/mei_pxp.c b/drivers/misc/mei/pxp/mei_pxp.c index 2820d389c88e..b79573c32a4d 100644 --- a/drivers/misc/mei/pxp/mei_pxp.c +++ b/drivers/misc/mei/pxp/mei_pxp.c @@ -273,7 +273,7 @@ static int mei_pxp_probe(struct mei_cl_device *cldev, goto enable_err_exit; } - comp_master = kzalloc(sizeof(*comp_master), GFP_KERNEL); + comp_master = kzalloc_obj(*comp_master, GFP_KERNEL); if (!comp_master) { ret = -ENOMEM; goto err_exit; diff --git a/drivers/misc/mei/vsc-fw-loader.c b/drivers/misc/mei/vsc-fw-loader.c index 43abefa806e1..dc32510c9ddb 100644 --- a/drivers/misc/mei/vsc-fw-loader.c +++ b/drivers/misc/mei/vsc-fw-loader.c @@ -721,7 +721,7 @@ int vsc_tp_init(struct vsc_tp *tp, struct device *dev) void *rx_buf __free(kfree) = NULL; int ret; - fw_loader = kzalloc(sizeof(*fw_loader), GFP_KERNEL); + fw_loader = kzalloc_obj(*fw_loader, GFP_KERNEL); if (!fw_loader) return -ENOMEM; diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index 9087f045e362..727d9bbe1a29 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -705,7 +705,7 @@ static struct ntsync_obj *ntsync_alloc_obj(struct ntsync_device *dev, { struct ntsync_obj *obj; - obj = kzalloc(sizeof(*obj), GFP_KERNEL); + obj = kzalloc_obj(*obj, GFP_KERNEL); if (!obj) return NULL; obj->type = type; @@ -884,7 +884,7 @@ static int setup_wait(struct ntsync_device *dev, if (args->alert) fds[count] = args->alert; - q = kmalloc(struct_size(q, entries, total_count), GFP_KERNEL); + q = kmalloc_flex(*q, entries, total_count, GFP_KERNEL); if (!q) return -ENOMEM; q->task = current; @@ -1145,7 +1145,7 @@ static int ntsync_char_open(struct inode *inode, struct file *file) { struct ntsync_device *dev; - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + dev = kzalloc_obj(*dev, GFP_KERNEL); if (!dev) return -ENOMEM; diff --git a/drivers/misc/ocxl/afu_irq.c b/drivers/misc/ocxl/afu_irq.c index f6b821fc274c..3969fc9d58e2 100644 --- a/drivers/misc/ocxl/afu_irq.c +++ b/drivers/misc/ocxl/afu_irq.c @@ -107,7 +107,7 @@ int ocxl_afu_irq_alloc(struct ocxl_context *ctx, int *irq_id) struct afu_irq *irq; int rc; - irq = kzalloc(sizeof(struct afu_irq), GFP_KERNEL); + irq = kzalloc_obj(struct afu_irq, GFP_KERNEL); if (!irq) return -ENOMEM; diff --git a/drivers/misc/ocxl/context.c b/drivers/misc/ocxl/context.c index cded7d1caf32..3ca1c442fb39 100644 --- a/drivers/misc/ocxl/context.c +++ b/drivers/misc/ocxl/context.c @@ -10,7 +10,7 @@ int ocxl_context_alloc(struct ocxl_context **context, struct ocxl_afu *afu, int pasid; struct ocxl_context *ctx; - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); + ctx = kzalloc_obj(*ctx, GFP_KERNEL); if (!ctx) return -ENOMEM; diff --git a/drivers/misc/ocxl/core.c b/drivers/misc/ocxl/core.c index aebfc53a2d09..608ac6a2d855 100644 --- a/drivers/misc/ocxl/core.c +++ b/drivers/misc/ocxl/core.c @@ -17,7 +17,7 @@ static struct ocxl_afu *alloc_afu(struct ocxl_fn *fn) { struct ocxl_afu *afu; - afu = kzalloc(sizeof(struct ocxl_afu), GFP_KERNEL); + afu = kzalloc_obj(struct ocxl_afu, GFP_KERNEL); if (!afu) return NULL; @@ -300,7 +300,7 @@ static struct ocxl_fn *alloc_function(void) { struct ocxl_fn *fn; - fn = kzalloc(sizeof(struct ocxl_fn), GFP_KERNEL); + fn = kzalloc_obj(struct ocxl_fn, GFP_KERNEL); if (!fn) return NULL; diff --git a/drivers/misc/ocxl/file.c b/drivers/misc/ocxl/file.c index 7eb74711ac96..fc03b82c3eb6 100644 --- a/drivers/misc/ocxl/file.c +++ b/drivers/misc/ocxl/file.c @@ -526,7 +526,7 @@ int ocxl_file_register_afu(struct ocxl_afu *afu) struct ocxl_fn *fn = afu->fn; struct pci_dev *pci_dev = to_pci_dev(fn->dev.parent); - info = kzalloc(sizeof(*info), GFP_KERNEL); + info = kzalloc_obj(*info, GFP_KERNEL); if (info == NULL) return -ENOMEM; diff --git a/drivers/misc/ocxl/link.c b/drivers/misc/ocxl/link.c index 03402203cacd..c413d065abe7 100644 --- a/drivers/misc/ocxl/link.c +++ b/drivers/misc/ocxl/link.c @@ -345,7 +345,7 @@ static int alloc_spa(struct pci_dev *dev, struct ocxl_link *link) { struct spa *spa; - spa = kzalloc(sizeof(struct spa), GFP_KERNEL); + spa = kzalloc_obj(struct spa, GFP_KERNEL); if (!spa) return -ENOMEM; @@ -387,7 +387,7 @@ static int alloc_link(struct pci_dev *dev, int PE_mask, struct ocxl_link **out_l struct ocxl_link *link; int rc; - link = kzalloc(sizeof(struct ocxl_link), GFP_KERNEL); + link = kzalloc_obj(struct ocxl_link, GFP_KERNEL); if (!link) return -ENOMEM; @@ -559,7 +559,7 @@ int ocxl_link_add_pe(void *link_handle, int pasid, u32 pidr, u32 tidr, goto unlock; } - pe_data = kmalloc(sizeof(*pe_data), GFP_KERNEL); + pe_data = kmalloc_obj(*pe_data, GFP_KERNEL); if (!pe_data) { rc = -ENOMEM; goto unlock; diff --git a/drivers/misc/ocxl/pasid.c b/drivers/misc/ocxl/pasid.c index d14cb56e6920..677870f49290 100644 --- a/drivers/misc/ocxl/pasid.c +++ b/drivers/misc/ocxl/pasid.c @@ -28,7 +28,7 @@ static int range_alloc(struct list_head *head, u32 size, int max_id, struct id_range *cur, *new; int rc, last_end; - new = kmalloc(sizeof(struct id_range), GFP_KERNEL); + new = kmalloc_obj(struct id_range, GFP_KERNEL); if (!new) return -ENOMEM; diff --git a/drivers/misc/pch_phub.c b/drivers/misc/pch_phub.c index 0d63e834dbe7..c69a88a09332 100644 --- a/drivers/misc/pch_phub.c +++ b/drivers/misc/pch_phub.c @@ -666,7 +666,7 @@ static int pch_phub_probe(struct pci_dev *pdev, int ret; struct pch_phub_reg *chip; - chip = kzalloc(sizeof(struct pch_phub_reg), GFP_KERNEL); + chip = kzalloc_obj(struct pch_phub_reg, GFP_KERNEL); if (chip == NULL) return -ENOMEM; diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c index 701db2c5859b..cb7f7d9243d3 100644 --- a/drivers/misc/phantom.c +++ b/drivers/misc/phantom.c @@ -362,7 +362,7 @@ static int phantom_probe(struct pci_dev *pdev, } retval = -ENOMEM; - pht = kzalloc(sizeof(*pht), GFP_KERNEL); + pht = kzalloc_obj(*pht, GFP_KERNEL); if (pht == NULL) { dev_err(&pdev->dev, "unable to allocate device\n"); goto err_reg; diff --git a/drivers/misc/rpmb-core.c b/drivers/misc/rpmb-core.c index 2d653926cdbb..2bd557665d1a 100644 --- a/drivers/misc/rpmb-core.c +++ b/drivers/misc/rpmb-core.c @@ -161,7 +161,7 @@ struct rpmb_dev *rpmb_dev_register(struct device *dev, !descr->dev_id_len) return ERR_PTR(-EINVAL); - rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); + rdev = kzalloc_obj(*rdev, GFP_KERNEL); if (!rdev) return ERR_PTR(-ENOMEM); rdev->descr = *descr; diff --git a/drivers/misc/sgi-gru/grumain.c b/drivers/misc/sgi-gru/grumain.c index 3036c15f3689..171d38913dcf 100644 --- a/drivers/misc/sgi-gru/grumain.c +++ b/drivers/misc/sgi-gru/grumain.c @@ -356,7 +356,7 @@ struct gru_vma_data *gru_alloc_vma_data(struct vm_area_struct *vma, int tsid) { struct gru_vma_data *vdata = NULL; - vdata = kmalloc(sizeof(*vdata), GFP_KERNEL); + vdata = kmalloc_obj(*vdata, GFP_KERNEL); if (!vdata) return NULL; diff --git a/drivers/misc/sgi-gru/grutlbpurge.c b/drivers/misc/sgi-gru/grutlbpurge.c index 1107dd3e2e9f..1bb07781a105 100644 --- a/drivers/misc/sgi-gru/grutlbpurge.c +++ b/drivers/misc/sgi-gru/grutlbpurge.c @@ -237,7 +237,7 @@ static struct mmu_notifier *gru_alloc_notifier(struct mm_struct *mm) { struct gru_mm_struct *gms; - gms = kzalloc(sizeof(*gms), GFP_KERNEL); + gms = kzalloc_obj(*gms, GFP_KERNEL); if (!gms) return ERR_PTR(-ENOMEM); STAT(gms_alloc); diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c index 9fe816bf3957..4e608379d6e7 100644 --- a/drivers/misc/sgi-xp/xpc_main.c +++ b/drivers/misc/sgi-xp/xpc_main.c @@ -400,9 +400,8 @@ xpc_setup_ch_structures(struct xpc_partition *part) * memory. */ DBUG_ON(part->channels != NULL); - part->channels = kcalloc(XPC_MAX_NCHANNELS, - sizeof(struct xpc_channel), - GFP_KERNEL); + part->channels = kzalloc_objs(struct xpc_channel, XPC_MAX_NCHANNELS, + GFP_KERNEL); if (part->channels == NULL) { dev_err(xpc_chan, "can't get memory for channels\n"); return xpNoMemory; @@ -890,9 +889,8 @@ xpc_setup_partitions(void) short partid; struct xpc_partition *part; - xpc_partitions = kcalloc(xp_max_npartitions, - sizeof(struct xpc_partition), - GFP_KERNEL); + xpc_partitions = kzalloc_objs(struct xpc_partition, xp_max_npartitions, + GFP_KERNEL); if (xpc_partitions == NULL) { dev_err(xpc_part, "can't get memory for partition structure\n"); return -ENOMEM; diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c index 2f03a7080d96..ccd3047580c5 100644 --- a/drivers/misc/sgi-xp/xpc_uv.c +++ b/drivers/misc/sgi-xp/xpc_uv.c @@ -147,7 +147,7 @@ xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char *irq_name, struct xpc_gru_mq_uv *mq; struct uv_IO_APIC_route_entry *mmr_value; - mq = kmalloc(sizeof(struct xpc_gru_mq_uv), GFP_KERNEL); + mq = kmalloc_obj(struct xpc_gru_mq_uv, GFP_KERNEL); if (mq == NULL) { dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to kmalloc() " "a xpc_gru_mq_uv structure\n"); @@ -155,8 +155,7 @@ xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char *irq_name, goto out_0; } - mq->gru_mq_desc = kzalloc(sizeof(struct gru_message_queue_desc), - GFP_KERNEL); + mq->gru_mq_desc = kzalloc_obj(struct gru_message_queue_desc, GFP_KERNEL); if (mq->gru_mq_desc == NULL) { dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to kmalloc() " "a gru_message_queue_desc structure\n"); @@ -623,9 +622,8 @@ again: if (!(part_uv->flags & XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV)) { gru_mq_desc = part_uv->cached_activate_gru_mq_desc; if (gru_mq_desc == NULL) { - gru_mq_desc = kmalloc(sizeof(struct - gru_message_queue_desc), - GFP_ATOMIC); + gru_mq_desc = kmalloc_obj(struct gru_message_queue_desc, + GFP_ATOMIC); if (gru_mq_desc == NULL) { ret = xpNoMemory; goto done; @@ -1075,9 +1073,8 @@ xpc_setup_msg_structures_uv(struct xpc_channel *ch) DBUG_ON(ch->flags & XPC_C_SETUP); - ch_uv->cached_notify_gru_mq_desc = kmalloc(sizeof(struct - gru_message_queue_desc), - GFP_KERNEL); + ch_uv->cached_notify_gru_mq_desc = kmalloc_obj(struct gru_message_queue_desc, + GFP_KERNEL); if (ch_uv->cached_notify_gru_mq_desc == NULL) return xpNoMemory; diff --git a/drivers/misc/sgi-xp/xpnet.c b/drivers/misc/sgi-xp/xpnet.c index 2396ba3b03bd..1533b72d57b1 100644 --- a/drivers/misc/sgi-xp/xpnet.c +++ b/drivers/misc/sgi-xp/xpnet.c @@ -431,7 +431,7 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) * xpc_send_notifies are relying on this skb. When none * remain, release the skb. */ - queued_msg = kmalloc(sizeof(struct xpnet_pending_msg), GFP_ATOMIC); + queued_msg = kmalloc_obj(struct xpnet_pending_msg, GFP_ATOMIC); if (queued_msg == NULL) { dev_warn(xpnet, "failed to kmalloc %ld bytes; dropping " "packet\n", sizeof(struct xpnet_pending_msg)); diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c index c98ff8aa221c..39b38d639638 100644 --- a/drivers/misc/sram.c +++ b/drivers/misc/sram.c @@ -191,7 +191,7 @@ static int sram_reserve_regions(struct sram_dev *sram, struct resource *res) * after the reserved blocks from the dt are processed. */ nblocks = (np) ? of_get_available_child_count(np) + 1 : 1; - rblocks = kcalloc(nblocks, sizeof(*rblocks), GFP_KERNEL); + rblocks = kzalloc_objs(*rblocks, nblocks, GFP_KERNEL); if (!rblocks) return -ENOMEM; diff --git a/drivers/misc/tifm_core.c b/drivers/misc/tifm_core.c index 12355d34e193..96ad091089a7 100644 --- a/drivers/misc/tifm_core.c +++ b/drivers/misc/tifm_core.c @@ -176,7 +176,7 @@ struct tifm_adapter *tifm_alloc_adapter(unsigned int num_sockets, { struct tifm_adapter *fm; - fm = kzalloc(struct_size(fm, sockets, num_sockets), GFP_KERNEL); + fm = kzalloc_flex(*fm, sockets, num_sockets, GFP_KERNEL); if (fm) { fm->dev.class = &tifm_adapter_class; fm->dev.parent = dev; @@ -252,7 +252,7 @@ struct tifm_dev *tifm_alloc_device(struct tifm_adapter *fm, unsigned int id, if (!tifm_media_type_name(type, 0)) return sock; - sock = kzalloc(sizeof(struct tifm_dev), GFP_KERNEL); + sock = kzalloc_obj(struct tifm_dev, GFP_KERNEL); if (sock) { spin_lock_init(&sock->lock); sock->type = type; diff --git a/drivers/misc/tsl2550.c b/drivers/misc/tsl2550.c index 1a7796ab3fad..8f592afe1a32 100644 --- a/drivers/misc/tsl2550.c +++ b/drivers/misc/tsl2550.c @@ -343,7 +343,7 @@ static int tsl2550_probe(struct i2c_client *client) goto exit; } - data = kzalloc(sizeof(struct tsl2550_data), GFP_KERNEL); + data = kzalloc_obj(struct tsl2550_data, GFP_KERNEL); if (!data) { err = -ENOMEM; goto exit; diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c index 6d71355528d3..55735335ce12 100644 --- a/drivers/misc/uacce/uacce.c +++ b/drivers/misc/uacce/uacce.c @@ -158,7 +158,7 @@ static int uacce_fops_open(struct inode *inode, struct file *filep) if (!uacce) return -ENODEV; - q = kzalloc(sizeof(struct uacce_queue), GFP_KERNEL); + q = kzalloc_obj(struct uacce_queue, GFP_KERNEL); if (!q) return -ENOMEM; @@ -251,7 +251,7 @@ static int uacce_fops_mmap(struct file *filep, struct vm_area_struct *vma) else return -EINVAL; - qfr = kzalloc(sizeof(*qfr), GFP_KERNEL); + qfr = kzalloc_obj(*qfr, GFP_KERNEL); if (!qfr) return -ENOMEM; @@ -506,7 +506,7 @@ struct uacce_device *uacce_alloc(struct device *parent, struct uacce_device *uacce; int ret; - uacce = kzalloc(sizeof(struct uacce_device), GFP_KERNEL); + uacce = kzalloc_obj(struct uacce_device, GFP_KERNEL); if (!uacce) return ERR_PTR(-ENOMEM); diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c index 216a16395968..5ae13779bd1a 100644 --- a/drivers/misc/vmw_balloon.c +++ b/drivers/misc/vmw_balloon.c @@ -1616,7 +1616,7 @@ static int vmballoon_enable_stats(struct vmballoon *b) if (b->stats) goto out; - b->stats = kzalloc(sizeof(*b->stats), GFP_KERNEL); + b->stats = kzalloc_obj(*b->stats, GFP_KERNEL); if (!b->stats) { /* allocation failed */ diff --git a/drivers/misc/vmw_vmci/vmci_context.c b/drivers/misc/vmw_vmci/vmci_context.c index 8069d271ed81..0a87d5430385 100644 --- a/drivers/misc/vmw_vmci/vmci_context.c +++ b/drivers/misc/vmw_vmci/vmci_context.c @@ -104,7 +104,7 @@ struct vmci_ctx *vmci_ctx_create(u32 cid, u32 priv_flags, goto err_out; } - context = kzalloc(sizeof(*context), GFP_KERNEL); + context = kzalloc_obj(*context, GFP_KERNEL); if (!context) { pr_warn("Failed to allocate memory for VMCI context\n"); error = -ENOMEM; @@ -294,7 +294,7 @@ int vmci_ctx_enqueue_datagram(u32 cid, struct vmci_datagram *dg) } /* Allocate guest call entry and add it to the target VM's queue. */ - dq_entry = kmalloc(sizeof(*dq_entry), GFP_KERNEL); + dq_entry = kmalloc_obj(*dq_entry, GFP_KERNEL); if (dq_entry == NULL) { pr_warn("Failed to allocate memory for datagram\n"); vmci_ctx_put(context); @@ -598,7 +598,7 @@ int vmci_ctx_add_notification(u32 context_id, u32 remote_cid) goto out; } - notifier = kmalloc(sizeof(struct vmci_handle_list), GFP_KERNEL); + notifier = kmalloc_obj(struct vmci_handle_list, GFP_KERNEL); if (!notifier) { result = VMCI_ERROR_NO_MEM; goto out; diff --git a/drivers/misc/vmw_vmci/vmci_datagram.c b/drivers/misc/vmw_vmci/vmci_datagram.c index 3964d9e5a39b..1a276717e20a 100644 --- a/drivers/misc/vmw_vmci/vmci_datagram.c +++ b/drivers/misc/vmw_vmci/vmci_datagram.c @@ -71,7 +71,7 @@ static int dg_create_handle(u32 resource_id, handle = vmci_make_handle(context_id, resource_id); - entry = kmalloc(sizeof(*entry), GFP_KERNEL); + entry = kmalloc_obj(*entry, GFP_KERNEL); if (!entry) { pr_warn("Failed allocating memory for datagram entry\n"); return VMCI_ERROR_NO_MEM; @@ -224,8 +224,8 @@ static int dg_dispatch_as_host(u32 context_id, struct vmci_datagram *dg) return VMCI_ERROR_NO_MEM; } - dg_info = kmalloc(struct_size(dg_info, msg_payload, dg->payload_size), - GFP_ATOMIC); + dg_info = kmalloc_flex(*dg_info, msg_payload, + dg->payload_size, GFP_ATOMIC); if (!dg_info) { atomic_dec(&delayed_dg_host_queue_size); vmci_resource_put(resource); diff --git a/drivers/misc/vmw_vmci/vmci_doorbell.c b/drivers/misc/vmw_vmci/vmci_doorbell.c index 53eeb9e6cb56..c2db2d4ab7f6 100644 --- a/drivers/misc/vmw_vmci/vmci_doorbell.c +++ b/drivers/misc/vmw_vmci/vmci_doorbell.c @@ -402,7 +402,7 @@ int vmci_doorbell_create(struct vmci_handle *handle, priv_flags & ~VMCI_PRIVILEGE_ALL_FLAGS) return VMCI_ERROR_INVALID_ARGS; - entry = kmalloc(sizeof(*entry), GFP_KERNEL); + entry = kmalloc_obj(*entry, GFP_KERNEL); if (entry == NULL) { pr_warn("Failed allocating memory for datagram entry\n"); return VMCI_ERROR_NO_MEM; diff --git a/drivers/misc/vmw_vmci/vmci_event.c b/drivers/misc/vmw_vmci/vmci_event.c index 9a41ab65378d..85dc12860f17 100644 --- a/drivers/misc/vmw_vmci/vmci_event.c +++ b/drivers/misc/vmw_vmci/vmci_event.c @@ -151,7 +151,7 @@ int vmci_event_subscribe(u32 event, return VMCI_ERROR_INVALID_ARGS; } - sub = kzalloc(sizeof(*sub), GFP_KERNEL); + sub = kzalloc_obj(*sub, GFP_KERNEL); if (!sub) return VMCI_ERROR_NO_MEM; diff --git a/drivers/misc/vmw_vmci/vmci_handle_array.c b/drivers/misc/vmw_vmci/vmci_handle_array.c index 681b3500125a..fd94e4f90322 100644 --- a/drivers/misc/vmw_vmci/vmci_handle_array.c +++ b/drivers/misc/vmw_vmci/vmci_handle_array.c @@ -19,7 +19,7 @@ struct vmci_handle_arr *vmci_handle_arr_create(u32 capacity, u32 max_capacity) capacity = min((u32)VMCI_HANDLE_ARRAY_DEFAULT_CAPACITY, max_capacity); - array = kmalloc(struct_size(array, entries, capacity), GFP_ATOMIC); + array = kmalloc_flex(*array, entries, capacity, GFP_ATOMIC); if (!array) return NULL; diff --git a/drivers/misc/vmw_vmci/vmci_host.c b/drivers/misc/vmw_vmci/vmci_host.c index b64944367ac5..88fea05203d5 100644 --- a/drivers/misc/vmw_vmci/vmci_host.c +++ b/drivers/misc/vmw_vmci/vmci_host.c @@ -120,7 +120,7 @@ static int vmci_host_open(struct inode *inode, struct file *filp) { struct vmci_host_dev *vmci_host_dev; - vmci_host_dev = kzalloc(sizeof(struct vmci_host_dev), GFP_KERNEL); + vmci_host_dev = kzalloc_obj(struct vmci_host_dev, GFP_KERNEL); if (vmci_host_dev == NULL) return -ENOMEM; diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c index b88ac144ad32..d2a7f79f4e8d 100644 --- a/drivers/misc/vmw_vmci/vmci_queue_pair.c +++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c @@ -895,7 +895,7 @@ qp_guest_endpoint_create(struct vmci_handle handle, handle = vmci_make_handle(context_id, VMCI_INVALID_ID); } - entry = kzalloc(sizeof(*entry), GFP_KERNEL); + entry = kzalloc_obj(*entry, GFP_KERNEL); if (entry) { entry->qp.peer = peer; entry->qp.flags = flags; @@ -1318,7 +1318,7 @@ static int qp_broker_create(struct vmci_handle handle, if (is_local && peer != VMCI_INVALID_ID && context_id != peer) return VMCI_ERROR_NO_ACCESS; - entry = kzalloc(sizeof(*entry), GFP_ATOMIC); + entry = kzalloc_obj(*entry, GFP_ATOMIC); if (!entry) return VMCI_ERROR_NO_MEM; @@ -2722,7 +2722,7 @@ int vmci_qpair_alloc(struct vmci_qp **qpair, return VMCI_ERROR_INVALID_ARGS; } - my_qpair = kzalloc(sizeof(*my_qpair), GFP_KERNEL); + my_qpair = kzalloc_obj(*my_qpair, GFP_KERNEL); if (!my_qpair) return VMCI_ERROR_NO_MEM; |
