aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorTomas Winkler <tomas.winkler@intel.com>2015-02-10 03:39:44 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-03-01 22:37:00 -0500
commit03b8d3419fdfc02d1984a0db51c8b74426e12605 (patch)
tree740b43b278842ad3d88c47e1b707616e4c2c4a1a /drivers/misc
parentbca67d681c4864b74fa5fae9ee47e562d1e272b1 (diff)
mei: add mei_cl_alloc_linked function
Add convenient wrapper mei_cl_alloc_linked to simplify error handling Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/mei/client.c35
-rw-r--r--drivers/misc/mei/client.h2
-rw-r--r--drivers/misc/mei/main.c17
-rw-r--r--drivers/misc/mei/nfc.c43
4 files changed, 61 insertions, 36 deletions
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
index 57461016f1ff..e263c0713a6d 100644
--- a/drivers/misc/mei/client.c
+++ b/drivers/misc/mei/client.c
@@ -547,11 +547,11 @@ struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl)
547 * mei_cl_link - allocate host id in the host map 547 * mei_cl_link - allocate host id in the host map
548 * 548 *
549 * @cl: host client 549 * @cl: host client
550 * @id: fixed host id or -1 for generic one 550 * @id: fixed host id or MEI_HOST_CLIENT_ID_ANY (-1) for generic one
551 * 551 *
552 * Return: 0 on success 552 * Return: 0 on success
553 * -EINVAL on incorrect values 553 * -EINVAL on incorrect values
554 * -ENONET if client not found 554 * -EMFILE if open count exceeded.
555 */ 555 */
556int mei_cl_link(struct mei_cl *cl, int id) 556int mei_cl_link(struct mei_cl *cl, int id)
557{ 557{
@@ -870,6 +870,37 @@ out:
870} 870}
871 871
872/** 872/**
873 * mei_cl_alloc_linked - allocate and link host client
874 *
875 * @dev: the device structure
876 * @id: fixed host id or MEI_HOST_CLIENT_ID_ANY (-1) for generic one
877 *
878 * Return: cl on success ERR_PTR on failure
879 */
880struct mei_cl *mei_cl_alloc_linked(struct mei_device *dev, int id)
881{
882 struct mei_cl *cl;
883 int ret;
884
885 cl = mei_cl_allocate(dev);
886 if (!cl) {
887 ret = -ENOMEM;
888 goto err;
889 }
890
891 ret = mei_cl_link(cl, id);
892 if (ret)
893 goto err;
894
895 return cl;
896err:
897 kfree(cl);
898 return ERR_PTR(ret);
899}
900
901
902
903/**
873 * mei_cl_flow_ctrl_creds - checks flow_control credits for cl. 904 * mei_cl_flow_ctrl_creds - checks flow_control credits for cl.
874 * 905 *
875 * @cl: private data of the file object 906 * @cl: private data of the file object
diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h
index f7d0285b5f57..c3d0e200a642 100644
--- a/drivers/misc/mei/client.h
+++ b/drivers/misc/mei/client.h
@@ -75,6 +75,8 @@ void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
75int mei_cl_link(struct mei_cl *cl, int id); 75int mei_cl_link(struct mei_cl *cl, int id);
76int mei_cl_unlink(struct mei_cl *cl); 76int mei_cl_unlink(struct mei_cl *cl);
77 77
78struct mei_cl *mei_cl_alloc_linked(struct mei_device *dev, int id);
79
78int mei_cl_flush_queues(struct mei_cl *cl); 80int mei_cl_flush_queues(struct mei_cl *cl);
79struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl); 81struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl);
80 82
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index 369de0a070f1..10fc3a6a1574 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -59,24 +59,18 @@ static int mei_open(struct inode *inode, struct file *file)
59 59
60 mutex_lock(&dev->device_lock); 60 mutex_lock(&dev->device_lock);
61 61
62 cl = NULL;
63
64 err = -ENODEV;
65 if (dev->dev_state != MEI_DEV_ENABLED) { 62 if (dev->dev_state != MEI_DEV_ENABLED) {
66 dev_dbg(dev->dev, "dev_state != MEI_ENABLED dev_state = %s\n", 63 dev_dbg(dev->dev, "dev_state != MEI_ENABLED dev_state = %s\n",
67 mei_dev_state_str(dev->dev_state)); 64 mei_dev_state_str(dev->dev_state));
65 err = -ENODEV;
68 goto err_unlock; 66 goto err_unlock;
69 } 67 }
70 68
71 err = -ENOMEM; 69 cl = mei_cl_alloc_linked(dev, MEI_HOST_CLIENT_ID_ANY);
72 cl = mei_cl_allocate(dev); 70 if (IS_ERR(cl)) {
73 if (!cl) 71 err = PTR_ERR(cl);
74 goto err_unlock;
75
76 /* open_handle_count check is handled in the mei_cl_link */
77 err = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY);
78 if (err)
79 goto err_unlock; 72 goto err_unlock;
73 }
80 74
81 file->private_data = cl; 75 file->private_data = cl;
82 76
@@ -86,7 +80,6 @@ static int mei_open(struct inode *inode, struct file *file)
86 80
87err_unlock: 81err_unlock:
88 mutex_unlock(&dev->device_lock); 82 mutex_unlock(&dev->device_lock);
89 kfree(cl);
90 return err; 83 return err;
91} 84}
92 85
diff --git a/drivers/misc/mei/nfc.c b/drivers/misc/mei/nfc.c
index bb61a119b8bb..c3bcb63686d7 100644
--- a/drivers/misc/mei/nfc.c
+++ b/drivers/misc/mei/nfc.c
@@ -482,8 +482,8 @@ err:
482int mei_nfc_host_init(struct mei_device *dev) 482int mei_nfc_host_init(struct mei_device *dev)
483{ 483{
484 struct mei_nfc_dev *ndev; 484 struct mei_nfc_dev *ndev;
485 struct mei_cl *cl_info, *cl = NULL; 485 struct mei_cl *cl_info, *cl;
486 struct mei_me_client *me_cl; 486 struct mei_me_client *me_cl = NULL;
487 int ret; 487 int ret;
488 488
489 489
@@ -500,17 +500,6 @@ int mei_nfc_host_init(struct mei_device *dev)
500 goto err; 500 goto err;
501 } 501 }
502 502
503 ndev->cl_info = mei_cl_allocate(dev);
504 ndev->cl = mei_cl_allocate(dev);
505
506 cl = ndev->cl;
507 cl_info = ndev->cl_info;
508
509 if (!cl || !cl_info) {
510 ret = -ENOMEM;
511 goto err;
512 }
513
514 /* check for valid client id */ 503 /* check for valid client id */
515 me_cl = mei_me_cl_by_uuid(dev, &mei_nfc_info_guid); 504 me_cl = mei_me_cl_by_uuid(dev, &mei_nfc_info_guid);
516 if (!me_cl) { 505 if (!me_cl) {
@@ -519,17 +508,21 @@ int mei_nfc_host_init(struct mei_device *dev)
519 goto err; 508 goto err;
520 } 509 }
521 510
511 cl_info = mei_cl_alloc_linked(dev, MEI_HOST_CLIENT_ID_ANY);
512 if (IS_ERR(cl_info)) {
513 ret = PTR_ERR(cl_info);
514 goto err;
515 }
516
522 cl_info->me_client_id = me_cl->client_id; 517 cl_info->me_client_id = me_cl->client_id;
523 cl_info->cl_uuid = me_cl->props.protocol_name; 518 cl_info->cl_uuid = me_cl->props.protocol_name;
524 mei_me_cl_put(me_cl); 519 mei_me_cl_put(me_cl);
525 520 me_cl = NULL;
526 ret = mei_cl_link(cl_info, MEI_HOST_CLIENT_ID_ANY);
527 if (ret)
528 goto err;
529
530 521
531 list_add_tail(&cl_info->device_link, &dev->device_list); 522 list_add_tail(&cl_info->device_link, &dev->device_list);
532 523
524 ndev->cl_info = cl_info;
525
533 /* check for valid client id */ 526 /* check for valid client id */
534 me_cl = mei_me_cl_by_uuid(dev, &mei_nfc_guid); 527 me_cl = mei_me_cl_by_uuid(dev, &mei_nfc_guid);
535 if (!me_cl) { 528 if (!me_cl) {
@@ -538,16 +531,21 @@ int mei_nfc_host_init(struct mei_device *dev)
538 goto err; 531 goto err;
539 } 532 }
540 533
534 cl = mei_cl_alloc_linked(dev, MEI_HOST_CLIENT_ID_ANY);
535 if (IS_ERR(cl)) {
536 ret = PTR_ERR(cl);
537 goto err;
538 }
539
541 cl->me_client_id = me_cl->client_id; 540 cl->me_client_id = me_cl->client_id;
542 cl->cl_uuid = me_cl->props.protocol_name; 541 cl->cl_uuid = me_cl->props.protocol_name;
543 mei_me_cl_put(me_cl); 542 mei_me_cl_put(me_cl);
544 543 me_cl = NULL;
545 ret = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY);
546 if (ret)
547 goto err;
548 544
549 list_add_tail(&cl->device_link, &dev->device_list); 545 list_add_tail(&cl->device_link, &dev->device_list);
550 546
547 ndev->cl = cl;
548
551 ndev->req_id = 1; 549 ndev->req_id = 1;
552 550
553 INIT_WORK(&ndev->init_work, mei_nfc_init); 551 INIT_WORK(&ndev->init_work, mei_nfc_init);
@@ -557,6 +555,7 @@ int mei_nfc_host_init(struct mei_device *dev)
557 return 0; 555 return 0;
558 556
559err: 557err:
558 mei_me_cl_put(me_cl);
560 mei_nfc_free(ndev); 559 mei_nfc_free(ndev);
561 560
562 return ret; 561 return ret;