usb: typec: mux: Use device type instead of device name for matching
authorHeikki Krogerus <heikki.krogerus@linux.intel.com>
Wed, 26 May 2021 15:35:47 +0000 (18:35 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 May 2021 07:23:57 +0000 (09:23 +0200)
Both the USB Type-C switch and mux have already a device
type defined for them. We can use those types instead of the
device name to differentiate the two.

Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20210526153548.61276-2-heikki.krogerus@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/mux.c
drivers/usb/typec/mux.h

index 9da22ae..6daf805 100644 (file)
 #include "class.h"
 #include "mux.h"
 
-static bool dev_name_ends_with(struct device *dev, const char *suffix)
-{
-       const char *name = dev_name(dev);
-       const int name_len = strlen(name);
-       const int suffix_len = strlen(suffix);
-
-       if (suffix_len > name_len)
-               return false;
-
-       return strcmp(name + (name_len - suffix_len), suffix) == 0;
-}
-
 static int switch_fwnode_match(struct device *dev, const void *fwnode)
 {
-       return dev_fwnode(dev) == fwnode && dev_name_ends_with(dev, "-switch");
+       if (!is_typec_switch(dev))
+               return 0;
+
+       return dev_fwnode(dev) == fwnode;
 }
 
 static void *typec_switch_match(struct fwnode_handle *fwnode, const char *id,
@@ -90,7 +81,7 @@ static void typec_switch_release(struct device *dev)
        kfree(to_typec_switch(dev));
 }
 
-static const struct device_type typec_switch_dev_type = {
+const struct device_type typec_switch_dev_type = {
        .name = "orientation_switch",
        .release = typec_switch_release,
 };
@@ -180,7 +171,10 @@ EXPORT_SYMBOL_GPL(typec_switch_get_drvdata);
 
 static int mux_fwnode_match(struct device *dev, const void *fwnode)
 {
-       return dev_fwnode(dev) == fwnode && dev_name_ends_with(dev, "-mux");
+       if (!is_typec_mux(dev))
+               return 0;
+
+       return dev_fwnode(dev) == fwnode;
 }
 
 static void *typec_mux_match(struct fwnode_handle *fwnode, const char *id,
@@ -294,7 +288,7 @@ static void typec_mux_release(struct device *dev)
        kfree(to_typec_mux(dev));
 }
 
-static const struct device_type typec_mux_dev_type = {
+const struct device_type typec_mux_dev_type = {
        .name = "mode_switch",
        .release = typec_mux_release,
 };
index 4fd9426..b1d6e83 100644 (file)
@@ -18,4 +18,10 @@ struct typec_mux {
 #define to_typec_switch(_dev_) container_of(_dev_, struct typec_switch, dev)
 #define to_typec_mux(_dev_) container_of(_dev_, struct typec_mux, dev)
 
+extern const struct device_type typec_switch_dev_type;
+extern const struct device_type typec_mux_dev_type;
+
+#define is_typec_switch(dev) ((dev)->type == &typec_switch_dev_type)
+#define is_typec_mux(dev) ((dev)->type == &typec_mux_dev_type)
+
 #endif /* __USB_TYPEC_MUX__ */