diff options
| author | Kees Cook | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/comedi | |
| 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/comedi')
| -rw-r--r-- | drivers/comedi/comedi_buf.c | 2 | ||||
| -rw-r--r-- | drivers/comedi/comedi_fops.c | 8 | ||||
| -rw-r--r-- | drivers/comedi/drivers.c | 4 | ||||
| -rw-r--r-- | drivers/comedi/drivers/addi_apci_2032.c | 2 | ||||
| -rw-r--r-- | drivers/comedi/drivers/comedi_8254.c | 2 | ||||
| -rw-r--r-- | drivers/comedi/drivers/comedi_bond.c | 2 | ||||
| -rw-r--r-- | drivers/comedi/drivers/comedi_isadma.c | 4 | ||||
| -rw-r--r-- | drivers/comedi/drivers/dt9812.c | 4 | ||||
| -rw-r--r-- | drivers/comedi/drivers/mite.c | 4 | ||||
| -rw-r--r-- | drivers/comedi/drivers/ni_670x.c | 5 | ||||
| -rw-r--r-- | drivers/comedi/drivers/ni_tio.c | 9 | ||||
| -rw-r--r-- | drivers/comedi/drivers/usbduxsigma.c | 4 |
12 files changed, 24 insertions, 26 deletions
diff --git a/drivers/comedi/comedi_buf.c b/drivers/comedi/comedi_buf.c index 785977b40a93..7215d4b9152b 100644 --- a/drivers/comedi/comedi_buf.c +++ b/drivers/comedi/comedi_buf.c @@ -70,7 +70,7 @@ comedi_buf_map_alloc(struct comedi_device *dev, enum dma_data_direction dma_dir, struct comedi_buf_page *buf; unsigned int i; - bm = kzalloc(sizeof(*bm), GFP_KERNEL); + bm = kzalloc_obj(*bm, GFP_KERNEL); if (!bm) return NULL; diff --git a/drivers/comedi/comedi_fops.c b/drivers/comedi/comedi_fops.c index 25aa4296f3b0..627680057812 100644 --- a/drivers/comedi/comedi_fops.c +++ b/drivers/comedi/comedi_fops.c @@ -1058,7 +1058,7 @@ static int do_subdinfo_ioctl(struct comedi_device *dev, struct comedi_subdevice *s; lockdep_assert_held(&dev->mutex); - tmp = kcalloc(dev->n_subdevices, sizeof(*tmp), GFP_KERNEL); + tmp = kzalloc_objs(*tmp, dev->n_subdevices, GFP_KERNEL); if (!tmp) return -ENOMEM; @@ -2969,7 +2969,7 @@ static int comedi_open(struct inode *inode, struct file *file) return -ENODEV; } - cfp = kzalloc(sizeof(*cfp), GFP_KERNEL); + cfp = kzalloc_obj(*cfp, GFP_KERNEL); if (!cfp) { comedi_dev_put(dev); return -ENOMEM; @@ -3322,7 +3322,7 @@ static int compat_insnlist(struct file *file, unsigned long arg) rc = check_insnlist_len(dev, insnlist32.n_insns); if (rc) return rc; - insns = kcalloc(insnlist32.n_insns, sizeof(*insns), GFP_KERNEL); + insns = kzalloc_objs(*insns, insnlist32.n_insns, GFP_KERNEL); if (!insns) return -ENOMEM; @@ -3505,7 +3505,7 @@ struct comedi_device *comedi_alloc_board_minor(struct device *hardware_device) struct device *csdev; unsigned int i; - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + dev = kzalloc_obj(*dev, GFP_KERNEL); if (!dev) return ERR_PTR(-ENOMEM); comedi_device_init(dev); diff --git a/drivers/comedi/drivers.c b/drivers/comedi/drivers.c index 69cd2a253c66..b0e39a04f0b3 100644 --- a/drivers/comedi/drivers.c +++ b/drivers/comedi/drivers.c @@ -101,7 +101,7 @@ int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices) if (num_subdevices < 1) return -EINVAL; - s = kcalloc(num_subdevices, sizeof(*s), GFP_KERNEL); + s = kzalloc_objs(*s, num_subdevices, GFP_KERNEL); if (!s) return -ENOMEM; dev->subdevices = s; @@ -733,7 +733,7 @@ static int __comedi_device_postconfig_async(struct comedi_device *dev, dev_warn(dev->class_dev, "async subdevices should have a cancel() function\n"); - async = kzalloc(sizeof(*async), GFP_KERNEL); + async = kzalloc_obj(*async, GFP_KERNEL); if (!async) return -ENOMEM; diff --git a/drivers/comedi/drivers/addi_apci_2032.c b/drivers/comedi/drivers/addi_apci_2032.c index e048dfc3ec77..b81837cd4ad5 100644 --- a/drivers/comedi/drivers/addi_apci_2032.c +++ b/drivers/comedi/drivers/addi_apci_2032.c @@ -274,7 +274,7 @@ static int apci2032_auto_attach(struct comedi_device *dev, struct apci2032_int_private *subpriv; dev->read_subdev = s; - subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL); + subpriv = kzalloc_obj(*subpriv, GFP_KERNEL); if (!subpriv) return -ENOMEM; spin_lock_init(&subpriv->spinlock); diff --git a/drivers/comedi/drivers/comedi_8254.c b/drivers/comedi/drivers/comedi_8254.c index 6beca2a6d66e..a748b452d76d 100644 --- a/drivers/comedi/drivers/comedi_8254.c +++ b/drivers/comedi/drivers/comedi_8254.c @@ -633,7 +633,7 @@ static struct comedi_8254 *__i8254_init(comedi_8254_iocb_fn *iocb, if (!iocb) return ERR_PTR(-EINVAL); - i8254 = kzalloc(sizeof(*i8254), GFP_KERNEL); + i8254 = kzalloc_obj(*i8254, GFP_KERNEL); if (!i8254) return ERR_PTR(-ENOMEM); diff --git a/drivers/comedi/drivers/comedi_bond.c b/drivers/comedi/drivers/comedi_bond.c index 30650fa36fff..1b530c819fc0 100644 --- a/drivers/comedi/drivers/comedi_bond.c +++ b/drivers/comedi/drivers/comedi_bond.c @@ -223,7 +223,7 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it) nchans, minor, sdev); return -EINVAL; } - bdev = kmalloc(sizeof(*bdev), GFP_KERNEL); + bdev = kmalloc_obj(*bdev, GFP_KERNEL); if (!bdev) return -ENOMEM; diff --git a/drivers/comedi/drivers/comedi_isadma.c b/drivers/comedi/drivers/comedi_isadma.c index 020b3d1e1ac0..259678bfd1f3 100644 --- a/drivers/comedi/drivers/comedi_isadma.c +++ b/drivers/comedi/drivers/comedi_isadma.c @@ -161,11 +161,11 @@ struct comedi_isadma *comedi_isadma_alloc(struct comedi_device *dev, if (n_desc < 1 || n_desc > 2) goto no_dma; - dma = kzalloc(sizeof(*dma), GFP_KERNEL); + dma = kzalloc_obj(*dma, GFP_KERNEL); if (!dma) goto no_dma; - desc = kcalloc(n_desc, sizeof(*desc), GFP_KERNEL); + desc = kzalloc_objs(*desc, n_desc, GFP_KERNEL); if (!desc) goto no_dma; dma->desc = desc; diff --git a/drivers/comedi/drivers/dt9812.c b/drivers/comedi/drivers/dt9812.c index b37b9d8eca0d..cace17d6e70e 100644 --- a/drivers/comedi/drivers/dt9812.c +++ b/drivers/comedi/drivers/dt9812.c @@ -329,7 +329,7 @@ static int dt9812_write_multiple_registers(struct comedi_device *dev, int i, count; int ret; - cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); + cmd = kzalloc_obj(*cmd, GFP_KERNEL); if (!cmd) return -ENOMEM; @@ -358,7 +358,7 @@ static int dt9812_rmw_multiple_registers(struct comedi_device *dev, int i, count; int ret; - cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); + cmd = kzalloc_obj(*cmd, GFP_KERNEL); if (!cmd) return -ENOMEM; diff --git a/drivers/comedi/drivers/mite.c b/drivers/comedi/drivers/mite.c index 88f3cd6f54f1..3a16f4b6a292 100644 --- a/drivers/comedi/drivers/mite.c +++ b/drivers/comedi/drivers/mite.c @@ -749,7 +749,7 @@ struct mite_ring *mite_alloc_ring(struct mite *mite) { struct mite_ring *ring; - ring = kmalloc(sizeof(*ring), GFP_KERNEL); + ring = kmalloc_obj(*ring, GFP_KERNEL); if (!ring) return NULL; ring->hw_dev = get_device(&mite->pcidev->dev); @@ -879,7 +879,7 @@ struct mite *mite_attach(struct comedi_device *dev, bool use_win1) unsigned int i; int ret; - mite = kzalloc(sizeof(*mite), GFP_KERNEL); + mite = kzalloc_obj(*mite, GFP_KERNEL); if (!mite) return NULL; diff --git a/drivers/comedi/drivers/ni_670x.c b/drivers/comedi/drivers/ni_670x.c index 563a9c790f12..bc0344d9a07b 100644 --- a/drivers/comedi/drivers/ni_670x.c +++ b/drivers/comedi/drivers/ni_670x.c @@ -198,9 +198,8 @@ static int ni_670x_auto_attach(struct comedi_device *dev, if (s->n_chan == 32) { const struct comedi_lrange **range_table_list; - range_table_list = kmalloc_array(32, - sizeof(*range_table_list), - GFP_KERNEL); + range_table_list = kmalloc_objs(*range_table_list, 32, + GFP_KERNEL); if (!range_table_list) return -ENOMEM; s->range_table_list = range_table_list; diff --git a/drivers/comedi/drivers/ni_tio.c b/drivers/comedi/drivers/ni_tio.c index da6826d77e60..56b5995e2c58 100644 --- a/drivers/comedi/drivers/ni_tio.c +++ b/drivers/comedi/drivers/ni_tio.c @@ -1778,7 +1778,7 @@ ni_gpct_device_construct(struct comedi_device *dev, if (num_counters == 0 || counters_per_chip == 0) return NULL; - counter_dev = kzalloc(sizeof(*counter_dev), GFP_KERNEL); + counter_dev = kzalloc_obj(*counter_dev, GFP_KERNEL); if (!counter_dev) return NULL; @@ -1793,10 +1793,9 @@ ni_gpct_device_construct(struct comedi_device *dev, counter_dev->num_counters = num_counters; counter_dev->num_chips = DIV_ROUND_UP(num_counters, counters_per_chip); - counter_dev->counters = kcalloc(num_counters, sizeof(*counter), - GFP_KERNEL); - counter_dev->regs = kcalloc(counter_dev->num_chips, - sizeof(*counter_dev->regs), GFP_KERNEL); + counter_dev->counters = kzalloc_objs(*counter, num_counters, GFP_KERNEL); + counter_dev->regs = kzalloc_objs(*counter_dev->regs, + counter_dev->num_chips, GFP_KERNEL); if (!counter_dev->regs || !counter_dev->counters) { kfree(counter_dev->regs); kfree(counter_dev->counters); diff --git a/drivers/comedi/drivers/usbduxsigma.c b/drivers/comedi/drivers/usbduxsigma.c index 3f215ae228b2..bcf9116c4bd7 100644 --- a/drivers/comedi/drivers/usbduxsigma.c +++ b/drivers/comedi/drivers/usbduxsigma.c @@ -1336,8 +1336,8 @@ static int usbduxsigma_alloc_usb_buffers(struct comedi_device *dev) devpriv->dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL); devpriv->in_buf = kzalloc(SIZEINBUF, GFP_KERNEL); devpriv->insn_buf = kzalloc(SIZEINSNBUF, GFP_KERNEL); - devpriv->ai_urbs = kcalloc(devpriv->n_ai_urbs, sizeof(urb), GFP_KERNEL); - devpriv->ao_urbs = kcalloc(devpriv->n_ao_urbs, sizeof(urb), GFP_KERNEL); + devpriv->ai_urbs = kzalloc_objs(urb, devpriv->n_ai_urbs, GFP_KERNEL); + devpriv->ao_urbs = kzalloc_objs(urb, devpriv->n_ao_urbs, GFP_KERNEL); if (!devpriv->dux_commands || !devpriv->in_buf || !devpriv->insn_buf || !devpriv->ai_urbs || !devpriv->ao_urbs) return -ENOMEM; |
