]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
greybus: protocol: warn on bad deregistration
authorJohan Hovold <johan@hovoldconsulting.com>
Tue, 13 Oct 2015 17:10:24 +0000 (19:10 +0200)
committerGreg Kroah-Hartman <gregkh@google.com>
Wed, 14 Oct 2015 19:06:00 +0000 (12:06 -0700)
A protocol should be deregistered exactly once when the protocol module
is being unloaded. This means that protocol deregister will never be
called with active users as we take a module reference when looking up a
protocol.

Remove comment suggesting that we could one day forcefully stop a user
of a protocol, and issue a big warning if a protocol is deregistered
more than once or at some other time than during module unload (e.g.
with active users).

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/protocol.c
drivers/staging/greybus/protocol.h

index c93f963656674b5a82ee8697b6efc5250f10ee7e..140baa68546980f865849f5918c2b8e47ae2729f 100644 (file)
@@ -102,36 +102,24 @@ EXPORT_SYMBOL_GPL(__gb_protocol_register);
 
 /*
  * De-register a previously registered protocol.
- *
- * XXX Currently this fails (and reports an error to the caller) if
- * XXX the protocol is currently in use.  We may want to forcefully
- * XXX kill off a protocol and all its active users at some point.
- * XXX But I think that's better handled by quiescing modules that
- * XXX have users and having those users drop their reference.
- *
- * Returns true if successful, false otherwise.
  */
-int gb_protocol_deregister(struct gb_protocol *protocol)
+void gb_protocol_deregister(struct gb_protocol *protocol)
 {
-       u8 protocol_count = 0;
-
        if (!protocol)
-               return 0;
+               return;
 
        spin_lock_irq(&gb_protocols_lock);
        protocol = gb_protocol_find(protocol->id, protocol->major,
                                    protocol->minor);
-       if (protocol) {
-               protocol_count = protocol->count;
-               if (!protocol_count)
-                       list_del(&protocol->links);
+       if (WARN_ON(!protocol || protocol->count)) {
+               spin_unlock_irq(&gb_protocols_lock);
+               return;
        }
-       spin_unlock_irq(&gb_protocols_lock);
 
-       if (protocol)
-               pr_info("Deregistered %s protocol.\n", protocol->name);
+       list_del(&protocol->links);
+       spin_unlock_irq(&gb_protocols_lock);
 
-       return protocol && !protocol_count;
+       pr_info("Deregistered %s protocol.\n", protocol->name);
 }
 EXPORT_SYMBOL_GPL(gb_protocol_deregister);
 
index d856885a89e1f2f83c407e292bb594df618b8ab5..2e0f4d667897a72427ab50b9eb567a928546ac00 100644 (file)
@@ -46,7 +46,7 @@ struct gb_protocol {
 };
 
 int __gb_protocol_register(struct gb_protocol *protocol, struct module *module);
-int gb_protocol_deregister(struct gb_protocol *protocol);
+void gb_protocol_deregister(struct gb_protocol *protocol);
 
 #define gb_protocol_register(protocol) \
        __gb_protocol_register(protocol, THIS_MODULE)