Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: typec: retimer: Use device type for matching

Device name is not reliable so using the type instead in
retimer_fwnode_match().

This will also introduce is_typec_retimer() helper, and
remove the static keyword from the retimer device type. That
will make it accessible also in the main typec class.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20221019145552.32493-1-heikki.krogerus@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Heikki Krogerus and committed by
Greg Kroah-Hartman
a84436a9 d182bf15

+6 -14
+2 -14
drivers/usb/typec/retimer.c
··· 17 17 #include "class.h" 18 18 #include "retimer.h" 19 19 20 - static bool dev_name_ends_with(struct device *dev, const char *suffix) 21 - { 22 - const char *name = dev_name(dev); 23 - const int name_len = strlen(name); 24 - const int suffix_len = strlen(suffix); 25 - 26 - if (suffix_len > name_len) 27 - return false; 28 - 29 - return strcmp(name + (name_len - suffix_len), suffix) == 0; 30 - } 31 - 32 20 static int retimer_fwnode_match(struct device *dev, const void *fwnode) 33 21 { 34 - return device_match_fwnode(dev, fwnode) && dev_name_ends_with(dev, "-retimer"); 22 + return is_typec_retimer(dev) && device_match_fwnode(dev, fwnode); 35 23 } 36 24 37 25 static void *typec_retimer_match(struct fwnode_handle *fwnode, const char *id, void *data) ··· 85 97 kfree(to_typec_retimer(dev)); 86 98 } 87 99 88 - static const struct device_type typec_retimer_dev_type = { 100 + const struct device_type typec_retimer_dev_type = { 89 101 .name = "typec_retimer", 90 102 .release = typec_retimer_release, 91 103 };
+4
drivers/usb/typec/retimer.h
··· 12 12 13 13 #define to_typec_retimer(_dev_) container_of(_dev_, struct typec_retimer, dev) 14 14 15 + const struct device_type typec_retimer_dev_type; 16 + 17 + #define is_typec_retimer(dev) ((dev)->type == &typec_retimer_dev_type) 18 + 15 19 #endif /* __USB_TYPEC_RETIMER__ */