Skip to content

Commit 257355a

Browse files
Tomas Winklergregkh
authored andcommitted
mei: make module referencing local to the bus.c
Module reference counting is relevant only to the mei client devices. Make the implementation clean and move it to bus.c Signed-off-by: Tomas Winkler <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent bb47944 commit 257355a

File tree

3 files changed

+34
-39
lines changed

3 files changed

+34
-39
lines changed

drivers/misc/mei/bus.c

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,29 @@ bool mei_cldev_enabled(struct mei_cl_device *cldev)
449449
}
450450
EXPORT_SYMBOL_GPL(mei_cldev_enabled);
451451

452+
/**
453+
* mei_cl_bus_module_get - acquire module of the underlying
454+
* hw driver.
455+
*
456+
* @cldev: mei client device
457+
*
458+
* Return: true on success; false if the module was removed.
459+
*/
460+
static bool mei_cl_bus_module_get(struct mei_cl_device *cldev)
461+
{
462+
return try_module_get(cldev->bus->dev->driver->owner);
463+
}
464+
465+
/**
466+
* mei_cl_bus_module_put - release the underlying hw module.
467+
*
468+
* @cldev: mei client device
469+
*/
470+
static void mei_cl_bus_module_put(struct mei_cl_device *cldev)
471+
{
472+
module_put(cldev->bus->dev->driver->owner);
473+
}
474+
452475
/**
453476
* mei_cldev_enable - enable me client device
454477
* create connection with me client
@@ -487,9 +510,17 @@ int mei_cldev_enable(struct mei_cl_device *cldev)
487510
goto out;
488511
}
489512

513+
if (!mei_cl_bus_module_get(cldev)) {
514+
dev_err(&cldev->dev, "get hw module failed");
515+
ret = -ENODEV;
516+
goto out;
517+
}
518+
490519
ret = mei_cl_connect(cl, cldev->me_cl, NULL);
491-
if (ret < 0)
520+
if (ret < 0) {
492521
dev_err(&cldev->dev, "cannot connect\n");
522+
mei_cl_bus_module_put(cldev);
523+
}
493524

494525
out:
495526
mutex_unlock(&bus->device_lock);
@@ -553,6 +584,8 @@ int mei_cldev_disable(struct mei_cl_device *cldev)
553584
dev_err(bus->dev, "Could not disconnect from the ME client\n");
554585

555586
out:
587+
mei_cl_bus_module_put(cldev);
588+
556589
/* Flush queues and remove any pending read */
557590
mei_cl_flush_queues(cl, NULL);
558591
mei_cl_unlink(cl);
@@ -562,37 +595,6 @@ int mei_cldev_disable(struct mei_cl_device *cldev)
562595
}
563596
EXPORT_SYMBOL_GPL(mei_cldev_disable);
564597

565-
/**
566-
* mei_cl_bus_module_get - acquire module of the underlying
567-
* hw module.
568-
*
569-
* @cl: host client
570-
*
571-
* Return: true on success; false if the module was removed.
572-
*/
573-
bool mei_cl_bus_module_get(struct mei_cl *cl)
574-
{
575-
struct mei_cl_device *cldev = cl->cldev;
576-
577-
if (!cldev)
578-
return true;
579-
580-
return try_module_get(cldev->bus->dev->driver->owner);
581-
}
582-
583-
/**
584-
* mei_cl_bus_module_put - release the underlying hw module.
585-
*
586-
* @cl: host client
587-
*/
588-
void mei_cl_bus_module_put(struct mei_cl *cl)
589-
{
590-
struct mei_cl_device *cldev = cl->cldev;
591-
592-
if (cldev)
593-
module_put(cldev->bus->dev->driver->owner);
594-
}
595-
596598
/**
597599
* mei_cl_device_find - find matching entry in the driver id table
598600
*

drivers/misc/mei/client.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,6 @@ static void mei_cl_set_disconnected(struct mei_cl *cl)
765765
cl->tx_flow_ctrl_creds = 0;
766766
cl->timer_count = 0;
767767

768-
mei_cl_bus_module_put(cl);
769-
770768
if (!cl->me_cl)
771769
return;
772770

@@ -1076,9 +1074,6 @@ int mei_cl_connect(struct mei_cl *cl, struct mei_me_client *me_cl,
10761074

10771075
dev = cl->dev;
10781076

1079-
if (!mei_cl_bus_module_get(cl))
1080-
return -ENODEV;
1081-
10821077
rets = mei_cl_set_connecting(cl, me_cl);
10831078
if (rets)
10841079
goto nortpm;

drivers/misc/mei/mei_dev.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,6 @@ ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length,
315315
bool mei_cl_bus_rx_event(struct mei_cl *cl);
316316
bool mei_cl_bus_notify_event(struct mei_cl *cl);
317317
void mei_cl_bus_remove_devices(struct mei_device *bus);
318-
bool mei_cl_bus_module_get(struct mei_cl *cl);
319-
void mei_cl_bus_module_put(struct mei_cl *cl);
320318
int mei_cl_bus_init(void);
321319
void mei_cl_bus_exit(void);
322320

0 commit comments

Comments
 (0)