提交 03b8d341 编写于 作者: T Tomas Winkler 提交者: Greg Kroah-Hartman

mei: add mei_cl_alloc_linked function

Add convenient wrapper mei_cl_alloc_linked
to simplify error handling
Signed-off-by: NTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 bca67d68
...@@ -547,11 +547,11 @@ struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl) ...@@ -547,11 +547,11 @@ struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl)
* mei_cl_link - allocate host id in the host map * mei_cl_link - allocate host id in the host map
* *
* @cl: host client * @cl: host client
* @id: fixed host id or -1 for generic one * @id: fixed host id or MEI_HOST_CLIENT_ID_ANY (-1) for generic one
* *
* Return: 0 on success * Return: 0 on success
* -EINVAL on incorrect values * -EINVAL on incorrect values
* -ENONET if client not found * -EMFILE if open count exceeded.
*/ */
int mei_cl_link(struct mei_cl *cl, int id) int mei_cl_link(struct mei_cl *cl, int id)
{ {
...@@ -869,6 +869,37 @@ int mei_cl_connect(struct mei_cl *cl, struct file *file) ...@@ -869,6 +869,37 @@ int mei_cl_connect(struct mei_cl *cl, struct file *file)
return rets; return rets;
} }
/**
* mei_cl_alloc_linked - allocate and link host client
*
* @dev: the device structure
* @id: fixed host id or MEI_HOST_CLIENT_ID_ANY (-1) for generic one
*
* Return: cl on success ERR_PTR on failure
*/
struct mei_cl *mei_cl_alloc_linked(struct mei_device *dev, int id)
{
struct mei_cl *cl;
int ret;
cl = mei_cl_allocate(dev);
if (!cl) {
ret = -ENOMEM;
goto err;
}
ret = mei_cl_link(cl, id);
if (ret)
goto err;
return cl;
err:
kfree(cl);
return ERR_PTR(ret);
}
/** /**
* mei_cl_flow_ctrl_creds - checks flow_control credits for cl. * mei_cl_flow_ctrl_creds - checks flow_control credits for cl.
* *
......
...@@ -75,6 +75,8 @@ void mei_cl_init(struct mei_cl *cl, struct mei_device *dev); ...@@ -75,6 +75,8 @@ void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
int mei_cl_link(struct mei_cl *cl, int id); int mei_cl_link(struct mei_cl *cl, int id);
int mei_cl_unlink(struct mei_cl *cl); int mei_cl_unlink(struct mei_cl *cl);
struct mei_cl *mei_cl_alloc_linked(struct mei_device *dev, int id);
int mei_cl_flush_queues(struct mei_cl *cl); int mei_cl_flush_queues(struct mei_cl *cl);
struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl); struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl);
......
...@@ -59,24 +59,18 @@ static int mei_open(struct inode *inode, struct file *file) ...@@ -59,24 +59,18 @@ static int mei_open(struct inode *inode, struct file *file)
mutex_lock(&dev->device_lock); mutex_lock(&dev->device_lock);
cl = NULL;
err = -ENODEV;
if (dev->dev_state != MEI_DEV_ENABLED) { if (dev->dev_state != MEI_DEV_ENABLED) {
dev_dbg(dev->dev, "dev_state != MEI_ENABLED dev_state = %s\n", dev_dbg(dev->dev, "dev_state != MEI_ENABLED dev_state = %s\n",
mei_dev_state_str(dev->dev_state)); mei_dev_state_str(dev->dev_state));
err = -ENODEV;
goto err_unlock; goto err_unlock;
} }
err = -ENOMEM; cl = mei_cl_alloc_linked(dev, MEI_HOST_CLIENT_ID_ANY);
cl = mei_cl_allocate(dev); if (IS_ERR(cl)) {
if (!cl) err = PTR_ERR(cl);
goto err_unlock;
/* open_handle_count check is handled in the mei_cl_link */
err = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY);
if (err)
goto err_unlock; goto err_unlock;
}
file->private_data = cl; file->private_data = cl;
...@@ -86,7 +80,6 @@ static int mei_open(struct inode *inode, struct file *file) ...@@ -86,7 +80,6 @@ static int mei_open(struct inode *inode, struct file *file)
err_unlock: err_unlock:
mutex_unlock(&dev->device_lock); mutex_unlock(&dev->device_lock);
kfree(cl);
return err; return err;
} }
......
...@@ -482,8 +482,8 @@ static void mei_nfc_init(struct work_struct *work) ...@@ -482,8 +482,8 @@ static void mei_nfc_init(struct work_struct *work)
int mei_nfc_host_init(struct mei_device *dev) int mei_nfc_host_init(struct mei_device *dev)
{ {
struct mei_nfc_dev *ndev; struct mei_nfc_dev *ndev;
struct mei_cl *cl_info, *cl = NULL; struct mei_cl *cl_info, *cl;
struct mei_me_client *me_cl; struct mei_me_client *me_cl = NULL;
int ret; int ret;
...@@ -500,17 +500,6 @@ int mei_nfc_host_init(struct mei_device *dev) ...@@ -500,17 +500,6 @@ int mei_nfc_host_init(struct mei_device *dev)
goto err; goto err;
} }
ndev->cl_info = mei_cl_allocate(dev);
ndev->cl = mei_cl_allocate(dev);
cl = ndev->cl;
cl_info = ndev->cl_info;
if (!cl || !cl_info) {
ret = -ENOMEM;
goto err;
}
/* check for valid client id */ /* check for valid client id */
me_cl = mei_me_cl_by_uuid(dev, &mei_nfc_info_guid); me_cl = mei_me_cl_by_uuid(dev, &mei_nfc_info_guid);
if (!me_cl) { if (!me_cl) {
...@@ -519,17 +508,21 @@ int mei_nfc_host_init(struct mei_device *dev) ...@@ -519,17 +508,21 @@ int mei_nfc_host_init(struct mei_device *dev)
goto err; goto err;
} }
cl_info = mei_cl_alloc_linked(dev, MEI_HOST_CLIENT_ID_ANY);
if (IS_ERR(cl_info)) {
ret = PTR_ERR(cl_info);
goto err;
}
cl_info->me_client_id = me_cl->client_id; cl_info->me_client_id = me_cl->client_id;
cl_info->cl_uuid = me_cl->props.protocol_name; cl_info->cl_uuid = me_cl->props.protocol_name;
mei_me_cl_put(me_cl); mei_me_cl_put(me_cl);
me_cl = NULL;
ret = mei_cl_link(cl_info, MEI_HOST_CLIENT_ID_ANY);
if (ret)
goto err;
list_add_tail(&cl_info->device_link, &dev->device_list); list_add_tail(&cl_info->device_link, &dev->device_list);
ndev->cl_info = cl_info;
/* check for valid client id */ /* check for valid client id */
me_cl = mei_me_cl_by_uuid(dev, &mei_nfc_guid); me_cl = mei_me_cl_by_uuid(dev, &mei_nfc_guid);
if (!me_cl) { if (!me_cl) {
...@@ -538,16 +531,21 @@ int mei_nfc_host_init(struct mei_device *dev) ...@@ -538,16 +531,21 @@ int mei_nfc_host_init(struct mei_device *dev)
goto err; goto err;
} }
cl = mei_cl_alloc_linked(dev, MEI_HOST_CLIENT_ID_ANY);
if (IS_ERR(cl)) {
ret = PTR_ERR(cl);
goto err;
}
cl->me_client_id = me_cl->client_id; cl->me_client_id = me_cl->client_id;
cl->cl_uuid = me_cl->props.protocol_name; cl->cl_uuid = me_cl->props.protocol_name;
mei_me_cl_put(me_cl); mei_me_cl_put(me_cl);
me_cl = NULL;
ret = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY);
if (ret)
goto err;
list_add_tail(&cl->device_link, &dev->device_list); list_add_tail(&cl->device_link, &dev->device_list);
ndev->cl = cl;
ndev->req_id = 1; ndev->req_id = 1;
INIT_WORK(&ndev->init_work, mei_nfc_init); INIT_WORK(&ndev->init_work, mei_nfc_init);
...@@ -557,6 +555,7 @@ int mei_nfc_host_init(struct mei_device *dev) ...@@ -557,6 +555,7 @@ int mei_nfc_host_init(struct mei_device *dev)
return 0; return 0;
err: err:
mei_me_cl_put(me_cl);
mei_nfc_free(ndev); mei_nfc_free(ndev);
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册