Skip to content

Commit 27f70f3

Browse files
jhedbergholtmann
authored andcommitted
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>
1 parent 0a961a4 commit 27f70f3

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎net/bluetooth/hci_conn.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
428428

429429
BT_DBG("%s dst %pMR", hdev->name, dst);
430430

431-
conn = kzalloc(sizeof(struct hci_conn), GFP_KERNEL);
431+
conn = kzalloc(sizeof(*conn), GFP_KERNEL);
432432
if (!conn)
433433
return NULL;
434434

@@ -1282,7 +1282,7 @@ struct hci_chan *hci_chan_create(struct hci_conn *conn)
12821282

12831283
BT_DBG("%s hcon %p", hdev->name, conn);
12841284

1285-
chan = kzalloc(sizeof(struct hci_chan), GFP_KERNEL);
1285+
chan = kzalloc(sizeof(*chan), GFP_KERNEL);
12861286
if (!chan)
12871287
return NULL;
12881288

‎net/bluetooth/hci_core.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,7 @@ u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
20882088
}
20892089

20902090
/* Entry not in the cache. Add new one. */
2091-
ie = kzalloc(sizeof(struct inquiry_entry), GFP_KERNEL);
2091+
ie = kzalloc(sizeof(*ie), GFP_KERNEL);
20922092
if (!ie) {
20932093
flags |= MGMT_DEV_FOUND_CONFIRM_NAME;
20942094
goto done;
@@ -3492,7 +3492,7 @@ int hci_bdaddr_list_add(struct list_head *list, bdaddr_t *bdaddr, u8 type)
34923492
if (hci_bdaddr_list_lookup(list, bdaddr, type))
34933493
return -EEXIST;
34943494

3495-
entry = kzalloc(sizeof(struct bdaddr_list), GFP_KERNEL);
3495+
entry = kzalloc(sizeof(*entry), GFP_KERNEL);
34963496
if (!entry)
34973497
return -ENOMEM;
34983498

@@ -3897,7 +3897,7 @@ struct hci_dev *hci_alloc_dev(void)
38973897
{
38983898
struct hci_dev *hdev;
38993899

3900-
hdev = kzalloc(sizeof(struct hci_dev), GFP_KERNEL);
3900+
hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
39013901
if (!hdev)
39023902
return NULL;
39033903

‎net/bluetooth/l2cap_core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6985,7 +6985,7 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon)
69856985
if (!hchan)
69866986
return NULL;
69876987

6988-
conn = kzalloc(sizeof(struct l2cap_conn), GFP_KERNEL);
6988+
conn = kzalloc(sizeof(*conn), GFP_KERNEL);
69896989
if (!conn) {
69906990
hci_chan_del(hchan);
69916991
return NULL;

0 commit comments

Comments
 (0)