Skip to contentSkip to conversation

usb: typec: silence a static checker warning

PATCH In review Dan Carpenter 2 participants 2 messages Apr 14, 2021

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

PATCH 1/1 usb: typec: silence a static checker warning

Smatch complains about a potential missing error code:

drivers/usb/typec/port-mapper.c:168 typec_link_port()
warn: missing error code 'ret'

This is a false positive and returning zero is intentional. Let's re-arrange the code to silence the warning and make the intent more clear.

---
 drivers/usb/typec/port-mapper.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/typec/port-mapper.c +4 -2
index fae736eb0601..9b0991bdf391 100644
@@ -157,15 +157,17 @@ int typec_link_port(struct device *port)
 {
 	struct device *connector;
 	struct port_node *node;
-	int ret = 0;
+	int ret;
 
 	node = create_port_node(port);
 	if (IS_ERR(node))
 		return PTR_ERR(node);
 
 	connector = find_connector(node);
-	if (!connector)
+	if (!connector) {
+		ret = 0;
 		goto remove_node;
+	}
 
 	ret = link_port(to_typec_port(connector), node);
 	if (ret)
Signature · 1 line
2.30.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Dan Carpenter

Smatch complains about a potential missing error code:

drivers/usb/typec/port-mapper.c:168 typec_link_port()
warn: missing error code 'ret'

This is a false positive and returning zero is intentional. Let's re-arrange the code to silence the warning and make the intent more clear.

Quoted 30 lines
---
 drivers/usb/typec/port-mapper.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/typec/port-mapper.c +4 -2
index fae736eb0601..9b0991bdf391 100644
@@ -157,15 +157,17 @@ int typec_link_port(struct device *port)
 {
 	struct device *connector;
 	struct port_node *node;
-	int ret = 0;
+	int ret;
 
 	node = create_port_node(port);
 	if (IS_ERR(node))
 		return PTR_ERR(node);
 
 	connector = find_connector(node);
-	if (!connector)
+	if (!connector) {
+		ret = 0;
 		goto remove_node;
+	}
 
 	ret = link_port(to_typec_port(connector), node);
 	if (ret)
Signature · 1 line
2.30.2

thanks,

Signature · 1 line
heikki