summaryrefslogtreecommitdiff
path: root/arch/um
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-20 23:49:23 -0800
committerKees Cook <kees@kernel.org>2026-02-21 01:02:28 -0800
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /arch/um
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (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 'arch/um')
-rw-r--r--arch/um/drivers/chan_kern.c2
-rw-r--r--arch/um/drivers/hostaudio_kern.c4
-rw-r--r--arch/um/drivers/line.c2
-rw-r--r--arch/um/drivers/mconsole_kern.c2
-rw-r--r--arch/um/drivers/port_kern.c6
-rw-r--r--arch/um/drivers/ubd_kern.c12
-rw-r--r--arch/um/drivers/vector_kern.c18
-rw-r--r--arch/um/drivers/vector_transports.c5
-rw-r--r--arch/um/drivers/vfio_kern.c9
-rw-r--r--arch/um/drivers/virtio_pcidev.c2
-rw-r--r--arch/um/drivers/virtio_uml.c4
-rw-r--r--arch/um/drivers/xterm_kern.c2
-rw-r--r--arch/um/kernel/irq.c2
13 files changed, 30 insertions, 40 deletions
diff --git a/arch/um/drivers/chan_kern.c b/arch/um/drivers/chan_kern.c
index 26442db7d608..db2bb032be30 100644
--- a/arch/um/drivers/chan_kern.c
+++ b/arch/um/drivers/chan_kern.c
@@ -504,7 +504,7 @@ static struct chan *parse_chan(struct line *line, char *str, int device,
return NULL;
}
- chan = kmalloc(sizeof(*chan), GFP_ATOMIC);
+ chan = kmalloc_obj(*chan, GFP_ATOMIC);
if (chan == NULL) {
*error_out = "Memory allocation failed";
return NULL;
diff --git a/arch/um/drivers/hostaudio_kern.c b/arch/um/drivers/hostaudio_kern.c
index 0ac149de1ac0..6983a35a9ead 100644
--- a/arch/um/drivers/hostaudio_kern.c
+++ b/arch/um/drivers/hostaudio_kern.c
@@ -186,7 +186,7 @@ static int hostaudio_open(struct inode *inode, struct file *file)
kernel_param_unlock(THIS_MODULE);
#endif
- state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL);
+ state = kmalloc_obj(struct hostaudio_state, GFP_KERNEL);
if (state == NULL)
return -ENOMEM;
@@ -247,7 +247,7 @@ static int hostmixer_open_mixdev(struct inode *inode, struct file *file)
printk(KERN_DEBUG "hostmixer: open called (host: %s)\n", mixer);
#endif
- state = kmalloc(sizeof(struct hostmixer_state), GFP_KERNEL);
+ state = kmalloc_obj(struct hostmixer_state, GFP_KERNEL);
if (state == NULL)
return -ENOMEM;
diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
index 43d8959cc746..62545319d0eb 100644
--- a/arch/um/drivers/line.c
+++ b/arch/um/drivers/line.c
@@ -672,7 +672,7 @@ void register_winch_irq(int fd, int tty_fd, int pid, struct tty_port *port,
{
struct winch *winch;
- winch = kmalloc(sizeof(*winch), GFP_KERNEL);
+ winch = kmalloc_obj(*winch, GFP_KERNEL);
if (winch == NULL) {
printk(KERN_ERR "register_winch_irq - kmalloc failed\n");
goto cleanup;
diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
index ff4bda95b9c7..e2a9e8879f58 100644
--- a/arch/um/drivers/mconsole_kern.c
+++ b/arch/um/drivers/mconsole_kern.c
@@ -87,7 +87,7 @@ static irqreturn_t mconsole_interrupt(int irq, void *dev_id)
if (req.cmd->context == MCONSOLE_INTR)
(*req.cmd->handler)(&req);
else {
- new = kmalloc(sizeof(*new), GFP_NOWAIT);
+ new = kmalloc_obj(*new, GFP_NOWAIT);
if (new == NULL)
mconsole_reply(&req, "Out of memory", 1, 0);
else {
diff --git a/arch/um/drivers/port_kern.c b/arch/um/drivers/port_kern.c
index a4508470df78..c51d6ca4de70 100644
--- a/arch/um/drivers/port_kern.c
+++ b/arch/um/drivers/port_kern.c
@@ -88,7 +88,7 @@ static int port_accept(struct port_list *port)
goto out;
}
- conn = kmalloc(sizeof(*conn), GFP_ATOMIC);
+ conn = kmalloc_obj(*conn, GFP_ATOMIC);
if (conn == NULL) {
printk(KERN_ERR "port_accept : failed to allocate "
"connection\n");
@@ -170,7 +170,7 @@ void *port_data(int port_num)
if (port->port == port_num)
goto found;
}
- port = kmalloc(sizeof(struct port_list), GFP_KERNEL);
+ port = kmalloc_obj(struct port_list, GFP_KERNEL);
if (port == NULL) {
printk(KERN_ERR "Allocation of port list failed\n");
goto out;
@@ -202,7 +202,7 @@ void *port_data(int port_num)
list_add(&port->list, &ports);
found:
- dev = kmalloc(sizeof(struct port_dev), GFP_KERNEL);
+ dev = kmalloc_obj(struct port_dev, GFP_KERNEL);
if (dev == NULL) {
printk(KERN_ERR "Allocation of port device entry failed\n");
goto out;
diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index 37455e74d314..42f392e6add3 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -1069,20 +1069,16 @@ static int __init ubd_init(void)
if (register_blkdev(UBD_MAJOR, "ubd"))
return -1;
- irq_req_buffer = kmalloc_array(UBD_REQ_BUFFER_SIZE,
- sizeof(struct io_thread_req *),
- GFP_KERNEL
- );
+ irq_req_buffer = kmalloc_objs(struct io_thread_req *,
+ UBD_REQ_BUFFER_SIZE, GFP_KERNEL);
irq_remainder = 0;
if (irq_req_buffer == NULL) {
printk(KERN_ERR "Failed to initialize ubd buffering\n");
return -ENOMEM;
}
- io_req_buffer = kmalloc_array(UBD_REQ_BUFFER_SIZE,
- sizeof(struct io_thread_req *),
- GFP_KERNEL
- );
+ io_req_buffer = kmalloc_objs(struct io_thread_req *,
+ UBD_REQ_BUFFER_SIZE, GFP_KERNEL);
io_remainder = 0;
diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c
index 28cfe1c700f0..8882ad7c983a 100644
--- a/arch/um/drivers/vector_kern.c
+++ b/arch/um/drivers/vector_kern.c
@@ -515,7 +515,7 @@ static struct vector_queue *create_queue(
struct iovec *iov;
struct mmsghdr *mmsg_vector;
- result = kmalloc(sizeof(struct vector_queue), GFP_KERNEL);
+ result = kmalloc_obj(struct vector_queue, GFP_KERNEL);
if (result == NULL)
return NULL;
result->max_depth = max_size;
@@ -544,15 +544,11 @@ static struct vector_queue *create_queue(
result->max_iov_frags = num_extra_frags;
for (i = 0; i < max_size; i++) {
if (vp->header_size > 0)
- iov = kmalloc_array(3 + num_extra_frags,
- sizeof(struct iovec),
- GFP_KERNEL
- );
+ iov = kmalloc_objs(struct iovec, 3 + num_extra_frags,
+ GFP_KERNEL);
else
- iov = kmalloc_array(2 + num_extra_frags,
- sizeof(struct iovec),
- GFP_KERNEL
- );
+ iov = kmalloc_objs(struct iovec, 2 + num_extra_frags,
+ GFP_KERNEL);
if (iov == NULL)
goto out_fail;
mmsg_vector->msg_hdr.msg_iov = iov;
@@ -1385,7 +1381,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
kfree(vp->bpf->filter);
vp->bpf->filter = NULL;
} else {
- vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_ATOMIC);
+ vp->bpf = kmalloc_obj(struct sock_fprog, GFP_ATOMIC);
if (vp->bpf == NULL) {
netdev_err(dev, "failed to allocate memory for firmware\n");
goto flash_fail;
@@ -1587,7 +1583,7 @@ static void vector_eth_configure(
struct vector_private *vp;
int err;
- device = kzalloc(sizeof(*device), GFP_KERNEL);
+ device = kzalloc_obj(*device, GFP_KERNEL);
if (device == NULL) {
pr_err("Failed to allocate struct vector_device for vec%d\n", n);
return;
diff --git a/arch/um/drivers/vector_transports.c b/arch/um/drivers/vector_transports.c
index 0794d23f07cb..da5d2083ed49 100644
--- a/arch/um/drivers/vector_transports.c
+++ b/arch/um/drivers/vector_transports.c
@@ -245,7 +245,7 @@ static int build_gre_transport_data(struct vector_private *vp)
int temp_rx;
int temp_tx;
- vp->transport_data = kmalloc(sizeof(struct uml_gre_data), GFP_KERNEL);
+ vp->transport_data = kmalloc_obj(struct uml_gre_data, GFP_KERNEL);
if (vp->transport_data == NULL)
return -ENOMEM;
td = vp->transport_data;
@@ -307,8 +307,7 @@ static int build_l2tpv3_transport_data(struct vector_private *vp)
unsigned long temp_rx;
unsigned long temp_tx;
- vp->transport_data = kmalloc(
- sizeof(struct uml_l2tpv3_data), GFP_KERNEL);
+ vp->transport_data = kmalloc_obj(struct uml_l2tpv3_data, GFP_KERNEL);
if (vp->transport_data == NULL)
return -ENOMEM;
diff --git a/arch/um/drivers/vfio_kern.c b/arch/um/drivers/vfio_kern.c
index 915812a79bfc..5f349be2fce7 100644
--- a/arch/um/drivers/vfio_kern.c
+++ b/arch/um/drivers/vfio_kern.c
@@ -107,7 +107,7 @@ static int uml_vfio_open_group(int group_id)
}
}
- group = kzalloc(sizeof(*group), GFP_KERNEL);
+ group = kzalloc_obj(*group, GFP_KERNEL);
if (!group)
return -ENOMEM;
@@ -514,9 +514,8 @@ static void uml_vfio_open_device(struct uml_vfio_device *dev)
goto teardown_udev;
}
- dev->intr_ctx = kmalloc_array(dev->udev.irq_count,
- sizeof(struct uml_vfio_intr_ctx),
- GFP_KERNEL);
+ dev->intr_ctx = kmalloc_objs(struct uml_vfio_intr_ctx,
+ dev->udev.irq_count, GFP_KERNEL);
if (!dev->intr_ctx) {
pr_err("Failed to allocate interrupt context (%s)\n",
dev->name);
@@ -600,7 +599,7 @@ static struct uml_vfio_device *uml_vfio_add_device(const char *device)
if (uml_vfio_find_device(device))
return ERR_PTR(-EEXIST);
- dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ dev = kzalloc_obj(*dev, GFP_KERNEL);
if (!dev)
return ERR_PTR(-ENOMEM);
diff --git a/arch/um/drivers/virtio_pcidev.c b/arch/um/drivers/virtio_pcidev.c
index f9b4b6f7582c..5db9a4461766 100644
--- a/arch/um/drivers/virtio_pcidev.c
+++ b/arch/um/drivers/virtio_pcidev.c
@@ -537,7 +537,7 @@ static int virtio_pcidev_virtio_probe(struct virtio_device *vdev)
struct virtio_pcidev_device *dev;
int err;
- dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ dev = kzalloc_obj(*dev, GFP_KERNEL);
if (!dev)
return -ENOMEM;
diff --git a/arch/um/drivers/virtio_uml.c b/arch/um/drivers/virtio_uml.c
index c24da0cf1627..ac269e6148fc 100644
--- a/arch/um/drivers/virtio_uml.c
+++ b/arch/um/drivers/virtio_uml.c
@@ -965,7 +965,7 @@ static struct virtqueue *vu_setup_vq(struct virtio_device *vdev,
int num = MAX_SUPPORTED_QUEUE_SIZE;
int rc;
- info = kzalloc(sizeof(*info), GFP_KERNEL);
+ info = kzalloc_obj(*info, GFP_KERNEL);
if (!info) {
rc = -ENOMEM;
goto error_kzalloc;
@@ -1217,7 +1217,7 @@ static int virtio_uml_probe(struct platform_device *pdev)
return PTR_ERR(pdata);
}
- vu_dev = kzalloc(sizeof(*vu_dev), GFP_KERNEL);
+ vu_dev = kzalloc_obj(*vu_dev, GFP_KERNEL);
if (!vu_dev)
return -ENOMEM;
diff --git a/arch/um/drivers/xterm_kern.c b/arch/um/drivers/xterm_kern.c
index 3971252cb1a6..7740d9a3b090 100644
--- a/arch/um/drivers/xterm_kern.c
+++ b/arch/um/drivers/xterm_kern.c
@@ -45,7 +45,7 @@ int xterm_fd(int socket, int *pid_out)
struct xterm_wait *data;
int err, ret;
- data = kmalloc(sizeof(*data), GFP_KERNEL);
+ data = kmalloc_obj(*data, GFP_KERNEL);
if (data == NULL) {
printk(KERN_ERR "xterm_fd : failed to allocate xterm_wait\n");
return -ENOMEM;
diff --git a/arch/um/kernel/irq.c b/arch/um/kernel/irq.c
index f4b13f15a9c1..5929d498b65f 100644
--- a/arch/um/kernel/irq.c
+++ b/arch/um/kernel/irq.c
@@ -326,7 +326,7 @@ already:
/* don't restore interrupts */
raw_spin_unlock(&irq_lock);
- new = kzalloc(sizeof(*irq_entry), GFP_ATOMIC);
+ new = kzalloc_obj(*irq_entry, GFP_ATOMIC);
if (!new) {
local_irq_restore(flags);
return -ENOMEM;