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 /drivers/misc/mei/client.c | |
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>
Diffstat (limited to 'drivers/misc/mei/client.c')
-rw-r--r-- | drivers/misc/mei/client.c | 64 |
1 files changed, 41 insertions, 23 deletions
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 | ||