Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Bluetooth: Prefer sizeof(*ptr) when allocating memory

It's safer practice to use sizeof(*ptr) instead of sizeof(ptr_type) when
allocating memory in case the type changes. This also fixes the
following style of warnings from static analyzers:

CHECK: Prefer kzalloc(sizeof(*ie)...) over kzalloc(sizeof(struct inquiry_entry)...)
+ ie = kzalloc(sizeof(struct inquiry_entry), GFP_KERNEL);

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

authored by

Johan Hedberg and committed by
Marcel Holtmann
27f70f3e 0a961a44

+6 -6
+2 -2
net/bluetooth/hci_conn.c
··· 428 428 429 429 BT_DBG("%s dst %pMR", hdev->name, dst); 430 430 431 - conn = kzalloc(sizeof(struct hci_conn), GFP_KERNEL); 431 + conn = kzalloc(sizeof(*conn), GFP_KERNEL); 432 432 if (!conn) 433 433 return NULL; 434 434 ··· 1282 1282 1283 1283 BT_DBG("%s hcon %p", hdev->name, conn); 1284 1284 1285 - chan = kzalloc(sizeof(struct hci_chan), GFP_KERNEL); 1285 + chan = kzalloc(sizeof(*chan), GFP_KERNEL); 1286 1286 if (!chan) 1287 1287 return NULL; 1288 1288
+3 -3
net/bluetooth/hci_core.c
··· 2088 2088 } 2089 2089 2090 2090 /* Entry not in the cache. Add new one. */ 2091 - ie = kzalloc(sizeof(struct inquiry_entry), GFP_KERNEL); 2091 + ie = kzalloc(sizeof(*ie), GFP_KERNEL); 2092 2092 if (!ie) { 2093 2093 flags |= MGMT_DEV_FOUND_CONFIRM_NAME; 2094 2094 goto done; ··· 3492 3492 if (hci_bdaddr_list_lookup(list, bdaddr, type)) 3493 3493 return -EEXIST; 3494 3494 3495 - entry = kzalloc(sizeof(struct bdaddr_list), GFP_KERNEL); 3495 + entry = kzalloc(sizeof(*entry), GFP_KERNEL); 3496 3496 if (!entry) 3497 3497 return -ENOMEM; 3498 3498 ··· 3897 3897 { 3898 3898 struct hci_dev *hdev; 3899 3899 3900 - hdev = kzalloc(sizeof(struct hci_dev), GFP_KERNEL); 3900 + hdev = kzalloc(sizeof(*hdev), GFP_KERNEL); 3901 3901 if (!hdev) 3902 3902 return NULL; 3903 3903
+1 -1
net/bluetooth/l2cap_core.c
··· 6985 6985 if (!hchan) 6986 6986 return NULL; 6987 6987 6988 - conn = kzalloc(sizeof(struct l2cap_conn), GFP_KERNEL); 6988 + conn = kzalloc(sizeof(*conn), GFP_KERNEL); 6989 6989 if (!conn) { 6990 6990 hci_chan_del(hchan); 6991 6991 return NULL;