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/input/serio | |
| 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/input/serio')
26 files changed, 41 insertions, 41 deletions
diff --git a/drivers/input/serio/altera_ps2.c b/drivers/input/serio/altera_ps2.c index 761aaaa3e571..b2f5fec9290c 100644 --- a/drivers/input/serio/altera_ps2.c +++ b/drivers/input/serio/altera_ps2.c @@ -100,7 +100,7 @@ static int altera_ps2_probe(struct platform_device *pdev) return error; } - serio = kzalloc(sizeof(*serio), GFP_KERNEL); + serio = kzalloc_obj(*serio, GFP_KERNEL); if (!serio) return -ENOMEM; diff --git a/drivers/input/serio/ambakmi.c b/drivers/input/serio/ambakmi.c index de4b3915c37d..5a4ef62fa3d3 100644 --- a/drivers/input/serio/ambakmi.c +++ b/drivers/input/serio/ambakmi.c @@ -114,8 +114,8 @@ static int amba_kmi_probe(struct amba_device *dev, if (ret) return ret; - kmi = kzalloc(sizeof(*kmi), GFP_KERNEL); - io = kzalloc(sizeof(*io), GFP_KERNEL); + kmi = kzalloc_obj(*kmi, GFP_KERNEL); + io = kzalloc_obj(*io, GFP_KERNEL); if (!kmi || !io) { ret = -ENOMEM; goto out; diff --git a/drivers/input/serio/ams_delta_serio.c b/drivers/input/serio/ams_delta_serio.c index 81b3a053df81..206e6dc3f502 100644 --- a/drivers/input/serio/ams_delta_serio.c +++ b/drivers/input/serio/ams_delta_serio.c @@ -150,7 +150,7 @@ static int ams_delta_serio_init(struct platform_device *pdev) return err; } - serio = kzalloc(sizeof(*serio), GFP_KERNEL); + serio = kzalloc_obj(*serio, GFP_KERNEL); if (!serio) return -ENOMEM; diff --git a/drivers/input/serio/apbps2.c b/drivers/input/serio/apbps2.c index a5fbb27088be..5828a4e9fe82 100644 --- a/drivers/input/serio/apbps2.c +++ b/drivers/input/serio/apbps2.c @@ -165,7 +165,7 @@ static int apbps2_of_probe(struct platform_device *ofdev) /* Set reload register to core freq in kHz/10 */ iowrite32be(freq_hz / 10000, &priv->regs->reload); - priv->io = kzalloc(sizeof(*priv->io), GFP_KERNEL); + priv->io = kzalloc_obj(*priv->io, GFP_KERNEL); if (!priv->io) return -ENOMEM; diff --git a/drivers/input/serio/arc_ps2.c b/drivers/input/serio/arc_ps2.c index 29095d8804d2..bce8d6308f8d 100644 --- a/drivers/input/serio/arc_ps2.c +++ b/drivers/input/serio/arc_ps2.c @@ -155,7 +155,7 @@ static int arc_ps2_create_port(struct platform_device *pdev, struct arc_ps2_port *port = &arc_ps2->port[index]; struct serio *io; - io = kzalloc(sizeof(*io), GFP_KERNEL); + io = kzalloc_obj(*io, GFP_KERNEL); if (!io) return -ENOMEM; diff --git a/drivers/input/serio/ct82c710.c b/drivers/input/serio/ct82c710.c index 053a15988c45..3a7424bdf877 100644 --- a/drivers/input/serio/ct82c710.c +++ b/drivers/input/serio/ct82c710.c @@ -158,7 +158,7 @@ static int __init ct82c710_detect(void) static int ct82c710_probe(struct platform_device *dev) { - ct82c710_port = kzalloc(sizeof(*ct82c710_port), GFP_KERNEL); + ct82c710_port = kzalloc_obj(*ct82c710_port, GFP_KERNEL); if (!ct82c710_port) return -ENOMEM; diff --git a/drivers/input/serio/gscps2.c b/drivers/input/serio/gscps2.c index 9c6ff04c46cf..59c242f97fd3 100644 --- a/drivers/input/serio/gscps2.c +++ b/drivers/input/serio/gscps2.c @@ -350,8 +350,8 @@ static int __init gscps2_probe(struct parisc_device *dev) if (dev->id.sversion == 0x96) hpa += GSC_DINO_OFFSET; - ps2port = kzalloc(sizeof(*ps2port), GFP_KERNEL); - serio = kzalloc(sizeof(*serio), GFP_KERNEL); + ps2port = kzalloc_obj(*ps2port, GFP_KERNEL); + serio = kzalloc_obj(*serio, GFP_KERNEL); if (!ps2port || !serio) { ret = -ENOMEM; goto fail_nomem; diff --git a/drivers/input/serio/hil_mlc.c b/drivers/input/serio/hil_mlc.c index 3fedfc5abc73..f56252d6df5b 100644 --- a/drivers/input/serio/hil_mlc.c +++ b/drivers/input/serio/hil_mlc.c @@ -939,7 +939,7 @@ int hil_mlc_register(hil_mlc *mlc) for (i = 0; i < HIL_MLC_DEVMEM; i++) { struct serio *mlc_serio; hil_mlc_copy_di_scratch(mlc, i); - mlc_serio = kzalloc(sizeof(*mlc_serio), GFP_KERNEL); + mlc_serio = kzalloc_obj(*mlc_serio, GFP_KERNEL); mlc->serio[i] = mlc_serio; if (!mlc->serio[i]) { for (; i >= 0; i--) diff --git a/drivers/input/serio/hyperv-keyboard.c b/drivers/input/serio/hyperv-keyboard.c index 0ee7505427ac..7cbf726b47a7 100644 --- a/drivers/input/serio/hyperv-keyboard.c +++ b/drivers/input/serio/hyperv-keyboard.c @@ -316,8 +316,8 @@ static int hv_kbd_probe(struct hv_device *hv_dev, struct serio *hv_serio; int error; - kbd_dev = kzalloc(sizeof(*kbd_dev), GFP_KERNEL); - hv_serio = kzalloc(sizeof(*hv_serio), GFP_KERNEL); + kbd_dev = kzalloc_obj(*kbd_dev, GFP_KERNEL); + hv_serio = kzalloc_obj(*hv_serio, GFP_KERNEL); if (!kbd_dev || !hv_serio) { error = -ENOMEM; goto err_free_mem; diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c index c135254665b6..1a5a7f2f0214 100644 --- a/drivers/input/serio/i8042.c +++ b/drivers/input/serio/i8042.c @@ -1324,7 +1324,7 @@ static int i8042_create_kbd_port(void) struct serio *serio; struct i8042_port *port = &i8042_ports[I8042_KBD_PORT_NO]; - serio = kzalloc(sizeof(*serio), GFP_KERNEL); + serio = kzalloc_obj(*serio, GFP_KERNEL); if (!serio) return -ENOMEM; @@ -1354,7 +1354,7 @@ static int i8042_create_aux_port(int idx) int port_no = idx < 0 ? I8042_AUX_PORT_NO : I8042_MUX_PORT_NO + idx; struct i8042_port *port = &i8042_ports[port_no]; - serio = kzalloc(sizeof(*serio), GFP_KERNEL); + serio = kzalloc_obj(*serio, GFP_KERNEL); if (!serio) return -ENOMEM; diff --git a/drivers/input/serio/ioc3kbd.c b/drivers/input/serio/ioc3kbd.c index d2c7ffb9a946..650758115bf0 100644 --- a/drivers/input/serio/ioc3kbd.c +++ b/drivers/input/serio/ioc3kbd.c @@ -139,11 +139,11 @@ static int ioc3kbd_probe(struct platform_device *pdev) if (!d) return -ENOMEM; - sk = kzalloc(sizeof(*sk), GFP_KERNEL); + sk = kzalloc_obj(*sk, GFP_KERNEL); if (!sk) return -ENOMEM; - sa = kzalloc(sizeof(*sa), GFP_KERNEL); + sa = kzalloc_obj(*sa, GFP_KERNEL); if (!sa) { kfree(sk); return -ENOMEM; diff --git a/drivers/input/serio/maceps2.c b/drivers/input/serio/maceps2.c index 3d28a5cddd61..dda52b7d2c1d 100644 --- a/drivers/input/serio/maceps2.c +++ b/drivers/input/serio/maceps2.c @@ -117,7 +117,7 @@ static struct serio *maceps2_allocate_port(int idx) { struct serio *serio; - serio = kzalloc(sizeof(*serio), GFP_KERNEL); + serio = kzalloc_obj(*serio, GFP_KERNEL); if (serio) { serio->id.type = SERIO_8042; serio->write = maceps2_write; diff --git a/drivers/input/serio/olpc_apsp.c b/drivers/input/serio/olpc_apsp.c index c07fb8a1799d..14c235b0b4e4 100644 --- a/drivers/input/serio/olpc_apsp.c +++ b/drivers/input/serio/olpc_apsp.c @@ -188,7 +188,7 @@ static int olpc_apsp_probe(struct platform_device *pdev) return priv->irq; /* KEYBOARD */ - kb_serio = kzalloc(sizeof(*kb_serio), GFP_KERNEL); + kb_serio = kzalloc_obj(*kb_serio, GFP_KERNEL); if (!kb_serio) return -ENOMEM; kb_serio->id.type = SERIO_8042_XL; @@ -203,7 +203,7 @@ static int olpc_apsp_probe(struct platform_device *pdev) serio_register_port(kb_serio); /* TOUCHPAD */ - pad_serio = kzalloc(sizeof(*pad_serio), GFP_KERNEL); + pad_serio = kzalloc_obj(*pad_serio, GFP_KERNEL); if (!pad_serio) { error = -ENOMEM; goto err_pad; diff --git a/drivers/input/serio/parkbd.c b/drivers/input/serio/parkbd.c index 22fe55490572..a4b830b499f6 100644 --- a/drivers/input/serio/parkbd.c +++ b/drivers/input/serio/parkbd.c @@ -165,7 +165,7 @@ static struct serio *parkbd_allocate_serio(void) { struct serio *serio; - serio = kzalloc(sizeof(*serio), GFP_KERNEL); + serio = kzalloc_obj(*serio, GFP_KERNEL); if (serio) { serio->id.type = parkbd_mode; serio->write = parkbd_write; diff --git a/drivers/input/serio/pcips2.c b/drivers/input/serio/pcips2.c index 6b9abb2e18c9..9e5d022fa502 100644 --- a/drivers/input/serio/pcips2.c +++ b/drivers/input/serio/pcips2.c @@ -137,8 +137,8 @@ static int pcips2_probe(struct pci_dev *dev, const struct pci_device_id *id) if (ret) goto disable; - ps2if = kzalloc(sizeof(*ps2if), GFP_KERNEL); - serio = kzalloc(sizeof(*serio), GFP_KERNEL); + ps2if = kzalloc_obj(*ps2if, GFP_KERNEL); + serio = kzalloc_obj(*serio, GFP_KERNEL); if (!ps2if || !serio) { ret = -ENOMEM; goto release; diff --git a/drivers/input/serio/ps2-gpio.c b/drivers/input/serio/ps2-gpio.c index 46fb7667b244..a52ce59952a9 100644 --- a/drivers/input/serio/ps2-gpio.c +++ b/drivers/input/serio/ps2-gpio.c @@ -405,7 +405,7 @@ static int ps2_gpio_probe(struct platform_device *pdev) int error; drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); - serio = kzalloc(sizeof(*serio), GFP_KERNEL); + serio = kzalloc_obj(*serio, GFP_KERNEL); if (!drvdata || !serio) { error = -ENOMEM; goto err_free_serio; diff --git a/drivers/input/serio/ps2mult.c b/drivers/input/serio/ps2mult.c index b96cee52fc52..e0462ac3aa1d 100644 --- a/drivers/input/serio/ps2mult.c +++ b/drivers/input/serio/ps2mult.c @@ -122,7 +122,7 @@ static int ps2mult_create_port(struct ps2mult *psm, int i) struct serio *mx_serio = psm->mx_serio; struct serio *serio; - serio = kzalloc(sizeof(*serio), GFP_KERNEL); + serio = kzalloc_obj(*serio, GFP_KERNEL); if (!serio) return -ENOMEM; @@ -160,7 +160,7 @@ static int ps2mult_connect(struct serio *serio, struct serio_driver *drv) if (!serio->write) return -EINVAL; - psm = kzalloc(sizeof(*psm), GFP_KERNEL); + psm = kzalloc_obj(*psm, GFP_KERNEL); if (!psm) return -ENOMEM; diff --git a/drivers/input/serio/q40kbd.c b/drivers/input/serio/q40kbd.c index ae55c4de092f..55c254fbdb24 100644 --- a/drivers/input/serio/q40kbd.c +++ b/drivers/input/serio/q40kbd.c @@ -102,8 +102,8 @@ static int q40kbd_probe(struct platform_device *pdev) struct serio *port; int error; - q40kbd = kzalloc(sizeof(*q40kbd), GFP_KERNEL); - port = kzalloc(sizeof(*port), GFP_KERNEL); + q40kbd = kzalloc_obj(*q40kbd, GFP_KERNEL); + port = kzalloc_obj(*port, GFP_KERNEL); if (!q40kbd || !port) { error = -ENOMEM; goto err_free_mem; diff --git a/drivers/input/serio/rpckbd.c b/drivers/input/serio/rpckbd.c index c65c552b0c45..c097716da53e 100644 --- a/drivers/input/serio/rpckbd.c +++ b/drivers/input/serio/rpckbd.c @@ -108,8 +108,8 @@ static int rpckbd_probe(struct platform_device *dev) if (tx_irq < 0) return tx_irq; - serio = kzalloc(sizeof(*serio), GFP_KERNEL); - rpckbd = kzalloc(sizeof(*rpckbd), GFP_KERNEL); + serio = kzalloc_obj(*serio, GFP_KERNEL); + rpckbd = kzalloc_obj(*rpckbd, GFP_KERNEL); if (!serio || !rpckbd) { kfree(rpckbd); kfree(serio); diff --git a/drivers/input/serio/sa1111ps2.c b/drivers/input/serio/sa1111ps2.c index 375c6f5f905c..32752d898797 100644 --- a/drivers/input/serio/sa1111ps2.c +++ b/drivers/input/serio/sa1111ps2.c @@ -254,8 +254,8 @@ static int ps2_probe(struct sa1111_dev *dev) struct serio *serio; int ret; - ps2if = kzalloc(sizeof(*ps2if), GFP_KERNEL); - serio = kzalloc(sizeof(*serio), GFP_KERNEL); + ps2if = kzalloc_obj(*ps2if, GFP_KERNEL); + serio = kzalloc_obj(*serio, GFP_KERNEL); if (!ps2if || !serio) { ret = -ENOMEM; goto free; diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c index 2b5ddc5dac19..54dd26249b02 100644 --- a/drivers/input/serio/serio.c +++ b/drivers/input/serio/serio.c @@ -244,7 +244,7 @@ static int serio_queue_event(void *object, struct module *owner, } } - event = kmalloc(sizeof(*event), GFP_ATOMIC); + event = kmalloc_obj(*event, GFP_ATOMIC); if (!event) { pr_err("Not enough memory to queue event %d\n", event_type); return -ENOMEM; diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c index 4d6395088986..70df54435a94 100644 --- a/drivers/input/serio/serio_raw.c +++ b/drivers/input/serio/serio_raw.c @@ -270,7 +270,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv) struct serio_raw *serio_raw; int err; - serio_raw = kzalloc(sizeof(*serio_raw), GFP_KERNEL); + serio_raw = kzalloc_obj(*serio_raw, GFP_KERNEL); if (!serio_raw) { dev_dbg(&serio->dev, "can't allocate memory for a device\n"); return -ENOMEM; diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c index 74ac88796187..46087c02c340 100644 --- a/drivers/input/serio/serport.c +++ b/drivers/input/serio/serport.c @@ -78,7 +78,7 @@ static int serport_ldisc_open(struct tty_struct *tty) if (!capable(CAP_SYS_ADMIN)) return -EPERM; - serport = kzalloc(sizeof(*serport), GFP_KERNEL); + serport = kzalloc_obj(*serport, GFP_KERNEL); if (!serport) return -ENOMEM; @@ -159,7 +159,7 @@ static ssize_t serport_ldisc_read(struct tty_struct * tty, struct file * file, if (test_and_set_bit(SERPORT_BUSY, &serport->flags)) return -EBUSY; - serport->serio = serio = kzalloc(sizeof(*serio), GFP_KERNEL); + serport->serio = serio = kzalloc_obj(*serio, GFP_KERNEL); if (!serio) return -ENOMEM; diff --git a/drivers/input/serio/sun4i-ps2.c b/drivers/input/serio/sun4i-ps2.c index 524929ce1cae..5b46c66b2100 100644 --- a/drivers/input/serio/sun4i-ps2.c +++ b/drivers/input/serio/sun4i-ps2.c @@ -209,8 +209,8 @@ static int sun4i_ps2_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int error; - drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL); - serio = kzalloc(sizeof(*serio), GFP_KERNEL); + drvdata = kzalloc_obj(*drvdata, GFP_KERNEL); + serio = kzalloc_obj(*serio, GFP_KERNEL); if (!drvdata || !serio) { error = -ENOMEM; goto err_free_mem; diff --git a/drivers/input/serio/userio.c b/drivers/input/serio/userio.c index 7f627b08055e..3bdb17b4dd25 100644 --- a/drivers/input/serio/userio.c +++ b/drivers/input/serio/userio.c @@ -73,7 +73,7 @@ static int userio_device_write(struct serio *id, unsigned char val) static int userio_char_open(struct inode *inode, struct file *file) { struct userio_device *userio __free(kfree) = - kzalloc(sizeof(*userio), GFP_KERNEL); + kzalloc_obj(*userio, GFP_KERNEL); if (!userio) return -ENOMEM; @@ -81,7 +81,7 @@ static int userio_char_open(struct inode *inode, struct file *file) spin_lock_init(&userio->buf_lock); init_waitqueue_head(&userio->waitq); - userio->serio = kzalloc(sizeof(*userio->serio), GFP_KERNEL); + userio->serio = kzalloc_obj(*userio->serio, GFP_KERNEL); if (!userio->serio) return -ENOMEM; diff --git a/drivers/input/serio/xilinx_ps2.c b/drivers/input/serio/xilinx_ps2.c index 01433f0b48f1..0c9ddc532c31 100644 --- a/drivers/input/serio/xilinx_ps2.c +++ b/drivers/input/serio/xilinx_ps2.c @@ -247,8 +247,8 @@ static int xps2_of_probe(struct platform_device *ofdev) return -ENODEV; } - drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL); - serio = kzalloc(sizeof(*serio), GFP_KERNEL); + drvdata = kzalloc_obj(*drvdata, GFP_KERNEL); + serio = kzalloc_obj(*serio, GFP_KERNEL); if (!drvdata || !serio) { error = -ENOMEM; goto failed1; |
