Commit 5d882460 authored by Alexander Usyskin's avatar Alexander Usyskin Committed by Greg Kroah-Hartman

mei: bus: prevent hardware module unload if device on bus is active

The hardware module should not be unloaded if the bus
has active devices.
Get get_/put_ bus parent module upon client device
connection/disconnection, to prevent the hardware managing
module to disappear underneath.
Signed-off-by: default avatarAlexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9ecb839f
...@@ -541,6 +541,37 @@ int mei_cldev_disable(struct mei_cl_device *cldev) ...@@ -541,6 +541,37 @@ int mei_cldev_disable(struct mei_cl_device *cldev)
} }
EXPORT_SYMBOL_GPL(mei_cldev_disable); EXPORT_SYMBOL_GPL(mei_cldev_disable);
/**
* mei_cl_bus_module_get - acquire module of the underlying
* hw module.
*
* @cl: host client
*
* Return: true on success; false if the module was removed.
*/
bool mei_cl_bus_module_get(struct mei_cl *cl)
{
struct mei_cl_device *cldev = cl->cldev;
if (!cldev)
return true;
return try_module_get(cldev->bus->dev->driver->owner);
}
/**
* mei_cl_bus_module_put - release the underlying hw module.
*
* @cl: host client
*/
void mei_cl_bus_module_put(struct mei_cl *cl)
{
struct mei_cl_device *cldev = cl->cldev;
if (cldev)
module_put(cldev->bus->dev->driver->owner);
}
/** /**
* mei_cl_device_find - find matching entry in the driver id table * mei_cl_device_find - find matching entry in the driver id table
* *
......
...@@ -774,6 +774,8 @@ static void mei_cl_set_disconnected(struct mei_cl *cl) ...@@ -774,6 +774,8 @@ static void mei_cl_set_disconnected(struct mei_cl *cl)
cl->tx_flow_ctrl_creds = 0; cl->tx_flow_ctrl_creds = 0;
cl->timer_count = 0; cl->timer_count = 0;
mei_cl_bus_module_put(cl);
if (!cl->me_cl) if (!cl->me_cl)
return; return;
...@@ -1077,13 +1079,17 @@ int mei_cl_connect(struct mei_cl *cl, struct mei_me_client *me_cl, ...@@ -1077,13 +1079,17 @@ int mei_cl_connect(struct mei_cl *cl, struct mei_me_client *me_cl,
dev = cl->dev; dev = cl->dev;
if (!mei_cl_bus_module_get(cl))
return -ENODEV;
rets = mei_cl_set_connecting(cl, me_cl); rets = mei_cl_set_connecting(cl, me_cl);
if (rets) if (rets)
return rets; goto nortpm;
if (mei_cl_is_fixed_address(cl)) { if (mei_cl_is_fixed_address(cl)) {
cl->state = MEI_FILE_CONNECTED; cl->state = MEI_FILE_CONNECTED;
return 0; rets = 0;
goto nortpm;
} }
rets = pm_runtime_get(dev->dev); rets = pm_runtime_get(dev->dev);
......
...@@ -328,6 +328,8 @@ ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length, ...@@ -328,6 +328,8 @@ ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length,
bool mei_cl_bus_rx_event(struct mei_cl *cl); bool mei_cl_bus_rx_event(struct mei_cl *cl);
bool mei_cl_bus_notify_event(struct mei_cl *cl); bool mei_cl_bus_notify_event(struct mei_cl *cl);
void mei_cl_bus_remove_devices(struct mei_device *bus); void mei_cl_bus_remove_devices(struct mei_device *bus);
bool mei_cl_bus_module_get(struct mei_cl *cl);
void mei_cl_bus_module_put(struct mei_cl *cl);
int mei_cl_bus_init(void); int mei_cl_bus_init(void);
void mei_cl_bus_exit(void); void mei_cl_bus_exit(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment