Skip to contentSkip to conversation

usb: typec: mux: Fix copy-paste of the container_of

PATCH In review Bjorn Andersson 2 participants 3 messages May 16, 2021 – May 17, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: typec: mux: Fix copy-paste of the container_of

Some of the boilerplate code was copy pasted from the typec_switch and retained the use of the switch's container_of macros. The two structs are identical in this regard, so this change doesn't cause a functional change today, but could possibly cause future issues.

Fixes 3370db35193b ("usb: typec: Registering real device entries for the muxes")
---
 drivers/usb/typec/mux.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/typec/mux.c +3 -3
index 8514bec7e1b8..e4467c4c3742 100644
@@ -45,7 +45,7 @@ static void *typec_switch_match(struct fwnode_handle *fwnode, const char *id,
 	dev = class_find_device(&typec_mux_class, NULL, fwnode,
 				switch_fwnode_match);
 
-	return dev ? to_typec_switch(dev) : ERR_PTR(-EPROBE_DEFER);
+	return dev ? to_typec_mux(dev) : ERR_PTR(-EPROBE_DEFER);
 }
 
 /**
@@ -87,7 +87,7 @@ EXPORT_SYMBOL_GPL(typec_switch_put);
 
 static void typec_switch_release(struct device *dev)
 {
-	kfree(to_typec_switch(dev));
+	kfree(to_typec_mux(dev));
 }
 
 static const struct device_type typec_switch_dev_type = {
@@ -239,7 +239,7 @@ static void *typec_mux_match(struct fwnode_handle *fwnode, const char *id,
 	dev = class_find_device(&typec_mux_class, NULL, fwnode,
 				mux_fwnode_match);
 
-	return dev ? to_typec_switch(dev) : ERR_PTR(-EPROBE_DEFER);
+	return dev ? to_typec_mux(dev) : ERR_PTR(-EPROBE_DEFER);
 }
 
 /**
Signature · 1 line
2.29.2
maintainer
#1 lore raw

Hi,

Quoted 16 lines · Bjorn Andersson

Some of the boilerplate code was copy pasted from the typec_switch and retained the use of the switch's container_of macros. The two structs are identical in this regard, so this change doesn't cause a functional change today, but could possibly cause future issues.

Fixes 3370db35193b ("usb: typec: Registering real device entries for the muxes")
---
 drivers/usb/typec/mux.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/typec/mux.c +0 -0
index 8514bec7e1b8..e4467c4c3742 100644

drivers/usb/typec/mux.c static void *typec_switch_match(struct fwnode_handle *fwnode, const char *id, · line 48

Quoted 5 lines
drivers/usb/typec/mux.c +1 -1
@@ -45,7 +45,7 @@ static void *typec_switch_match(struct fwnode_handle *fwnode, const char *id,
 	dev = class_find_device(&typec_mux_class, NULL, fwnode,
 				switch_fwnode_match);
 
-	return dev ? to_typec_switch(dev) : ERR_PTR(-EPROBE_DEFER);
+	return dev ? to_typec_mux(dev) : ERR_PTR(-EPROBE_DEFER);

That does not look correct to me?

drivers/usb/typec/mux.c EXPORT_SYMBOL_GPL(typec_switch_put); · line 90

Quoted 9 lines
drivers/usb/typec/mux.c +1 -1
 }
 
 /**
@@ -87,7 +87,7 @@ EXPORT_SYMBOL_GPL(typec_switch_put);
 
 static void typec_switch_release(struct device *dev)
 {
-	kfree(to_typec_switch(dev));
+	kfree(to_typec_mux(dev));

Ditto.

drivers/usb/typec/mux.c static void *typec_mux_match(struct fwnode_handle *fwnode, const char *id, · line 242

Quoted 9 lines
drivers/usb/typec/mux.c +1 -1
 }
 
 static const struct device_type typec_switch_dev_type = {
@@ -239,7 +239,7 @@ static void *typec_mux_match(struct fwnode_handle *fwnode, const char *id,
 	dev = class_find_device(&typec_mux_class, NULL, fwnode,
 				mux_fwnode_match);
 
-	return dev ? to_typec_switch(dev) : ERR_PTR(-EPROBE_DEFER);
+	return dev ? to_typec_mux(dev) : ERR_PTR(-EPROBE_DEFER);

That looks correct.

Either I'm missing something, or only the last change is needed.

thanks,

Signature · 1 line
heikki
#2 lore raw
Quoted 22 lines · Heikki Krogerus

Hi,

Quoted 19 lines · Bjorn Andersson

Some of the boilerplate code was copy pasted from the typec_switch and retained the use of the switch's container_of macros. The two structs are identical in this regard, so this change doesn't cause a functional change today, but could possibly cause future issues.

Fixes 3370db35193b ("usb: typec: Registering real device entries for the muxes")
---
 drivers/usb/typec/mux.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/typec/mux.c +0 -0
index 8514bec7e1b8..e4467c4c3742 100644
@@ -45,7 +45,7 @@ static void *typec_switch_match(struct fwnode_handle *fwnode, const char *id,
 	dev = class_find_device(&typec_mux_class, NULL, fwnode,
 				switch_fwnode_match);
 
Quoted 5 lines

drivers/usb/typec/mux.c static void *typec_switch_match(struct fwnode_handle *fwnode, const char *id, · line 48

Quoted 2 lines
drivers/usb/typec/mux.c +1 -1
-	return dev ? to_typec_switch(dev) : ERR_PTR(-EPROBE_DEFER);
+	return dev ? to_typec_mux(dev) : ERR_PTR(-EPROBE_DEFER);

That does not look correct to me?

No it doesn't, you're right. I spotted the last one and it being trivial I obviously didn't pay enough attention when just "fixing" the other two instances of "the same".

Quoted 19 lines

drivers/usb/typec/mux.c EXPORT_SYMBOL_GPL(typec_switch_put); · line 90

Quoted 9 lines
drivers/usb/typec/mux.c +1 -1
 }
 
 /**
@@ -87,7 +87,7 @@ EXPORT_SYMBOL_GPL(typec_switch_put);
 
 static void typec_switch_release(struct device *dev)
 {
-	kfree(to_typec_switch(dev));
+	kfree(to_typec_mux(dev));

Ditto.

Quoted 7 lines
drivers/usb/typec/mux.c +0 -0
 }
 
 static const struct device_type typec_switch_dev_type = {
@@ -239,7 +239,7 @@ static void *typec_mux_match(struct fwnode_handle *fwnode, const char *id,
 	dev = class_find_device(&typec_mux_class, NULL, fwnode,
 				mux_fwnode_match);
 
Quoted 7 lines

drivers/usb/typec/mux.c static void *typec_mux_match(struct fwnode_handle *fwnode, const char *id, · line 242

Quoted 2 lines
drivers/usb/typec/mux.c +1 -1
-	return dev ? to_typec_switch(dev) : ERR_PTR(-EPROBE_DEFER);
+	return dev ? to_typec_mux(dev) : ERR_PTR(-EPROBE_DEFER);

That looks correct.

Either I'm missing something, or only the last change is needed.

Sorry about that, I'll fix it up and repost the patch.

Regards,
Bjorn