Skip to content

Commit da86dc1

Browse files
ddalessajgunthorpe
authored andcommitted
IB/hfi1: Properly allocate rdma counter desc memory
When optional counter support was added the allocation of the memory holding the counter descriptors was not cleared properly. This caused WARN_ON()s in the IB/sysfs code to be hit. This is because the uninitialized memory made some of the counters wrongly look like optional counters. Use kzalloc. While here change the sizeof() calls to use the pointer rather than the name of the type. WARNING: CPU: 0 PID: 32644 at drivers/infiniband/core/sysfs.c:1064 ib_setup_port_attrs+0x7e1/0x890 [ib_core] CPU: 0 PID: 32644 Comm: kworker/0:2 Tainted: G S W 5.15.0+ #36 Hardware name: Intel Corporation S2600WTT/S2600WTT, BIOS SE5C610.86B.01.01.0018.C4.072020161249 07/20/2016 Workqueue: events work_for_cpu_fn RIP: 0010:ib_setup_port_attrs+0x7e1/0x890 [ib_core] RSP: 0018:ffffc90006ea3c40 EFLAGS: 00010202 RAX: 0000000000000068 RBX: ffff888106ad8000 RCX: 0000000000000138 RDX: ffff888126c84c00 RSI: ffff888103c41000 RDI: 0000000000000124 RBP: ffff88810f63a801 R08: ffff888126c8a000 R09: 0000000000000001 R10: ffffffffa09acf20 R11: 0000000000000065 R12: ffff88810f63a800 R13: ffff88810f63a800 R14: ffff88810f63a8e0 R15: 0000000000000001 FS: 0000000000000000(0000) GS:ffff888667a00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00005590102cb078 CR3: 000000000240a003 CR4: 00000000001706f0 Call Trace: ib_register_device.cold.44+0x23e/0x2d0 [ib_core] rvt_register_device+0xfa/0x230 [rdmavt] hfi1_register_ib_device+0x623/0x690 [hfi1] init_one.cold.36+0x2d1/0x49b [hfi1] local_pci_probe+0x45/0x80 work_for_cpu_fn+0x16/0x20 process_one_work+0x1b1/0x360 worker_thread+0x1d4/0x3a0 kthread+0x11a/0x140 ret_from_fork+0x22/0x30 Fixes: 5e2ddd1 ("RDMA/counter: Add optional counter support") Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Mike Marciniszyn <[email protected]> Signed-off-by: Dennis Dalessandro <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 6cd7397 commit da86dc1

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/infiniband/hw/hfi1/verbs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,16 +1628,15 @@ static int init_cntr_names(const char *names_in, const size_t names_len,
16281628
n++;
16291629

16301630
names_out =
1631-
kmalloc((n + num_extra_names) * sizeof(struct rdma_stat_desc) +
1632-
names_len,
1631+
kzalloc((n + num_extra_names) * sizeof(*q) + names_len,
16331632
GFP_KERNEL);
16341633
if (!names_out) {
16351634
*num_cntrs = 0;
16361635
*cntr_descs = NULL;
16371636
return -ENOMEM;
16381637
}
16391638

1640-
p = names_out + (n + num_extra_names) * sizeof(struct rdma_stat_desc);
1639+
p = names_out + (n + num_extra_names) * sizeof(*q);
16411640
memcpy(p, names_in, names_len);
16421641

16431642
q = (struct rdma_stat_desc *)names_out;

0 commit comments

Comments
 (0)