IB/hfi1: Convert kzalloc_node and kcalloc to use kcalloc_node
Kzalloc_node API doesn't check for overflows in size multiplication. While kcalloc API check for overflows in size multiplication but these implementations are not NUMA-aware. This conversion allowed for correcting an allocation used in the hot path to be on the local NUMA and ensure us overflow free multiplication for the size of a memory allocation. Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com> Signed-off-by: Kamenee Arumugam <kamenee.arumugam@intel.com> Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
This commit is contained in:

committed by
Jason Gunthorpe

parent
2ff124d597
commit
953a9cebea
@@ -172,7 +172,7 @@ int hfi1_create_kctxts(struct hfi1_devdata *dd)
|
||||
u16 i;
|
||||
int ret;
|
||||
|
||||
dd->rcd = kzalloc_node(dd->num_rcv_contexts * sizeof(*dd->rcd),
|
||||
dd->rcd = kcalloc_node(dd->num_rcv_contexts, sizeof(*dd->rcd),
|
||||
GFP_KERNEL, dd->node);
|
||||
if (!dd->rcd)
|
||||
return -ENOMEM;
|
||||
@@ -439,15 +439,16 @@ int hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, int numa,
|
||||
* The resulting value will be rounded down to the closest
|
||||
* multiple of dd->rcv_entries.group_size.
|
||||
*/
|
||||
rcd->egrbufs.buffers = kzalloc_node(
|
||||
rcd->egrbufs.count * sizeof(*rcd->egrbufs.buffers),
|
||||
GFP_KERNEL, numa);
|
||||
rcd->egrbufs.buffers =
|
||||
kcalloc_node(rcd->egrbufs.count,
|
||||
sizeof(*rcd->egrbufs.buffers),
|
||||
GFP_KERNEL, numa);
|
||||
if (!rcd->egrbufs.buffers)
|
||||
goto bail;
|
||||
rcd->egrbufs.rcvtids = kzalloc_node(
|
||||
rcd->egrbufs.count *
|
||||
sizeof(*rcd->egrbufs.rcvtids),
|
||||
GFP_KERNEL, numa);
|
||||
rcd->egrbufs.rcvtids =
|
||||
kcalloc_node(rcd->egrbufs.count,
|
||||
sizeof(*rcd->egrbufs.rcvtids),
|
||||
GFP_KERNEL, numa);
|
||||
if (!rcd->egrbufs.rcvtids)
|
||||
goto bail;
|
||||
rcd->egrbufs.size = eager_buffer_size;
|
||||
|
Reference in New Issue
Block a user