diff options
author | Tomas Winkler <tomas.winkler@intel.com> | 2015-02-10 03:39:43 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-03-01 22:37:00 -0500 |
commit | bca67d681c4864b74fa5fae9ee47e562d1e272b1 (patch) | |
tree | 1538db82496b44cc2f7343714ed4a949311f1815 | |
parent | 5db7514d9333c920791538c850cfb9dbd19025f7 (diff) |
mei: always initialize the callback with the intended operation type
We set the operation type at initialization time as each cb is used only
for a single type of operation
As a byproduct we add a convenient wrapper for allocating cb with
the data buffer.
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/misc/mei/amthif.c | 4 | ||||
-rw-r--r-- | drivers/misc/mei/bus.c | 14 | ||||
-rw-r--r-- | drivers/misc/mei/client.c | 64 | ||||
-rw-r--r-- | drivers/misc/mei/client.h | 7 | ||||
-rw-r--r-- | drivers/misc/mei/hbm.c | 3 | ||||
-rw-r--r-- | drivers/misc/mei/main.c | 8 |
6 files changed, 55 insertions, 45 deletions
diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c index 2cc41cb3bb38..3fdd22395b9f 100644 --- a/drivers/misc/mei/amthif.c +++ b/drivers/misc/mei/amthif.c | |||
@@ -254,7 +254,7 @@ static int mei_amthif_read_start(struct mei_cl *cl, struct file *file) | |||
254 | size_t length = dev->iamthif_mtu; | 254 | size_t length = dev->iamthif_mtu; |
255 | int rets; | 255 | int rets; |
256 | 256 | ||
257 | cb = mei_io_cb_init(cl, file); | 257 | cb = mei_io_cb_init(cl, MEI_FOP_READ, file); |
258 | if (!cb) { | 258 | if (!cb) { |
259 | rets = -ENOMEM; | 259 | rets = -ENOMEM; |
260 | goto err; | 260 | goto err; |
@@ -264,7 +264,6 @@ static int mei_amthif_read_start(struct mei_cl *cl, struct file *file) | |||
264 | if (rets) | 264 | if (rets) |
265 | goto err; | 265 | goto err; |
266 | 266 | ||
267 | cb->fop_type = MEI_FOP_READ; | ||
268 | list_add_tail(&cb->list, &dev->ctrl_wr_list.list); | 267 | list_add_tail(&cb->list, &dev->ctrl_wr_list.list); |
269 | 268 | ||
270 | dev->iamthif_state = MEI_IAMTHIF_READING; | 269 | dev->iamthif_state = MEI_IAMTHIF_READING; |
@@ -359,7 +358,6 @@ int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb) | |||
359 | 358 | ||
360 | dev = cl->dev; | 359 | dev = cl->dev; |
361 | 360 | ||
362 | cb->fop_type = MEI_FOP_WRITE; | ||
363 | list_add_tail(&cb->list, &dev->amthif_cmd_list.list); | 361 | list_add_tail(&cb->list, &dev->amthif_cmd_list.list); |
364 | return mei_amthif_run_next_cmd(dev); | 362 | return mei_amthif_run_next_cmd(dev); |
365 | } | 363 | } |
diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c index 36b949a0fddb..3e6ffed9402a 100644 --- a/drivers/misc/mei/bus.c +++ b/drivers/misc/mei/bus.c | |||
@@ -255,16 +255,12 @@ static ssize_t ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, | |||
255 | goto out; | 255 | goto out; |
256 | } | 256 | } |
257 | 257 | ||
258 | cb = mei_io_cb_init(cl, NULL); | 258 | cb = mei_cl_alloc_cb(cl, length, MEI_FOP_WRITE, NULL); |
259 | if (!cb) { | 259 | if (!cb) { |
260 | rets = -ENOMEM; | 260 | rets = -ENOMEM; |
261 | goto out; | 261 | goto out; |
262 | } | 262 | } |
263 | 263 | ||
264 | rets = mei_io_cb_alloc_buf(cb, length); | ||
265 | if (rets < 0) | ||
266 | goto out; | ||
267 | |||
268 | memcpy(cb->buf.data, buf, length); | 264 | memcpy(cb->buf.data, buf, length); |
269 | 265 | ||
270 | rets = mei_cl_write(cl, cb, blocking); | 266 | rets = mei_cl_write(cl, cb, blocking); |
@@ -293,7 +289,7 @@ ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length) | |||
293 | mutex_lock(&dev->device_lock); | 289 | mutex_lock(&dev->device_lock); |
294 | 290 | ||
295 | if (!cl->read_cb) { | 291 | if (!cl->read_cb) { |
296 | rets = mei_cl_read_start(cl, length); | 292 | rets = mei_cl_read_start(cl, length, NULL); |
297 | if (rets < 0) | 293 | if (rets < 0) |
298 | goto out; | 294 | goto out; |
299 | } | 295 | } |
@@ -392,7 +388,7 @@ static void mei_bus_event_work(struct work_struct *work) | |||
392 | device->events = 0; | 388 | device->events = 0; |
393 | 389 | ||
394 | /* Prepare for the next read */ | 390 | /* Prepare for the next read */ |
395 | mei_cl_read_start(device->cl, 0); | 391 | mei_cl_read_start(device->cl, 0, NULL); |
396 | } | 392 | } |
397 | 393 | ||
398 | int mei_cl_register_event_cb(struct mei_cl_device *device, | 394 | int mei_cl_register_event_cb(struct mei_cl_device *device, |
@@ -406,7 +402,7 @@ int mei_cl_register_event_cb(struct mei_cl_device *device, | |||
406 | device->event_context = context; | 402 | device->event_context = context; |
407 | INIT_WORK(&device->event_work, mei_bus_event_work); | 403 | INIT_WORK(&device->event_work, mei_bus_event_work); |
408 | 404 | ||
409 | mei_cl_read_start(device->cl, 0); | 405 | mei_cl_read_start(device->cl, 0, NULL); |
410 | 406 | ||
411 | return 0; | 407 | return 0; |
412 | } | 408 | } |
@@ -448,7 +444,7 @@ int mei_cl_enable_device(struct mei_cl_device *device) | |||
448 | mutex_unlock(&dev->device_lock); | 444 | mutex_unlock(&dev->device_lock); |
449 | 445 | ||
450 | if (device->event_cb && !cl->read_cb) | 446 | if (device->event_cb && !cl->read_cb) |
451 | mei_cl_read_start(device->cl, 0); | 447 | mei_cl_read_start(device->cl, 0, NULL); |
452 | 448 | ||
453 | if (!device->ops || !device->ops->enable) | 449 | if (!device->ops || !device->ops->enable) |
454 | return 0; | 450 | return 0; |
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c index 5ecb6cc79d70..57461016f1ff 100644 --- a/drivers/misc/mei/client.c +++ b/drivers/misc/mei/client.c | |||
@@ -384,11 +384,13 @@ void mei_io_cb_free(struct mei_cl_cb *cb) | |||
384 | * mei_io_cb_init - allocate and initialize io callback | 384 | * mei_io_cb_init - allocate and initialize io callback |
385 | * | 385 | * |
386 | * @cl: mei client | 386 | * @cl: mei client |
387 | * @type: operation type | ||
387 | * @fp: pointer to file structure | 388 | * @fp: pointer to file structure |
388 | * | 389 | * |
389 | * Return: mei_cl_cb pointer or NULL; | 390 | * Return: mei_cl_cb pointer or NULL; |
390 | */ | 391 | */ |
391 | struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp) | 392 | struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, enum mei_cb_file_ops type, |
393 | struct file *fp) | ||
392 | { | 394 | { |
393 | struct mei_cl_cb *cb; | 395 | struct mei_cl_cb *cb; |
394 | 396 | ||
@@ -401,6 +403,7 @@ struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp) | |||
401 | cb->file_object = fp; | 403 | cb->file_object = fp; |
402 | cb->cl = cl; | 404 | cb->cl = cl; |
403 | cb->buf_idx = 0; | 405 | cb->buf_idx = 0; |
406 | cb->fop_type = type; | ||
404 | return cb; | 407 | return cb; |
405 | } | 408 | } |
406 | 409 | ||
@@ -430,6 +433,33 @@ int mei_io_cb_alloc_buf(struct mei_cl_cb *cb, size_t length) | |||
430 | } | 433 | } |
431 | 434 | ||
432 | /** | 435 | /** |
436 | * mei_cl_alloc_cb - a convenient wrapper for allocating read cb | ||
437 | * | ||
438 | * @cl: host client | ||
439 | * @length: size of the buffer | ||
440 | * @type: operation type | ||
441 | * @fp: associated file pointer (might be NULL) | ||
442 | * | ||
443 | * Return: cb on success and NULL on failure | ||
444 | */ | ||
445 | struct mei_cl_cb *mei_cl_alloc_cb(struct mei_cl *cl, size_t length, | ||
446 | enum mei_cb_file_ops type, struct file *fp) | ||
447 | { | ||
448 | struct mei_cl_cb *cb; | ||
449 | |||
450 | cb = mei_io_cb_init(cl, type, fp); | ||
451 | if (!cb) | ||
452 | return NULL; | ||
453 | |||
454 | if (mei_io_cb_alloc_buf(cb, length)) { | ||
455 | mei_io_cb_free(cb); | ||
456 | return NULL; | ||
457 | } | ||
458 | |||
459 | return cb; | ||
460 | } | ||
461 | |||
462 | /** | ||
433 | * mei_cl_flush_queues - flushes queue lists belonging to cl. | 463 | * mei_cl_flush_queues - flushes queue lists belonging to cl. |
434 | * | 464 | * |
435 | * @cl: host client | 465 | * @cl: host client |
@@ -688,13 +718,10 @@ int mei_cl_disconnect(struct mei_cl *cl) | |||
688 | return rets; | 718 | return rets; |
689 | } | 719 | } |
690 | 720 | ||
691 | cb = mei_io_cb_init(cl, NULL); | 721 | cb = mei_io_cb_init(cl, MEI_FOP_DISCONNECT, NULL); |
692 | if (!cb) { | 722 | rets = cb ? 0 : -ENOMEM; |
693 | rets = -ENOMEM; | 723 | if (rets) |
694 | goto free; | 724 | goto free; |
695 | } | ||
696 | |||
697 | cb->fop_type = MEI_FOP_DISCONNECT; | ||
698 | 725 | ||
699 | if (mei_hbuf_acquire(dev)) { | 726 | if (mei_hbuf_acquire(dev)) { |
700 | if (mei_hbm_cl_disconnect_req(dev, cl)) { | 727 | if (mei_hbm_cl_disconnect_req(dev, cl)) { |
@@ -795,13 +822,10 @@ int mei_cl_connect(struct mei_cl *cl, struct file *file) | |||
795 | return rets; | 822 | return rets; |
796 | } | 823 | } |
797 | 824 | ||
798 | cb = mei_io_cb_init(cl, file); | 825 | cb = mei_io_cb_init(cl, MEI_FOP_CONNECT, file); |
799 | if (!cb) { | 826 | rets = cb ? 0 : -ENOMEM; |
800 | rets = -ENOMEM; | 827 | if (rets) |
801 | goto out; | 828 | goto out; |
802 | } | ||
803 | |||
804 | cb->fop_type = MEI_FOP_CONNECT; | ||
805 | 829 | ||
806 | /* run hbuf acquire last so we don't have to undo */ | 830 | /* run hbuf acquire last so we don't have to undo */ |
807 | if (!mei_cl_is_other_connecting(cl) && mei_hbuf_acquire(dev)) { | 831 | if (!mei_cl_is_other_connecting(cl) && mei_hbuf_acquire(dev)) { |
@@ -934,10 +958,11 @@ out: | |||
934 | * | 958 | * |
935 | * @cl: host client | 959 | * @cl: host client |
936 | * @length: number of bytes to read | 960 | * @length: number of bytes to read |
961 | * @fp: pointer to file structure | ||
937 | * | 962 | * |
938 | * Return: 0 on success, <0 on failure. | 963 | * Return: 0 on success, <0 on failure. |
939 | */ | 964 | */ |
940 | int mei_cl_read_start(struct mei_cl *cl, size_t length) | 965 | int mei_cl_read_start(struct mei_cl *cl, size_t length, struct file *fp) |
941 | { | 966 | { |
942 | struct mei_device *dev; | 967 | struct mei_device *dev; |
943 | struct mei_cl_cb *cb; | 968 | struct mei_cl_cb *cb; |
@@ -972,17 +997,11 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length) | |||
972 | return rets; | 997 | return rets; |
973 | } | 998 | } |
974 | 999 | ||
975 | cb = mei_io_cb_init(cl, NULL); | 1000 | cb = mei_cl_alloc_cb(cl, length, MEI_FOP_READ, fp); |
976 | if (!cb) { | 1001 | rets = cb ? 0 : -ENOMEM; |
977 | rets = -ENOMEM; | ||
978 | goto out; | ||
979 | } | ||
980 | |||
981 | rets = mei_io_cb_alloc_buf(cb, length); | ||
982 | if (rets) | 1002 | if (rets) |
983 | goto out; | 1003 | goto out; |
984 | 1004 | ||
985 | cb->fop_type = MEI_FOP_READ; | ||
986 | if (mei_hbuf_acquire(dev)) { | 1005 | if (mei_hbuf_acquire(dev)) { |
987 | rets = mei_hbm_cl_flow_control_req(dev, cl); | 1006 | rets = mei_hbm_cl_flow_control_req(dev, cl); |
988 | if (rets < 0) | 1007 | if (rets < 0) |
@@ -1128,7 +1147,6 @@ int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, bool blocking) | |||
1128 | return rets; | 1147 | return rets; |
1129 | } | 1148 | } |
1130 | 1149 | ||
1131 | cb->fop_type = MEI_FOP_WRITE; | ||
1132 | cb->buf_idx = 0; | 1150 | cb->buf_idx = 0; |
1133 | cl->writing_state = MEI_IDLE; | 1151 | cl->writing_state = MEI_IDLE; |
1134 | 1152 | ||
diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h index d430a6e09ae8..f7d0285b5f57 100644 --- a/drivers/misc/mei/client.h +++ b/drivers/misc/mei/client.h | |||
@@ -47,7 +47,8 @@ void mei_me_cl_rm_all(struct mei_device *dev); | |||
47 | /* | 47 | /* |
48 | * MEI IO Functions | 48 | * MEI IO Functions |
49 | */ | 49 | */ |
50 | struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp); | 50 | struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, enum mei_cb_file_ops type, |
51 | struct file *fp); | ||
51 | void mei_io_cb_free(struct mei_cl_cb *priv_cb); | 52 | void mei_io_cb_free(struct mei_cl_cb *priv_cb); |
52 | int mei_io_cb_alloc_buf(struct mei_cl_cb *cb, size_t length); | 53 | int mei_io_cb_alloc_buf(struct mei_cl_cb *cb, size_t length); |
53 | 54 | ||
@@ -77,6 +78,8 @@ int mei_cl_unlink(struct mei_cl *cl); | |||
77 | int mei_cl_flush_queues(struct mei_cl *cl); | 78 | int mei_cl_flush_queues(struct mei_cl *cl); |
78 | struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl); | 79 | struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl); |
79 | 80 | ||
81 | struct mei_cl_cb *mei_cl_alloc_cb(struct mei_cl *cl, size_t length, | ||
82 | enum mei_cb_file_ops type, struct file *fp); | ||
80 | 83 | ||
81 | int mei_cl_flow_ctrl_creds(struct mei_cl *cl); | 84 | int mei_cl_flow_ctrl_creds(struct mei_cl *cl); |
82 | 85 | ||
@@ -100,7 +103,7 @@ static inline bool mei_cl_is_transitioning(struct mei_cl *cl) | |||
100 | bool mei_cl_is_other_connecting(struct mei_cl *cl); | 103 | bool mei_cl_is_other_connecting(struct mei_cl *cl); |
101 | int mei_cl_disconnect(struct mei_cl *cl); | 104 | int mei_cl_disconnect(struct mei_cl *cl); |
102 | int mei_cl_connect(struct mei_cl *cl, struct file *file); | 105 | int mei_cl_connect(struct mei_cl *cl, struct file *file); |
103 | int mei_cl_read_start(struct mei_cl *cl, size_t length); | 106 | int mei_cl_read_start(struct mei_cl *cl, size_t length, struct file *fp); |
104 | int mei_cl_irq_read_msg(struct mei_cl *cl, struct mei_msg_hdr *hdr, | 107 | int mei_cl_irq_read_msg(struct mei_cl *cl, struct mei_msg_hdr *hdr, |
105 | struct mei_cl_cb *cmpl_list); | 108 | struct mei_cl_cb *cmpl_list); |
106 | int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, bool blocking); | 109 | int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, bool blocking); |
diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c index 4f83e9aaa6f9..2c581dcaf3b1 100644 --- a/drivers/misc/mei/hbm.c +++ b/drivers/misc/mei/hbm.c | |||
@@ -684,10 +684,9 @@ static int mei_hbm_fw_disconnect_req(struct mei_device *dev, | |||
684 | cl->state = MEI_FILE_DISCONNECTED; | 684 | cl->state = MEI_FILE_DISCONNECTED; |
685 | cl->timer_count = 0; | 685 | cl->timer_count = 0; |
686 | 686 | ||
687 | cb = mei_io_cb_init(cl, NULL); | 687 | cb = mei_io_cb_init(cl, MEI_FOP_DISCONNECT_RSP, NULL); |
688 | if (!cb) | 688 | if (!cb) |
689 | return -ENOMEM; | 689 | return -ENOMEM; |
690 | cb->fop_type = MEI_FOP_DISCONNECT_RSP; | ||
691 | cl_dbg(dev, cl, "add disconnect response as first\n"); | 690 | cl_dbg(dev, cl, "add disconnect response as first\n"); |
692 | list_add(&cb->list, &dev->ctrl_wr_list.list); | 691 | list_add(&cb->list, &dev->ctrl_wr_list.list); |
693 | } | 692 | } |
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c index 1d44d110ed94..369de0a070f1 100644 --- a/drivers/misc/mei/main.c +++ b/drivers/misc/mei/main.c | |||
@@ -209,7 +209,7 @@ static ssize_t mei_read(struct file *file, char __user *ubuf, | |||
209 | *offset = 0; | 209 | *offset = 0; |
210 | } | 210 | } |
211 | 211 | ||
212 | err = mei_cl_read_start(cl, length); | 212 | err = mei_cl_read_start(cl, length, file); |
213 | if (err && err != -EBUSY) { | 213 | if (err && err != -EBUSY) { |
214 | dev_dbg(dev->dev, | 214 | dev_dbg(dev->dev, |
215 | "mei start read failure with status = %d\n", err); | 215 | "mei start read failure with status = %d\n", err); |
@@ -383,15 +383,11 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, | |||
383 | } else if (cl->reading_state == MEI_IDLE) | 383 | } else if (cl->reading_state == MEI_IDLE) |
384 | *offset = 0; | 384 | *offset = 0; |
385 | 385 | ||
386 | 386 | write_cb = mei_cl_alloc_cb(cl, length, MEI_FOP_WRITE, file); | |
387 | write_cb = mei_io_cb_init(cl, file); | ||
388 | if (!write_cb) { | 387 | if (!write_cb) { |
389 | rets = -ENOMEM; | 388 | rets = -ENOMEM; |
390 | goto out; | 389 | goto out; |
391 | } | 390 | } |
392 | rets = mei_io_cb_alloc_buf(write_cb, length); | ||
393 | if (rets) | ||
394 | goto out; | ||
395 | 391 | ||
396 | rets = copy_from_user(write_cb->buf.data, ubuf, length); | 392 | rets = copy_from_user(write_cb->buf.data, ubuf, length); |
397 | if (rets) { | 393 | if (rets) { |