Commit 98f179a5 authored by Tadeusz Struk's avatar Tadeusz Struk Committed by Doug Ledford

IB/hfi1: Fix sleep inside atomic issue in init_asic_data

The critical section should protect only the list traversal
and dd->asic_data modification, not the memory allocation.
The fix pulls the allocation out of the critical section.
Reviewed-by: default avatarDennis Dalessandro <dennis.dalessandro@intel.com>
Reviewed-by: default avatarSebastian Sanchez <sebastian.sanchez@intel.com>
Reviewed-by: default avatarDean Luick <dean.luick@intel.com>
Signed-off-by: default avatarTadeusz Struk <tadeusz.struk@intel.com>
Signed-off-by: default avatarDennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: default avatarMike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent 896ce45d
...@@ -14113,8 +14113,14 @@ static int init_asic_data(struct hfi1_devdata *dd) ...@@ -14113,8 +14113,14 @@ static int init_asic_data(struct hfi1_devdata *dd)
{ {
unsigned long flags; unsigned long flags;
struct hfi1_devdata *tmp, *peer = NULL; struct hfi1_devdata *tmp, *peer = NULL;
struct hfi1_asic_data *asic_data;
int ret = 0; int ret = 0;
/* pre-allocate the asic structure in case we are the first device */
asic_data = kzalloc(sizeof(*dd->asic_data), GFP_KERNEL);
if (!asic_data)
return -ENOMEM;
spin_lock_irqsave(&hfi1_devs_lock, flags); spin_lock_irqsave(&hfi1_devs_lock, flags);
/* Find our peer device */ /* Find our peer device */
list_for_each_entry(tmp, &hfi1_dev_list, list) { list_for_each_entry(tmp, &hfi1_dev_list, list) {
...@@ -14126,18 +14132,14 @@ static int init_asic_data(struct hfi1_devdata *dd) ...@@ -14126,18 +14132,14 @@ static int init_asic_data(struct hfi1_devdata *dd)
} }
if (peer) { if (peer) {
/* use already allocated structure */
dd->asic_data = peer->asic_data; dd->asic_data = peer->asic_data;
kfree(asic_data);
} else { } else {
dd->asic_data = kzalloc(sizeof(*dd->asic_data), GFP_KERNEL); dd->asic_data = asic_data;
if (!dd->asic_data) {
ret = -ENOMEM;
goto done;
}
mutex_init(&dd->asic_data->asic_resource_mutex); mutex_init(&dd->asic_data->asic_resource_mutex);
} }
dd->asic_data->dds[dd->hfi1_id] = dd; /* self back-pointer */ dd->asic_data->dds[dd->hfi1_id] = dd; /* self back-pointer */
done:
spin_unlock_irqrestore(&hfi1_devs_lock, flags); spin_unlock_irqrestore(&hfi1_devs_lock, flags);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment