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 /net/nfc | |
| 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 'net/nfc')
| -rw-r--r-- | net/nfc/core.c | 4 | ||||
| -rw-r--r-- | net/nfc/digital_core.c | 8 | ||||
| -rw-r--r-- | net/nfc/digital_technology.c | 6 | ||||
| -rw-r--r-- | net/nfc/hci/core.c | 4 | ||||
| -rw-r--r-- | net/nfc/hci/hcp.c | 2 | ||||
| -rw-r--r-- | net/nfc/hci/llc.c | 4 | ||||
| -rw-r--r-- | net/nfc/hci/llc_nop.c | 2 | ||||
| -rw-r--r-- | net/nfc/hci/llc_shdlc.c | 2 | ||||
| -rw-r--r-- | net/nfc/llcp_commands.c | 4 | ||||
| -rw-r--r-- | net/nfc/llcp_core.c | 2 | ||||
| -rw-r--r-- | net/nfc/nci/core.c | 2 | ||||
| -rw-r--r-- | net/nfc/nci/hci.c | 2 | ||||
| -rw-r--r-- | net/nfc/nci/uart.c | 2 | ||||
| -rw-r--r-- | net/nfc/netlink.c | 8 |
14 files changed, 26 insertions, 26 deletions
diff --git a/net/nfc/core.c b/net/nfc/core.c index f50e5bab35d8..c39d00b2a0d7 100644 --- a/net/nfc/core.c +++ b/net/nfc/core.c @@ -879,7 +879,7 @@ int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type) if (se) return -EALREADY; - se = kzalloc(sizeof(struct nfc_se), GFP_KERNEL); + se = kzalloc_obj(struct nfc_se, GFP_KERNEL); if (!se) return -ENOMEM; @@ -1062,7 +1062,7 @@ struct nfc_dev *nfc_allocate_device(const struct nfc_ops *ops, if (!supported_protocols) return NULL; - dev = kzalloc(sizeof(struct nfc_dev), GFP_KERNEL); + dev = kzalloc_obj(struct nfc_dev, GFP_KERNEL); if (!dev) return NULL; diff --git a/net/nfc/digital_core.c b/net/nfc/digital_core.c index dae378f1d52b..be9a048b583b 100644 --- a/net/nfc/digital_core.c +++ b/net/nfc/digital_core.c @@ -231,7 +231,7 @@ int digital_send_cmd(struct nfc_digital_dev *ddev, u8 cmd_type, { struct digital_cmd *cmd; - cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); + cmd = kzalloc_obj(*cmd, GFP_KERNEL); if (!cmd) return -ENOMEM; @@ -279,7 +279,7 @@ static int digital_tg_listen_mdaa(struct nfc_digital_dev *ddev, u8 rf_tech) struct digital_tg_mdaa_params *params; int rc; - params = kzalloc(sizeof(*params), GFP_KERNEL); + params = kzalloc_obj(*params, GFP_KERNEL); if (!params) return -ENOMEM; @@ -706,7 +706,7 @@ static int digital_in_send(struct nfc_dev *nfc_dev, struct nfc_target *target, struct digital_data_exch *data_exch; int rc; - data_exch = kzalloc(sizeof(*data_exch), GFP_KERNEL); + data_exch = kzalloc_obj(*data_exch, GFP_KERNEL); if (!data_exch) return -ENOMEM; @@ -762,7 +762,7 @@ struct nfc_digital_dev *nfc_digital_allocate_device(const struct nfc_digital_ops !ops->switch_rf || (ops->tg_listen_md && !ops->tg_get_rf_tech)) return NULL; - ddev = kzalloc(sizeof(*ddev), GFP_KERNEL); + ddev = kzalloc_obj(*ddev, GFP_KERNEL); if (!ddev) return NULL; diff --git a/net/nfc/digital_technology.c b/net/nfc/digital_technology.c index 3adf4589852a..df2bfb4734c5 100644 --- a/net/nfc/digital_technology.c +++ b/net/nfc/digital_technology.c @@ -490,7 +490,7 @@ static void digital_in_recv_sens_res(struct nfc_digital_dev *ddev, void *arg, goto exit; } - target = kzalloc(sizeof(struct nfc_target), GFP_KERNEL); + target = kzalloc_obj(struct nfc_target, GFP_KERNEL); if (!target) { rc = -ENOMEM; goto exit; @@ -688,7 +688,7 @@ static void digital_in_recv_sensb_res(struct nfc_digital_dev *ddev, void *arg, else ddev->target_fsc = digital_ats_fsc[fsci]; - target = kzalloc(sizeof(struct nfc_target), GFP_KERNEL); + target = kzalloc_obj(struct nfc_target, GFP_KERNEL); if (!target) { rc = -ENOMEM; goto exit; @@ -863,7 +863,7 @@ static void digital_in_recv_iso15693_inv_res(struct nfc_digital_dev *ddev, goto out_free_skb; } - target = kzalloc(sizeof(*target), GFP_KERNEL); + target = kzalloc_obj(*target, GFP_KERNEL); if (!target) { rc = -ENOMEM; goto out_free_skb; diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c index 8618d57c23da..10bcd9d2576a 100644 --- a/net/nfc/hci/core.c +++ b/net/nfc/hci/core.c @@ -291,7 +291,7 @@ int nfc_hci_target_discovered(struct nfc_hci_dev *hdev, u8 gate) pr_debug("from gate %d\n", gate); - targets = kzalloc(sizeof(struct nfc_target), GFP_KERNEL); + targets = kzalloc_obj(struct nfc_target, GFP_KERNEL); if (targets == NULL) return -ENOMEM; @@ -964,7 +964,7 @@ struct nfc_hci_dev *nfc_hci_allocate_device(const struct nfc_hci_ops *ops, if (protocols == 0) return NULL; - hdev = kzalloc(sizeof(struct nfc_hci_dev), GFP_KERNEL); + hdev = kzalloc_obj(struct nfc_hci_dev, GFP_KERNEL); if (hdev == NULL) return NULL; diff --git a/net/nfc/hci/hcp.c b/net/nfc/hci/hcp.c index 4902f5064098..903fb134cd80 100644 --- a/net/nfc/hci/hcp.c +++ b/net/nfc/hci/hcp.c @@ -30,7 +30,7 @@ int nfc_hci_hcp_message_tx(struct nfc_hci_dev *hdev, u8 pipe, int hci_len, err; bool firstfrag = true; - cmd = kzalloc(sizeof(struct hci_msg), GFP_KERNEL); + cmd = kzalloc_obj(struct hci_msg, GFP_KERNEL); if (cmd == NULL) return -ENOMEM; diff --git a/net/nfc/hci/llc.c b/net/nfc/hci/llc.c index e6cf4eb06b46..12d7940c6217 100644 --- a/net/nfc/hci/llc.c +++ b/net/nfc/hci/llc.c @@ -49,7 +49,7 @@ int nfc_llc_register(const char *name, const struct nfc_llc_ops *ops) { struct nfc_llc_engine *llc_engine; - llc_engine = kzalloc(sizeof(struct nfc_llc_engine), GFP_KERNEL); + llc_engine = kzalloc_obj(struct nfc_llc_engine, GFP_KERNEL); if (llc_engine == NULL) return -ENOMEM; @@ -90,7 +90,7 @@ struct nfc_llc *nfc_llc_allocate(const char *name, struct nfc_hci_dev *hdev, if (llc_engine == NULL) return NULL; - llc = kzalloc(sizeof(struct nfc_llc), GFP_KERNEL); + llc = kzalloc_obj(struct nfc_llc, GFP_KERNEL); if (llc == NULL) return NULL; diff --git a/net/nfc/hci/llc_nop.c b/net/nfc/hci/llc_nop.c index a58716f16954..eb940330fd5d 100644 --- a/net/nfc/hci/llc_nop.c +++ b/net/nfc/hci/llc_nop.c @@ -28,7 +28,7 @@ static void *llc_nop_init(struct nfc_hci_dev *hdev, xmit_to_drv_t xmit_to_drv, *rx_headroom = 0; *rx_tailroom = 0; - llc_nop = kzalloc(sizeof(struct llc_nop), GFP_KERNEL); + llc_nop = kzalloc_obj(struct llc_nop, GFP_KERNEL); if (llc_nop == NULL) return NULL; diff --git a/net/nfc/hci/llc_shdlc.c b/net/nfc/hci/llc_shdlc.c index 08c8aa1530d8..7e0d84c29cb1 100644 --- a/net/nfc/hci/llc_shdlc.c +++ b/net/nfc/hci/llc_shdlc.c @@ -728,7 +728,7 @@ static void *llc_shdlc_init(struct nfc_hci_dev *hdev, xmit_to_drv_t xmit_to_drv, *rx_headroom = SHDLC_LLC_HEAD_ROOM; *rx_tailroom = 0; - shdlc = kzalloc(sizeof(struct llc_shdlc), GFP_KERNEL); + shdlc = kzalloc_obj(struct llc_shdlc, GFP_KERNEL); if (shdlc == NULL) return NULL; diff --git a/net/nfc/llcp_commands.c b/net/nfc/llcp_commands.c index b652323bc2c1..90f68199ecca 100644 --- a/net/nfc/llcp_commands.c +++ b/net/nfc/llcp_commands.c @@ -108,7 +108,7 @@ struct nfc_llcp_sdp_tlv *nfc_llcp_build_sdres_tlv(u8 tid, u8 sap) struct nfc_llcp_sdp_tlv *sdres; u8 value[2]; - sdres = kzalloc(sizeof(struct nfc_llcp_sdp_tlv), GFP_KERNEL); + sdres = kzalloc_obj(struct nfc_llcp_sdp_tlv, GFP_KERNEL); if (sdres == NULL) return NULL; @@ -141,7 +141,7 @@ struct nfc_llcp_sdp_tlv *nfc_llcp_build_sdreq_tlv(u8 tid, const char *uri, if (WARN_ON_ONCE(uri_len > U8_MAX - 4)) return NULL; - sdreq = kzalloc(sizeof(struct nfc_llcp_sdp_tlv), GFP_KERNEL); + sdreq = kzalloc_obj(struct nfc_llcp_sdp_tlv, GFP_KERNEL); if (sdreq == NULL) return NULL; diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c index 444a3774c8e8..98f0c3281281 100644 --- a/net/nfc/llcp_core.c +++ b/net/nfc/llcp_core.c @@ -1621,7 +1621,7 @@ int nfc_llcp_register_device(struct nfc_dev *ndev) { struct nfc_llcp_local *local; - local = kzalloc(sizeof(struct nfc_llcp_local), GFP_KERNEL); + local = kzalloc_obj(struct nfc_llcp_local, GFP_KERNEL); if (local == NULL) return -ENOMEM; diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c index e419e020a70a..dc17ed8be242 100644 --- a/net/nfc/nci/core.c +++ b/net/nfc/nci/core.c @@ -1171,7 +1171,7 @@ struct nci_dev *nci_allocate_device(const struct nci_ops *ops, if (!supported_protocols) return NULL; - ndev = kzalloc(sizeof(struct nci_dev), GFP_KERNEL); + ndev = kzalloc_obj(struct nci_dev, GFP_KERNEL); if (!ndev) return NULL; diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c index 082ab66f120b..cd3e87b2dd3e 100644 --- a/net/nfc/nci/hci.c +++ b/net/nfc/nci/hci.c @@ -777,7 +777,7 @@ struct nci_hci_dev *nci_hci_allocate(struct nci_dev *ndev) { struct nci_hci_dev *hdev; - hdev = kzalloc(sizeof(*hdev), GFP_KERNEL); + hdev = kzalloc_obj(*hdev, GFP_KERNEL); if (!hdev) return NULL; diff --git a/net/nfc/nci/uart.c b/net/nfc/nci/uart.c index aab107727f18..25dc2868fd27 100644 --- a/net/nfc/nci/uart.c +++ b/net/nfc/nci/uart.c @@ -113,7 +113,7 @@ static int nci_uart_set_driver(struct tty_struct *tty, unsigned int driver) if (!nci_uart_drivers[driver]) return -ENOENT; - nu = kzalloc(sizeof(*nu), GFP_KERNEL); + nu = kzalloc_obj(*nu, GFP_KERNEL); if (!nu) return -ENOMEM; diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c index a18e2c503da6..a69322721c31 100644 --- a/net/nfc/netlink.c +++ b/net/nfc/netlink.c @@ -604,7 +604,7 @@ static int nfc_genl_dump_devices(struct sk_buff *skb, if (!iter) { first_call = true; - iter = kmalloc(sizeof(struct class_dev_iter), GFP_KERNEL); + iter = kmalloc_obj(struct class_dev_iter, GFP_KERNEL); if (!iter) return -ENOMEM; cb->args[0] = (long) iter; @@ -1370,7 +1370,7 @@ static int nfc_genl_dump_ses(struct sk_buff *skb, if (!iter) { first_call = true; - iter = kmalloc(sizeof(struct class_dev_iter), GFP_KERNEL); + iter = kmalloc_obj(struct class_dev_iter, GFP_KERNEL); if (!iter) return -ENOMEM; cb->args[0] = (long) iter; @@ -1541,7 +1541,7 @@ static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info) apdu = nla_data(info->attrs[NFC_ATTR_SE_APDU]); - ctx = kzalloc(sizeof(struct se_io_ctx), GFP_KERNEL); + ctx = kzalloc_obj(struct se_io_ctx, GFP_KERNEL); if (!ctx) { rc = -ENOMEM; goto put_dev; @@ -1875,7 +1875,7 @@ static int nfc_genl_rcv_nl_event(struct notifier_block *this, pr_debug("NETLINK_URELEASE event from id %d\n", n->portid); - w = kmalloc(sizeof(*w), GFP_ATOMIC); + w = kmalloc_obj(*w, GFP_ATOMIC); if (w) { INIT_WORK(&w->w, nfc_urelease_event_work); w->portid = n->portid; |
