Commit b7cd2d9f authored by Tomas Winkler's avatar Tomas Winkler Committed by Greg Kroah-Hartman

staging/mei: don't check if list is empty before looping

1. No need to check if a list is empty before list_for_each_ looping as
this is already checked by loop stopping conditional.

The side effect is reduced indentation depth
from:
	if (!list_empty)
		list_for_each()
to:
	list_for_each()

2. drop cb_ prefix from cl_pos, cl_next variables used in list_for_each
loops. The code is more compact and readable
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent c8372094
...@@ -48,20 +48,15 @@ void mei_io_list_init(struct mei_io_list *list) ...@@ -48,20 +48,15 @@ void mei_io_list_init(struct mei_io_list *list)
*/ */
void mei_io_list_flush(struct mei_io_list *list, struct mei_cl *cl) void mei_io_list_flush(struct mei_io_list *list, struct mei_cl *cl)
{ {
struct mei_cl_cb *cb_pos = NULL; struct mei_cl_cb *pos = NULL;
struct mei_cl_cb *cb_next = NULL; struct mei_cl_cb *next = NULL;
if (list_empty(&list->mei_cb.cb_list))
return;
list_for_each_entry_safe(cb_pos, cb_next, list_for_each_entry_safe(pos, next, &list->mei_cb.cb_list, cb_list) {
&list->mei_cb.cb_list, cb_list) { if (pos) {
if (cb_pos) {
struct mei_cl *cl_tmp; struct mei_cl *cl_tmp;
cl_tmp = (struct mei_cl *)cb_pos->file_private; cl_tmp = (struct mei_cl *)pos->file_private;
if (mei_cl_cmp_id(cl, cl_tmp)) if (mei_cl_cmp_id(cl, cl_tmp))
list_del(&cb_pos->cb_list); list_del(&pos->cb_list);
} }
} }
} }
...@@ -335,7 +330,6 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled) ...@@ -335,7 +330,6 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
} }
} }
/* remove all waiting requests */ /* remove all waiting requests */
if (!list_empty(&dev->write_list.mei_cb.cb_list)) {
list_for_each_entry_safe(cb_pos, cb_next, list_for_each_entry_safe(cb_pos, cb_next,
&dev->write_list.mei_cb.cb_list, cb_list) { &dev->write_list.mei_cb.cb_list, cb_list) {
if (cb_pos) { if (cb_pos) {
...@@ -344,7 +338,6 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled) ...@@ -344,7 +338,6 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
cb_pos = NULL; cb_pos = NULL;
} }
} }
}
} }
......
...@@ -412,9 +412,9 @@ static void mei_client_connect_response(struct mei_device *dev, ...@@ -412,9 +412,9 @@ static void mei_client_connect_response(struct mei_device *dev,
dev->iamthif_state = MEI_IAMTHIF_IDLE; dev->iamthif_state = MEI_IAMTHIF_IDLE;
return; return;
} }
if (!list_empty(&dev->ctrl_rd_list.mei_cb.cb_list)) {
list_for_each_entry_safe(cb_pos, cb_next, list_for_each_entry_safe(cb_pos, cb_next,
&dev->ctrl_rd_list.mei_cb.cb_list, cb_list) { &dev->ctrl_rd_list.mei_cb.cb_list, cb_list) {
cl = (struct mei_cl *)cb_pos->file_private; cl = (struct mei_cl *)cb_pos->file_private;
if (!cl) { if (!cl) {
list_del(&cb_pos->cb_list); list_del(&cb_pos->cb_list);
...@@ -429,7 +429,6 @@ static void mei_client_connect_response(struct mei_device *dev, ...@@ -429,7 +429,6 @@ static void mei_client_connect_response(struct mei_device *dev,
} }
} }
} }
}
} }
/** /**
...@@ -453,7 +452,6 @@ static void mei_client_disconnect_response(struct mei_device *dev, ...@@ -453,7 +452,6 @@ static void mei_client_disconnect_response(struct mei_device *dev,
rs->host_addr, rs->host_addr,
rs->status); rs->status);
if (!list_empty(&dev->ctrl_rd_list.mei_cb.cb_list)) {
list_for_each_entry_safe(cb_pos, cb_next, list_for_each_entry_safe(cb_pos, cb_next,
&dev->ctrl_rd_list.mei_cb.cb_list, cb_list) { &dev->ctrl_rd_list.mei_cb.cb_list, cb_list) {
cl = (struct mei_cl *)cb_pos->file_private; cl = (struct mei_cl *)cb_pos->file_private;
...@@ -476,7 +474,6 @@ static void mei_client_disconnect_response(struct mei_device *dev, ...@@ -476,7 +474,6 @@ static void mei_client_disconnect_response(struct mei_device *dev,
break; break;
} }
} }
}
} }
/** /**
...@@ -1222,7 +1219,7 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list, ...@@ -1222,7 +1219,7 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
{ {
struct mei_cl *cl; struct mei_cl *cl;
struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL; struct mei_cl_cb *pos = NULL, *next = NULL;
struct mei_io_list *list; struct mei_io_list *list;
int ret; int ret;
...@@ -1235,29 +1232,27 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list, ...@@ -1235,29 +1232,27 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
dev_dbg(&dev->pdev->dev, "complete all waiting for write cb.\n"); dev_dbg(&dev->pdev->dev, "complete all waiting for write cb.\n");
list = &dev->write_waiting_list; list = &dev->write_waiting_list;
if (!list_empty(&list->mei_cb.cb_list)) { list_for_each_entry_safe(pos, next,
list_for_each_entry_safe(cb_pos, cb_next,
&list->mei_cb.cb_list, cb_list) { &list->mei_cb.cb_list, cb_list) {
cl = (struct mei_cl *)cb_pos->file_private; cl = (struct mei_cl *)pos->file_private;
if (cl) { if (cl == NULL)
continue;
cl->status = 0; cl->status = 0;
list_del(&cb_pos->cb_list); list_del(&pos->cb_list);
if (MEI_WRITING == cl->writing_state && if (MEI_WRITING == cl->writing_state &&
(cb_pos->major_file_operations == (pos->major_file_operations == MEI_WRITE) &&
MEI_WRITE) &&
(cl != &dev->iamthif_cl)) { (cl != &dev->iamthif_cl)) {
dev_dbg(&dev->pdev->dev, dev_dbg(&dev->pdev->dev,
"MEI WRITE COMPLETE\n"); "MEI WRITE COMPLETE\n");
cl->writing_state = cl->writing_state = MEI_WRITE_COMPLETE;
MEI_WRITE_COMPLETE; list_add_tail(&pos->cb_list,
list_add_tail(&cb_pos->cb_list,
&cmpl_list->mei_cb.cb_list); &cmpl_list->mei_cb.cb_list);
} }
if (cl == &dev->iamthif_cl) { if (cl == &dev->iamthif_cl) {
dev_dbg(&dev->pdev->dev, "check iamthif flow control.\n"); dev_dbg(&dev->pdev->dev, "check iamthif flow control.\n");
if (dev->iamthif_flow_control_pending) { if (dev->iamthif_flow_control_pending) {
ret = ret = _mei_irq_thread_iamthif_read(
_mei_irq_thread_iamthif_read(
dev, slots); dev, slots);
if (ret) if (ret)
return ret; return ret;
...@@ -1265,9 +1260,6 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list, ...@@ -1265,9 +1260,6 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
} }
} }
}
}
if (dev->stop && !dev->wd_pending) { if (dev->stop && !dev->wd_pending) {
dev->wd_stopped = true; dev->wd_stopped = true;
wake_up_interruptible(&dev->wait_stop_wd); wake_up_interruptible(&dev->wait_stop_wd);
...@@ -1312,24 +1304,24 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list, ...@@ -1312,24 +1304,24 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
/* complete control write list CB */ /* complete control write list CB */
dev_dbg(&dev->pdev->dev, "complete control write list cb.\n"); dev_dbg(&dev->pdev->dev, "complete control write list cb.\n");
list_for_each_entry_safe(cb_pos, cb_next, list_for_each_entry_safe(pos, next,
&dev->ctrl_wr_list.mei_cb.cb_list, cb_list) { &dev->ctrl_wr_list.mei_cb.cb_list, cb_list) {
cl = (struct mei_cl *) cb_pos->file_private; cl = (struct mei_cl *) pos->file_private;
if (!cl) { if (!cl) {
list_del(&cb_pos->cb_list); list_del(&pos->cb_list);
return -ENODEV; return -ENODEV;
} }
switch (cb_pos->major_file_operations) { switch (pos->major_file_operations) {
case MEI_CLOSE: case MEI_CLOSE:
/* send disconnect message */ /* send disconnect message */
ret = _mei_irq_thread_close(dev, slots, cb_pos, cl, cmpl_list); ret = _mei_irq_thread_close(dev, slots, pos, cl, cmpl_list);
if (ret) if (ret)
return ret; return ret;
break; break;
case MEI_READ: case MEI_READ:
/* send flow control message */ /* send flow control message */
ret = _mei_irq_thread_read(dev, slots, cb_pos, cl, cmpl_list); ret = _mei_irq_thread_read(dev, slots, pos, cl, cmpl_list);
if (ret) if (ret)
return ret; return ret;
...@@ -1338,7 +1330,7 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list, ...@@ -1338,7 +1330,7 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
/* connect message */ /* connect message */
if (!mei_other_client_is_connecting(dev, cl)) if (!mei_other_client_is_connecting(dev, cl))
continue; continue;
ret = _mei_irq_thread_ioctl(dev, slots, cb_pos, cl, cmpl_list); ret = _mei_irq_thread_ioctl(dev, slots, pos, cl, cmpl_list);
if (ret) if (ret)
return ret; return ret;
...@@ -1350,16 +1342,15 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list, ...@@ -1350,16 +1342,15 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
} }
/* complete write list CB */ /* complete write list CB */
if (!list_empty(&dev->write_list.mei_cb.cb_list)) {
dev_dbg(&dev->pdev->dev, "complete write list cb.\n"); dev_dbg(&dev->pdev->dev, "complete write list cb.\n");
list_for_each_entry_safe(cb_pos, cb_next, list_for_each_entry_safe(pos, next,
&dev->write_list.mei_cb.cb_list, cb_list) { &dev->write_list.mei_cb.cb_list, cb_list) {
cl = (struct mei_cl *)cb_pos->file_private; cl = (struct mei_cl *)pos->file_private;
if (cl == NULL)
continue;
if (cl) {
if (cl != &dev->iamthif_cl) { if (cl != &dev->iamthif_cl) {
if (!mei_flow_ctrl_creds(dev, if (!mei_flow_ctrl_creds(dev, cl)) {
cl)) {
dev_dbg(&dev->pdev->dev, dev_dbg(&dev->pdev->dev,
"No flow control" "No flow control"
" credentials for client" " credentials for client"
...@@ -1368,7 +1359,7 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list, ...@@ -1368,7 +1359,7 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
continue; continue;
} }
ret = _mei_irq_thread_cmpl(dev, slots, ret = _mei_irq_thread_cmpl(dev, slots,
cb_pos, pos,
cl, cmpl_list); cl, cmpl_list);
if (ret) if (ret)
return ret; return ret;
...@@ -1376,8 +1367,7 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list, ...@@ -1376,8 +1367,7 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
} else if (cl == &dev->iamthif_cl) { } else if (cl == &dev->iamthif_cl) {
/* IAMTHIF IOCTL */ /* IAMTHIF IOCTL */
dev_dbg(&dev->pdev->dev, "complete amthi write cb.\n"); dev_dbg(&dev->pdev->dev, "complete amthi write cb.\n");
if (!mei_flow_ctrl_creds(dev, if (!mei_flow_ctrl_creds(dev, cl)) {
cl)) {
dev_dbg(&dev->pdev->dev, dev_dbg(&dev->pdev->dev,
"No flow control" "No flow control"
" credentials for amthi" " credentials for amthi"
...@@ -1387,17 +1377,15 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list, ...@@ -1387,17 +1377,15 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
} }
ret = _mei_irq_thread_cmpl_iamthif(dev, ret = _mei_irq_thread_cmpl_iamthif(dev,
slots, slots,
cb_pos, pos,
cl, cl,
cmpl_list); cmpl_list);
if (ret) if (ret)
return ret; return ret;
} }
}
} }
}
return 0; return 0;
} }
...@@ -1487,11 +1475,7 @@ void mei_timer(struct work_struct *work) ...@@ -1487,11 +1475,7 @@ void mei_timer(struct work_struct *work)
amthi_complete_list = &dev->amthi_read_complete_list. amthi_complete_list = &dev->amthi_read_complete_list.
mei_cb.cb_list; mei_cb.cb_list;
if (!list_empty(amthi_complete_list)) { list_for_each_entry_safe(cb_pos, cb_next, amthi_complete_list, cb_list) {
list_for_each_entry_safe(cb_pos, cb_next,
amthi_complete_list,
cb_list) {
cl_pos = cb_pos->file_object->private_data; cl_pos = cb_pos->file_object->private_data;
...@@ -1499,7 +1483,6 @@ void mei_timer(struct work_struct *work) ...@@ -1499,7 +1483,6 @@ void mei_timer(struct work_struct *work)
if (cl_pos == &dev->iamthif_cl) if (cl_pos == &dev->iamthif_cl)
list_del(&cb_pos->cb_list); list_del(&cb_pos->cb_list);
} }
}
if (dev->iamthif_current_cb) if (dev->iamthif_current_cb)
mei_free_cb_private(dev->iamthif_current_cb); mei_free_cb_private(dev->iamthif_current_cb);
......
...@@ -228,17 +228,15 @@ struct mei_cl_cb *find_amthi_read_list_entry( ...@@ -228,17 +228,15 @@ struct mei_cl_cb *find_amthi_read_list_entry(
struct file *file) struct file *file)
{ {
struct mei_cl *cl_temp; struct mei_cl *cl_temp;
struct mei_cl_cb *cb_pos = NULL; struct mei_cl_cb *pos = NULL;
struct mei_cl_cb *cb_next = NULL; struct mei_cl_cb *next = NULL;
if (!list_empty(&dev->amthi_read_complete_list.mei_cb.cb_list)) { list_for_each_entry_safe(pos, next,
list_for_each_entry_safe(cb_pos, cb_next,
&dev->amthi_read_complete_list.mei_cb.cb_list, cb_list) { &dev->amthi_read_complete_list.mei_cb.cb_list, cb_list) {
cl_temp = (struct mei_cl *)cb_pos->file_private; cl_temp = (struct mei_cl *)pos->file_private;
if (cl_temp && cl_temp == &dev->iamthif_cl && if (cl_temp && cl_temp == &dev->iamthif_cl &&
cb_pos->file_object == file) pos->file_object == file)
return cb_pos; return pos;
}
} }
return NULL; return NULL;
} }
...@@ -549,8 +547,8 @@ int amthi_write(struct mei_device *dev, struct mei_cl_cb *cb) ...@@ -549,8 +547,8 @@ int amthi_write(struct mei_device *dev, struct mei_cl_cb *cb)
void mei_run_next_iamthif_cmd(struct mei_device *dev) void mei_run_next_iamthif_cmd(struct mei_device *dev)
{ {
struct mei_cl *cl_tmp; struct mei_cl *cl_tmp;
struct mei_cl_cb *cb_pos = NULL; struct mei_cl_cb *pos = NULL;
struct mei_cl_cb *cb_next = NULL; struct mei_cl_cb *next = NULL;
int status; int status;
if (!dev) if (!dev)
...@@ -564,16 +562,15 @@ void mei_run_next_iamthif_cmd(struct mei_device *dev) ...@@ -564,16 +562,15 @@ void mei_run_next_iamthif_cmd(struct mei_device *dev)
dev->iamthif_timer = 0; dev->iamthif_timer = 0;
dev->iamthif_file_object = NULL; dev->iamthif_file_object = NULL;
if (!list_empty(&dev->amthi_cmd_list.mei_cb.cb_list)) {
dev_dbg(&dev->pdev->dev, "complete amthi cmd_list cb.\n"); dev_dbg(&dev->pdev->dev, "complete amthi cmd_list cb.\n");
list_for_each_entry_safe(cb_pos, cb_next, list_for_each_entry_safe(pos, next,
&dev->amthi_cmd_list.mei_cb.cb_list, cb_list) { &dev->amthi_cmd_list.mei_cb.cb_list, cb_list) {
list_del(&cb_pos->cb_list); list_del(&pos->cb_list);
cl_tmp = (struct mei_cl *)cb_pos->file_private; cl_tmp = (struct mei_cl *)pos->file_private;
if (cl_tmp && cl_tmp == &dev->iamthif_cl) { if (cl_tmp && cl_tmp == &dev->iamthif_cl) {
status = amthi_write(dev, cb_pos); status = amthi_write(dev, pos);
if (status) { if (status) {
dev_dbg(&dev->pdev->dev, dev_dbg(&dev->pdev->dev,
"amthi write failed status = %d\n", "amthi write failed status = %d\n",
...@@ -583,7 +580,6 @@ void mei_run_next_iamthif_cmd(struct mei_device *dev) ...@@ -583,7 +580,6 @@ void mei_run_next_iamthif_cmd(struct mei_device *dev)
break; break;
} }
} }
}
} }
/** /**
......
...@@ -198,20 +198,17 @@ static struct mei_cl_cb *find_read_list_entry( ...@@ -198,20 +198,17 @@ static struct mei_cl_cb *find_read_list_entry(
struct mei_device *dev, struct mei_device *dev,
struct mei_cl *cl) struct mei_cl *cl)
{ {
struct mei_cl_cb *cb_pos = NULL; struct mei_cl_cb *pos = NULL;
struct mei_cl_cb *cb_next = NULL; struct mei_cl_cb *next = NULL;
if (!list_empty(&dev->read_list.mei_cb.cb_list)) {
dev_dbg(&dev->pdev->dev, "remove read_list CB\n"); dev_dbg(&dev->pdev->dev, "remove read_list CB\n");
list_for_each_entry_safe(cb_pos, cb_next, list_for_each_entry_safe(pos, next,
&dev->read_list.mei_cb.cb_list, cb_list) { &dev->read_list.mei_cb.cb_list, cb_list) {
struct mei_cl *cl_temp; struct mei_cl *cl_temp;
cl_temp = (struct mei_cl *)cb_pos->file_private; cl_temp = (struct mei_cl *)pos->file_private;
if (mei_cl_cmp_id(cl, cl_temp)) if (mei_cl_cmp_id(cl, cl_temp))
return cb_pos; return pos;
}
} }
return NULL; return NULL;
} }
......
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