提交 c110cdb1 编写于 作者: A Alexander Usyskin 提交者: Greg Kroah-Hartman

mei: bus: make a client pointer always available

Change life time of the client pointer, allocate it upon client device
creation and free it upon device destruction, instead of upon
connection and disconnection.
This helps to eliminate racy NULL checks in the bus code.
Signed-off-by: NAlexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: NTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 bd47b526
......@@ -187,9 +187,6 @@ ssize_t mei_cldev_send(struct mei_cl_device *cldev, u8 *buf, size_t length)
{
struct mei_cl *cl = cldev->cl;
if (cl == NULL)
return -ENODEV;
return __mei_cl_send(cl, buf, length, MEI_CL_IO_TX_BLOCKING);
}
EXPORT_SYMBOL_GPL(mei_cldev_send);
......@@ -207,9 +204,6 @@ ssize_t mei_cldev_recv(struct mei_cl_device *cldev, u8 *buf, size_t length)
{
struct mei_cl *cl = cldev->cl;
if (cl == NULL)
return -ENODEV;
return __mei_cl_recv(cl, buf, length);
}
EXPORT_SYMBOL_GPL(mei_cldev_recv);
......@@ -403,7 +397,7 @@ EXPORT_SYMBOL_GPL(mei_cldev_ver);
*/
bool mei_cldev_enabled(struct mei_cl_device *cldev)
{
return cldev->cl && mei_cl_is_connected(cldev->cl);
return mei_cl_is_connected(cldev->cl);
}
EXPORT_SYMBOL_GPL(mei_cldev_enabled);
......@@ -423,14 +417,13 @@ int mei_cldev_enable(struct mei_cl_device *cldev)
cl = cldev->cl;
if (!cl) {
if (cl->state == MEI_FILE_UNINITIALIZED) {
mutex_lock(&bus->device_lock);
cl = mei_cl_alloc_linked(bus);
ret = mei_cl_link(cl);
mutex_unlock(&bus->device_lock);
if (IS_ERR(cl))
return PTR_ERR(cl);
if (ret)
return ret;
/* update pointers */
cldev->cl = cl;
cl->cldev = cldev;
}
......@@ -471,7 +464,7 @@ int mei_cldev_disable(struct mei_cl_device *cldev)
struct mei_cl *cl;
int err;
if (!cldev || !cldev->cl)
if (!cldev)
return -ENODEV;
cl = cldev->cl;
......@@ -497,9 +490,6 @@ int mei_cldev_disable(struct mei_cl_device *cldev)
mei_cl_flush_queues(cl, NULL);
mei_cl_unlink(cl);
kfree(cl);
cldev->cl = NULL;
mutex_unlock(&bus->device_lock);
return err;
}
......@@ -754,6 +744,7 @@ static void mei_cl_bus_dev_release(struct device *dev)
mei_me_cl_put(cldev->me_cl);
mei_dev_bus_put(cldev->bus);
kfree(cldev->cl);
kfree(cldev);
}
......@@ -786,17 +777,25 @@ static struct mei_cl_device *mei_cl_bus_dev_alloc(struct mei_device *bus,
struct mei_me_client *me_cl)
{
struct mei_cl_device *cldev;
struct mei_cl *cl;
cldev = kzalloc(sizeof(struct mei_cl_device), GFP_KERNEL);
if (!cldev)
return NULL;
cl = mei_cl_allocate(bus);
if (!cl) {
kfree(cldev);
return NULL;
}
device_initialize(&cldev->dev);
cldev->dev.parent = bus->dev;
cldev->dev.bus = &mei_cl_bus_type;
cldev->dev.type = &mei_cl_device_type;
cldev->bus = mei_dev_bus_get(bus);
cldev->me_cl = mei_me_cl_get(me_cl);
cldev->cl = cl;
mei_cl_bus_set_name(cldev);
cldev->is_added = 0;
INIT_LIST_HEAD(&cldev->bus_list);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册