Commit 58b25a63 authored by Dongxiao Xu's avatar Dongxiao Xu Committed by Greg Kroah-Hartman

Staging: heci: fix softirq safe to unsafe spinlock issue

When spinlock is nested, and the outside one is spin_lock_bh, the inner
spinlock should also be spin_lock_bh, otherwise it will bring softirq-safe
to softirq-unsafe lock conversion.
Signed-off-by: default avatarDongxiao Xu <dongxiao.xu@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 72abd228
...@@ -955,10 +955,10 @@ static ssize_t heci_read(struct file *file, char __user *ubuf, ...@@ -955,10 +955,10 @@ static ssize_t heci_read(struct file *file, char __user *ubuf,
} }
err = heci_start_read(dev, if_num, file_ext); err = heci_start_read(dev, if_num, file_ext);
spin_lock(&file_ext->read_io_lock); spin_lock_bh(&file_ext->read_io_lock);
if (err != 0 && err != -EBUSY) { if (err != 0 && err != -EBUSY) {
DBG("heci start read failure with status = %d\n", err); DBG("heci start read failure with status = %d\n", err);
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
rets = err; rets = err;
goto out; goto out;
} }
...@@ -966,10 +966,10 @@ static ssize_t heci_read(struct file *file, char __user *ubuf, ...@@ -966,10 +966,10 @@ static ssize_t heci_read(struct file *file, char __user *ubuf,
&& !waitqueue_active(&file_ext->rx_wait)) { && !waitqueue_active(&file_ext->rx_wait)) {
if (file->f_flags & O_NONBLOCK) { if (file->f_flags & O_NONBLOCK) {
rets = -EAGAIN; rets = -EAGAIN;
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
goto out; goto out;
} }
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
if (wait_event_interruptible(file_ext->rx_wait, if (wait_event_interruptible(file_ext->rx_wait,
(HECI_READ_COMPLETE == file_ext->reading_state (HECI_READ_COMPLETE == file_ext->reading_state
...@@ -989,20 +989,20 @@ static ssize_t heci_read(struct file *file, char __user *ubuf, ...@@ -989,20 +989,20 @@ static ssize_t heci_read(struct file *file, char __user *ubuf,
rets = -EBUSY; rets = -EBUSY;
goto out; goto out;
} }
spin_lock(&file_ext->read_io_lock); spin_lock_bh(&file_ext->read_io_lock);
} }
priv_cb = file_ext->read_cb; priv_cb = file_ext->read_cb;
if (!priv_cb) { if (!priv_cb) {
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
return -ENODEV; return -ENODEV;
} }
if (file_ext->reading_state != HECI_READ_COMPLETE) { if (file_ext->reading_state != HECI_READ_COMPLETE) {
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
return 0; return 0;
} }
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
/* now copy the data to user space */ /* now copy the data to user space */
copy_buffer: copy_buffer:
DBG("priv_cb->response_buffer size - %d\n", DBG("priv_cb->response_buffer size - %d\n",
...@@ -1040,11 +1040,11 @@ free: ...@@ -1040,11 +1040,11 @@ free:
list_del(&priv_cb_pos->cb_list); list_del(&priv_cb_pos->cb_list);
spin_unlock_bh(&dev->device_lock); spin_unlock_bh(&dev->device_lock);
heci_free_cb_private(priv_cb); heci_free_cb_private(priv_cb);
spin_lock(&file_ext->read_io_lock); spin_lock_bh(&file_ext->read_io_lock);
file_ext->reading_state = HECI_IDLE; file_ext->reading_state = HECI_IDLE;
file_ext->read_cb = NULL; file_ext->read_cb = NULL;
file_ext->read_pending = 0; file_ext->read_pending = 0;
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
out: DBG("end heci read rets= %d\n", rets); out: DBG("end heci read rets= %d\n", rets);
return rets; return rets;
} }
...@@ -1106,11 +1106,11 @@ static ssize_t heci_write(struct file *file, const char __user *ubuf, ...@@ -1106,11 +1106,11 @@ static ssize_t heci_write(struct file *file, const char __user *ubuf,
list_del(&priv_write_cb->cb_list); list_del(&priv_write_cb->cb_list);
heci_free_cb_private(priv_write_cb); heci_free_cb_private(priv_write_cb);
priv_write_cb = NULL; priv_write_cb = NULL;
spin_lock(&file_ext->read_io_lock); spin_lock_bh(&file_ext->read_io_lock);
file_ext->reading_state = HECI_IDLE; file_ext->reading_state = HECI_IDLE;
file_ext->read_cb = NULL; file_ext->read_cb = NULL;
file_ext->read_pending = 0; file_ext->read_pending = 0;
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
} }
} else if (file_ext->reading_state == HECI_IDLE && } else if (file_ext->reading_state == HECI_IDLE &&
file_ext->read_pending == 0) file_ext->read_pending == 0)
......
...@@ -622,7 +622,7 @@ static int heci_bh_read_client_message(struct io_heci_list *complete_list, ...@@ -622,7 +622,7 @@ static int heci_bh_read_client_message(struct io_heci_list *complete_list,
priv_cb_pos->file_private; priv_cb_pos->file_private;
if ((file_ext != NULL) && if ((file_ext != NULL) &&
(_heci_bh_state_ok(file_ext, heci_hdr))) { (_heci_bh_state_ok(file_ext, heci_hdr))) {
spin_lock(&file_ext->read_io_lock); spin_lock_bh(&file_ext->read_io_lock);
file_ext->reading_state = HECI_READING; file_ext->reading_state = HECI_READING;
buffer = (unsigned char *) buffer = (unsigned char *)
(priv_cb_pos->response_buffer.data + (priv_cb_pos->response_buffer.data +
...@@ -636,7 +636,7 @@ static int heci_bh_read_client_message(struct io_heci_list *complete_list, ...@@ -636,7 +636,7 @@ static int heci_bh_read_client_message(struct io_heci_list *complete_list,
priv_cb_pos->information) { priv_cb_pos->information) {
DBG("message overflow.\n"); DBG("message overflow.\n");
list_del(&priv_cb_pos->cb_list); list_del(&priv_cb_pos->cb_list);
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
return -ENOMEM; return -ENOMEM;
} }
if (buffer) { if (buffer) {
...@@ -647,7 +647,7 @@ static int heci_bh_read_client_message(struct io_heci_list *complete_list, ...@@ -647,7 +647,7 @@ static int heci_bh_read_client_message(struct io_heci_list *complete_list,
if (heci_hdr->msg_complete) { if (heci_hdr->msg_complete) {
file_ext->status = 0; file_ext->status = 0;
list_del(&priv_cb_pos->cb_list); list_del(&priv_cb_pos->cb_list);
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
DBG("completed read host client = %d," DBG("completed read host client = %d,"
"ME client = %d, " "ME client = %d, "
"data length = %lu\n", "data length = %lu\n",
...@@ -662,7 +662,7 @@ static int heci_bh_read_client_message(struct io_heci_list *complete_list, ...@@ -662,7 +662,7 @@ static int heci_bh_read_client_message(struct io_heci_list *complete_list,
list_add_tail(&priv_cb_pos->cb_list, list_add_tail(&priv_cb_pos->cb_list,
&complete_list->heci_cb.cb_list); &complete_list->heci_cb.cb_list);
} else { } else {
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
} }
break; break;
......
...@@ -648,26 +648,26 @@ int heci_start_read(struct iamt_heci_device *dev, int if_num, ...@@ -648,26 +648,26 @@ int heci_start_read(struct iamt_heci_device *dev, int if_num,
} }
spin_unlock_bh(&dev->device_lock); spin_unlock_bh(&dev->device_lock);
DBG("check if read is pending.\n"); DBG("check if read is pending.\n");
spin_lock(&file_ext->read_io_lock); spin_lock_bh(&file_ext->read_io_lock);
if ((file_ext->read_pending) || (file_ext->read_cb != NULL)) { if ((file_ext->read_pending) || (file_ext->read_cb != NULL)) {
DBG("read is pending.\n"); DBG("read is pending.\n");
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
return -EBUSY; return -EBUSY;
} }
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
priv_cb = kzalloc(sizeof(struct heci_cb_private), GFP_KERNEL); priv_cb = kzalloc(sizeof(struct heci_cb_private), GFP_KERNEL);
if (!priv_cb) if (!priv_cb)
return -ENOMEM; return -ENOMEM;
spin_lock(&file_ext->read_io_lock); spin_lock_bh(&file_ext->read_io_lock);
DBG("allocation call back success\n" DBG("allocation call back success\n"
"host client = %d, ME client = %d\n", "host client = %d, ME client = %d\n",
file_ext->host_client_id, file_ext->me_client_id); file_ext->host_client_id, file_ext->me_client_id);
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
spin_lock_bh(&dev->device_lock); spin_lock_bh(&dev->device_lock);
spin_lock(&file_ext->read_io_lock); spin_lock_bh(&file_ext->read_io_lock);
for (i = 0; i < dev->num_heci_me_clients; i++) { for (i = 0; i < dev->num_heci_me_clients; i++) {
if (dev->me_clients[i].client_id == file_ext->me_client_id) if (dev->me_clients[i].client_id == file_ext->me_client_id)
break; break;
...@@ -675,7 +675,7 @@ int heci_start_read(struct iamt_heci_device *dev, int if_num, ...@@ -675,7 +675,7 @@ int heci_start_read(struct iamt_heci_device *dev, int if_num,
} }
BUG_ON(dev->me_clients[i].client_id != file_ext->me_client_id); BUG_ON(dev->me_clients[i].client_id != file_ext->me_client_id);
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
if (i == dev->num_heci_me_clients) { if (i == dev->num_heci_me_clients) {
rets = -ENODEV; rets = -ENODEV;
goto unlock; goto unlock;
...@@ -695,13 +695,13 @@ int heci_start_read(struct iamt_heci_device *dev, int if_num, ...@@ -695,13 +695,13 @@ int heci_start_read(struct iamt_heci_device *dev, int if_num,
priv_cb->information = 0; priv_cb->information = 0;
priv_cb->file_private = (void *) file_ext; priv_cb->file_private = (void *) file_ext;
spin_lock_bh(&dev->device_lock); spin_lock_bh(&dev->device_lock);
spin_lock(&file_ext->read_io_lock); spin_lock_bh(&file_ext->read_io_lock);
file_ext->read_cb = priv_cb; file_ext->read_cb = priv_cb;
if (dev->host_buffer_is_empty) { if (dev->host_buffer_is_empty) {
dev->host_buffer_is_empty = 0; dev->host_buffer_is_empty = 0;
if (!heci_send_flow_control(dev, file_ext)) { if (!heci_send_flow_control(dev, file_ext)) {
rets = -ENODEV; rets = -ENODEV;
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
goto unlock; goto unlock;
} else { } else {
list_add_tail(&priv_cb->cb_list, list_add_tail(&priv_cb->cb_list,
...@@ -711,7 +711,7 @@ int heci_start_read(struct iamt_heci_device *dev, int if_num, ...@@ -711,7 +711,7 @@ int heci_start_read(struct iamt_heci_device *dev, int if_num,
list_add_tail(&priv_cb->cb_list, list_add_tail(&priv_cb->cb_list,
&dev->ctrl_wr_list.heci_cb.cb_list); &dev->ctrl_wr_list.heci_cb.cb_list);
} }
spin_unlock(&file_ext->read_io_lock); spin_unlock_bh(&file_ext->read_io_lock);
spin_unlock_bh(&dev->device_lock); spin_unlock_bh(&dev->device_lock);
return rets; return rets;
unlock: unlock:
......
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