From 69050f8d6d075dc01af7a5f2f550a8067510366f Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 20 Feb 2026 23:49:23 -0800 Subject: 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 --- drivers/ps3/ps3-lpm.c | 2 +- drivers/ps3/ps3-vuart.c | 5 ++--- drivers/ps3/ps3av.c | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'drivers/ps3') diff --git a/drivers/ps3/ps3-lpm.c b/drivers/ps3/ps3-lpm.c index 188ae2572674..8f1ee4c748bf 100644 --- a/drivers/ps3/ps3-lpm.c +++ b/drivers/ps3/ps3-lpm.c @@ -1181,7 +1181,7 @@ static int ps3_lpm_probe(struct ps3_system_bus_device *dev) return -EBUSY; } - lpm_priv = kzalloc(sizeof(*lpm_priv), GFP_KERNEL); + lpm_priv = kzalloc_obj(*lpm_priv, GFP_KERNEL); if (!lpm_priv) return -ENOMEM; diff --git a/drivers/ps3/ps3-vuart.c b/drivers/ps3/ps3-vuart.c index 5cb92535a4a1..3493a9ef05ce 100644 --- a/drivers/ps3/ps3-vuart.c +++ b/drivers/ps3/ps3-vuart.c @@ -914,7 +914,7 @@ static int ps3_vuart_bus_interrupt_get(void) BUG_ON(vuart_bus_priv.bmp); - vuart_bus_priv.bmp = kzalloc(sizeof(struct ports_bmp), GFP_KERNEL); + vuart_bus_priv.bmp = kzalloc_obj(struct ports_bmp, GFP_KERNEL); if (!vuart_bus_priv.bmp) { result = -ENOMEM; @@ -1015,8 +1015,7 @@ static int ps3_vuart_probe(struct ps3_system_bus_device *dev) /* Setup dev->driver_priv. */ - dev->driver_priv = kzalloc(sizeof(struct ps3_vuart_port_priv), - GFP_KERNEL); + dev->driver_priv = kzalloc_obj(struct ps3_vuart_port_priv, GFP_KERNEL); if (!dev->driver_priv) { result = -ENOMEM; diff --git a/drivers/ps3/ps3av.c b/drivers/ps3/ps3av.c index f6c9e56bdba7..19f2c5b4f8f3 100644 --- a/drivers/ps3/ps3av.c +++ b/drivers/ps3/ps3av.c @@ -934,7 +934,7 @@ static int ps3av_probe(struct ps3_system_bus_device *dev) return -EBUSY; } - ps3av = kzalloc(sizeof(*ps3av), GFP_KERNEL); + ps3av = kzalloc_obj(*ps3av, GFP_KERNEL); if (!ps3av) return -ENOMEM; -- cgit v1.2.3