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/thunderbolt | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.zip | |
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/thunderbolt')
| -rw-r--r-- | drivers/thunderbolt/ctl.c | 6 | ||||
| -rw-r--r-- | drivers/thunderbolt/debugfs.c | 2 | ||||
| -rw-r--r-- | drivers/thunderbolt/dma_port.c | 2 | ||||
| -rw-r--r-- | drivers/thunderbolt/dma_test.c | 4 | ||||
| -rw-r--r-- | drivers/thunderbolt/domain.c | 4 | ||||
| -rw-r--r-- | drivers/thunderbolt/icm.c | 6 | ||||
| -rw-r--r-- | drivers/thunderbolt/nhi.c | 2 | ||||
| -rw-r--r-- | drivers/thunderbolt/nvm.c | 2 | ||||
| -rw-r--r-- | drivers/thunderbolt/path.c | 8 | ||||
| -rw-r--r-- | drivers/thunderbolt/property.c | 6 | ||||
| -rw-r--r-- | drivers/thunderbolt/retimer.c | 2 | ||||
| -rw-r--r-- | drivers/thunderbolt/switch.c | 10 | ||||
| -rw-r--r-- | drivers/thunderbolt/tb.c | 4 | ||||
| -rw-r--r-- | drivers/thunderbolt/tunnel.c | 4 | ||||
| -rw-r--r-- | drivers/thunderbolt/usb4_port.c | 2 | ||||
| -rw-r--r-- | drivers/thunderbolt/xdomain.c | 6 |
16 files changed, 35 insertions, 35 deletions
diff --git a/drivers/thunderbolt/ctl.c b/drivers/thunderbolt/ctl.c index d7a535671404..3108727c4ef2 100644 --- a/drivers/thunderbolt/ctl.c +++ b/drivers/thunderbolt/ctl.c @@ -89,7 +89,7 @@ struct tb_cfg_request *tb_cfg_request_alloc(void) { struct tb_cfg_request *req; - req = kzalloc(sizeof(*req), GFP_KERNEL); + req = kzalloc_obj(*req, GFP_KERNEL); if (!req) return NULL; @@ -333,7 +333,7 @@ static void tb_ctl_pkg_free(struct ctl_pkg *pkg) static struct ctl_pkg *tb_ctl_pkg_alloc(struct tb_ctl *ctl) { - struct ctl_pkg *pkg = kzalloc(sizeof(*pkg), GFP_KERNEL); + struct ctl_pkg *pkg = kzalloc_obj(*pkg, GFP_KERNEL); if (!pkg) return NULL; pkg->ctl = ctl; @@ -654,7 +654,7 @@ struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, int index, int timeout_msec, event_cb cb, void *cb_data) { int i; - struct tb_ctl *ctl = kzalloc(sizeof(*ctl), GFP_KERNEL); + struct tb_ctl *ctl = kzalloc_obj(*ctl, GFP_KERNEL); if (!ctl) return NULL; diff --git a/drivers/thunderbolt/debugfs.c b/drivers/thunderbolt/debugfs.c index 45266ec72f88..7e2a59dddbbd 100644 --- a/drivers/thunderbolt/debugfs.c +++ b/drivers/thunderbolt/debugfs.c @@ -1657,7 +1657,7 @@ static struct tb_margining *margining_alloc(struct tb_port *port, return NULL; } - margining = kzalloc(sizeof(*margining), GFP_KERNEL); + margining = kzalloc_obj(*margining, GFP_KERNEL); if (!margining) return NULL; diff --git a/drivers/thunderbolt/dma_port.c b/drivers/thunderbolt/dma_port.c index dc8ea188a114..ddbf5f9971fb 100644 --- a/drivers/thunderbolt/dma_port.c +++ b/drivers/thunderbolt/dma_port.c @@ -209,7 +209,7 @@ struct tb_dma_port *dma_port_alloc(struct tb_switch *sw) if (port < 0) return NULL; - dma = kzalloc(sizeof(*dma), GFP_KERNEL); + dma = kzalloc_obj(*dma, GFP_KERNEL); if (!dma) return NULL; diff --git a/drivers/thunderbolt/dma_test.c b/drivers/thunderbolt/dma_test.c index 9e47a63f28e7..8298f25ef6bd 100644 --- a/drivers/thunderbolt/dma_test.c +++ b/drivers/thunderbolt/dma_test.c @@ -267,7 +267,7 @@ static int dma_test_submit_rx(struct dma_test *dt, size_t npackets) struct dma_test_frame *tf; dma_addr_t dma_addr; - tf = kzalloc(sizeof(*tf), GFP_KERNEL); + tf = kzalloc_obj(*tf, GFP_KERNEL); if (!tf) return -ENOMEM; @@ -318,7 +318,7 @@ static int dma_test_submit_tx(struct dma_test *dt, size_t npackets) struct dma_test_frame *tf; dma_addr_t dma_addr; - tf = kzalloc(sizeof(*tf), GFP_KERNEL); + tf = kzalloc_obj(*tf, GFP_KERNEL); if (!tf) return -ENOMEM; diff --git a/drivers/thunderbolt/domain.c b/drivers/thunderbolt/domain.c index 3ced37b4a869..1e7268e26fc2 100644 --- a/drivers/thunderbolt/domain.c +++ b/drivers/thunderbolt/domain.c @@ -126,7 +126,7 @@ static ssize_t boot_acl_show(struct device *dev, struct device_attribute *attr, ssize_t ret; int i; - uuids = kcalloc(tb->nboot_acl, sizeof(uuid_t), GFP_KERNEL); + uuids = kzalloc_objs(uuid_t, tb->nboot_acl, GFP_KERNEL); if (!uuids) return -ENOMEM; @@ -181,7 +181,7 @@ static ssize_t boot_acl_store(struct device *dev, struct device_attribute *attr, if (!str) return -ENOMEM; - acl = kcalloc(tb->nboot_acl, sizeof(uuid_t), GFP_KERNEL); + acl = kzalloc_objs(uuid_t, tb->nboot_acl, GFP_KERNEL); if (!acl) { ret = -ENOMEM; goto err_free_str; diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c index d339ba835376..fda1471c7ef8 100644 --- a/drivers/thunderbolt/icm.c +++ b/drivers/thunderbolt/icm.c @@ -427,7 +427,7 @@ static int icm_fr_get_route(struct tb *tb, u8 link, u8 depth, u64 *route) int ret, index; u8 i; - switches = kcalloc(npackets, sizeof(*switches), GFP_KERNEL); + switches = kzalloc_objs(*switches, npackets, GFP_KERNEL); if (!switches) return -ENOMEM; @@ -1769,7 +1769,7 @@ static void icm_handle_event(struct tb *tb, enum tb_cfg_pkg_type type, { struct icm_notification *n; - n = kmalloc(sizeof(*n), GFP_KERNEL); + n = kmalloc_obj(*n, GFP_KERNEL); if (!n) return; @@ -2246,7 +2246,7 @@ static int icm_usb4_switch_nvm_authenticate(struct tb *tb, u64 route) struct tb_cfg_request *req; int ret; - auth = kzalloc(sizeof(*auth), GFP_KERNEL); + auth = kzalloc_obj(*auth, GFP_KERNEL); if (!auth) return -ENOMEM; diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c index 6d0c9d37c55d..6431c411fb17 100644 --- a/drivers/thunderbolt/nhi.c +++ b/drivers/thunderbolt/nhi.c @@ -587,7 +587,7 @@ static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size, dev_dbg(&nhi->pdev->dev, "allocating %s ring %d of size %d\n", transmit ? "TX" : "RX", hop, size); - ring = kzalloc(sizeof(*ring), GFP_KERNEL); + ring = kzalloc_obj(*ring, GFP_KERNEL); if (!ring) return NULL; diff --git a/drivers/thunderbolt/nvm.c b/drivers/thunderbolt/nvm.c index 6901058b7ac0..ac9c5504cfc1 100644 --- a/drivers/thunderbolt/nvm.c +++ b/drivers/thunderbolt/nvm.c @@ -330,7 +330,7 @@ struct tb_nvm *tb_nvm_alloc(struct device *dev) return ERR_PTR(-EOPNOTSUPP); } - nvm = kzalloc(sizeof(*nvm), GFP_KERNEL); + nvm = kzalloc_obj(*nvm, GFP_KERNEL); if (!nvm) return ERR_PTR(-ENOMEM); diff --git a/drivers/thunderbolt/path.c b/drivers/thunderbolt/path.c index 50659bd55d7b..88311c6e599b 100644 --- a/drivers/thunderbolt/path.c +++ b/drivers/thunderbolt/path.c @@ -150,7 +150,7 @@ struct tb_path *tb_path_discover(struct tb_port *src, int src_hopid, num_hops++; } - path = kzalloc(sizeof(*path), GFP_KERNEL); + path = kzalloc_obj(*path, GFP_KERNEL); if (!path) return NULL; @@ -160,7 +160,7 @@ struct tb_path *tb_path_discover(struct tb_port *src, int src_hopid, path->activated = true; path->alloc_hopid = alloc_hopid; - path->hops = kcalloc(num_hops, sizeof(*path->hops), GFP_KERNEL); + path->hops = kzalloc_objs(*path->hops, num_hops, GFP_KERNEL); if (!path->hops) { kfree(path); return NULL; @@ -245,7 +245,7 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid, size_t num_hops; int i, ret; - path = kzalloc(sizeof(*path), GFP_KERNEL); + path = kzalloc_obj(*path, GFP_KERNEL); if (!path) return NULL; @@ -267,7 +267,7 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid, /* Each hop takes two ports */ num_hops = i / 2; - path->hops = kcalloc(num_hops, sizeof(*path->hops), GFP_KERNEL); + path->hops = kzalloc_objs(*path->hops, num_hops, GFP_KERNEL); if (!path->hops) { kfree(path); return NULL; diff --git a/drivers/thunderbolt/property.c b/drivers/thunderbolt/property.c index 31aa0516932a..a274c02d71c0 100644 --- a/drivers/thunderbolt/property.c +++ b/drivers/thunderbolt/property.c @@ -81,7 +81,7 @@ tb_property_alloc(const char *key, enum tb_property_type type) { struct tb_property *property; - property = kzalloc(sizeof(*property), GFP_KERNEL); + property = kzalloc_obj(*property, GFP_KERNEL); if (!property) return NULL; @@ -166,7 +166,7 @@ static struct tb_property_dir *__tb_property_parse_dir(const u32 *block, unsigned int content_offset; struct tb_property_dir *dir; - dir = kzalloc(sizeof(*dir), GFP_KERNEL); + dir = kzalloc_obj(*dir, GFP_KERNEL); if (!dir) return NULL; @@ -247,7 +247,7 @@ struct tb_property_dir *tb_property_create_dir(const uuid_t *uuid) { struct tb_property_dir *dir; - dir = kzalloc(sizeof(*dir), GFP_KERNEL); + dir = kzalloc_obj(*dir, GFP_KERNEL); if (!dir) return NULL; diff --git a/drivers/thunderbolt/retimer.c b/drivers/thunderbolt/retimer.c index 13d64dbd2bc5..b95f5c19cca5 100644 --- a/drivers/thunderbolt/retimer.c +++ b/drivers/thunderbolt/retimer.c @@ -410,7 +410,7 @@ static int tb_retimer_add(struct tb_port *port, u8 index, u32 auth_status, } - rt = kzalloc(sizeof(*rt), GFP_KERNEL); + rt = kzalloc_obj(*rt, GFP_KERNEL); if (!rt) return -ENOMEM; diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index e2732c575bad..90d62141ecd8 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -69,7 +69,7 @@ static void nvm_set_auth_status(const struct tb_switch *sw, u32 status) st = __nvm_get_auth_status(sw); if (!st) { - st = kzalloc(sizeof(*st), GFP_KERNEL); + st = kzalloc_obj(*st, GFP_KERNEL); if (!st) goto unlock; @@ -2475,7 +2475,7 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, struct device *parent, if (upstream_port < 0) return ERR_PTR(upstream_port); - sw = kzalloc(sizeof(*sw), GFP_KERNEL); + sw = kzalloc_obj(*sw, GFP_KERNEL); if (!sw) return ERR_PTR(-ENOMEM); @@ -2503,8 +2503,8 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, struct device *parent, } /* initialize ports */ - sw->ports = kcalloc(sw->config.max_port_number + 1, sizeof(*sw->ports), - GFP_KERNEL); + sw->ports = kzalloc_objs(*sw->ports, sw->config.max_port_number + 1, + GFP_KERNEL); if (!sw->ports) { ret = -ENOMEM; goto err_free_sw_ports; @@ -2577,7 +2577,7 @@ tb_switch_alloc_safe_mode(struct tb *tb, struct device *parent, u64 route) { struct tb_switch *sw; - sw = kzalloc(sizeof(*sw), GFP_KERNEL); + sw = kzalloc_obj(*sw, GFP_KERNEL); if (!sw) return ERR_PTR(-ENOMEM); diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c index 4f5f1dfc0fbf..4c3b2d48c4a0 100644 --- a/drivers/thunderbolt/tb.c +++ b/drivers/thunderbolt/tb.c @@ -94,7 +94,7 @@ static void tb_queue_hotplug(struct tb *tb, u64 route, u8 port, bool unplug) { struct tb_hotplug_event *ev; - ev = kmalloc(sizeof(*ev), GFP_KERNEL); + ev = kmalloc_obj(*ev, GFP_KERNEL); if (!ev) return; @@ -2862,7 +2862,7 @@ static void tb_queue_dp_bandwidth_request(struct tb *tb, u64 route, u8 port, { struct tb_hotplug_event *ev; - ev = kmalloc(sizeof(*ev), GFP_KERNEL); + ev = kmalloc_obj(*ev, GFP_KERNEL); if (!ev) return; diff --git a/drivers/thunderbolt/tunnel.c b/drivers/thunderbolt/tunnel.c index 9fa95c595ecc..2d537ada98e1 100644 --- a/drivers/thunderbolt/tunnel.c +++ b/drivers/thunderbolt/tunnel.c @@ -180,11 +180,11 @@ static struct tb_tunnel *tb_tunnel_alloc(struct tb *tb, size_t npaths, { struct tb_tunnel *tunnel; - tunnel = kzalloc(sizeof(*tunnel), GFP_KERNEL); + tunnel = kzalloc_obj(*tunnel, GFP_KERNEL); if (!tunnel) return NULL; - tunnel->paths = kcalloc(npaths, sizeof(tunnel->paths[0]), GFP_KERNEL); + tunnel->paths = kzalloc_objs(tunnel->paths[0], npaths, GFP_KERNEL); if (!tunnel->paths) { kfree(tunnel); return NULL; diff --git a/drivers/thunderbolt/usb4_port.c b/drivers/thunderbolt/usb4_port.c index b5e06237261b..642822b58b42 100644 --- a/drivers/thunderbolt/usb4_port.c +++ b/drivers/thunderbolt/usb4_port.c @@ -305,7 +305,7 @@ struct usb4_port *usb4_port_device_add(struct tb_port *port) struct usb4_port *usb4; int ret; - usb4 = kzalloc(sizeof(*usb4), GFP_KERNEL); + usb4 = kzalloc_obj(*usb4, GFP_KERNEL); if (!usb4) return ERR_PTR(-ENOMEM); diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c index 63c7be818b2c..384afd16af72 100644 --- a/drivers/thunderbolt/xdomain.c +++ b/drivers/thunderbolt/xdomain.c @@ -858,7 +858,7 @@ tb_xdp_schedule_request(struct tb *tb, const struct tb_xdp_header *hdr, { struct xdomain_request_work *xw; - xw = kmalloc(sizeof(*xw), GFP_KERNEL); + xw = kmalloc_obj(*xw, GFP_KERNEL); if (!xw) return false; @@ -1094,7 +1094,7 @@ static void enumerate_services(struct tb_xdomain *xd) continue; } - svc = kzalloc(sizeof(*svc), GFP_KERNEL); + svc = kzalloc_obj(*svc, GFP_KERNEL); if (!svc) break; @@ -1974,7 +1974,7 @@ struct tb_xdomain *tb_xdomain_alloc(struct tb *tb, struct device *parent, down = tb_port_at(route, parent_sw); tb_port_unlock(down); - xd = kzalloc(sizeof(*xd), GFP_KERNEL); + xd = kzalloc_obj(*xd, GFP_KERNEL); if (!xd) return NULL; |
