@@ -449,6 +449,29 @@ bool mei_cldev_enabled(struct mei_cl_device *cldev)
449449}
450450EXPORT_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
494525out :
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
555586out :
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}
563596EXPORT_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 *
0 commit comments