Skip to contentSkip to conversation

usb: typec: tipd: Fix error handling in cd321x_read_data_status

PATCH In review Sven Peter 2 participants 2 messages Sep 20, 2025 – Sep 22, 2025

Subsystems (2)
lore
Share & tools
lore

Sven Peter

author
#0 lore raw

PATCH 1/1 usb: typec: tipd: Fix error handling in cd321x_read_data_status

Right now cd321x_read_data_status always returns true even if it encounters any errors: tps6598x_read_data_status returns a boolean but we treated it as an errno and then we have a bunch of dev_errs in case tps6598x_block_read fails but just continue along and return true. Fix that to correctly report errors to the callee.

---
 drivers/usb/typec/tipd/core.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/usb/typec/tipd/core.c +10 -4
index 2b1049c9a6f3c4300f4a25a97fe502c47e82a134..d0c86347251c5cc19a9b377550c00c27966f8329 100644
@@ -577,30 +577,36 @@ static bool cd321x_read_data_status(struct tps6598x *tps)
 	int ret;
 
 	ret = tps6598x_read_data_status(tps);
-	if (ret < 0)
+	if (!ret)
 		return false;
 
 	if (tps->data_status & TPS_DATA_STATUS_DP_CONNECTION) {
 		ret = tps6598x_block_read(tps, TPS_REG_DP_SID_STATUS,
 				&cd321x->dp_sid_status, sizeof(cd321x->dp_sid_status));
-		if (ret)
+		if (ret) {
 			dev_err(tps->dev, "Failed to read DP SID Status: %d\n",
 				ret);
+			return false;
+		}
 	}
 
 	if (tps->data_status & TPS_DATA_STATUS_TBT_CONNECTION) {
 		ret = tps6598x_block_read(tps, TPS_REG_INTEL_VID_STATUS,
 				&cd321x->intel_vid_status, sizeof(cd321x->intel_vid_status));
-		if (ret)
+		if (ret) {
 			dev_err(tps->dev, "Failed to read Intel VID Status: %d\n", ret);
+			return false;
+		}
 	}
 
 	if (tps->data_status & CD321X_DATA_STATUS_USB4_CONNECTION) {
 		ret = tps6598x_block_read(tps, TPS_REG_USB4_STATUS,
 				&cd321x->usb4_status, sizeof(cd321x->usb4_status));
-		if (ret)
+		if (ret) {
 			dev_err(tps->dev,
 				"Failed to read USB4 Status: %d\n", ret);
+			return false;
+		}
 	}
 
 	return true;

---
base-commit: a4e143636d5def935dd461539b67b61287a8dfef
change-id: 20250920-tipd-fix-0c50f9f99a5a

Best regards,

Signature · 1 line
Sven Peter <[email protected]>
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Sven Peter

Right now cd321x_read_data_status always returns true even if it encounters any errors: tps6598x_read_data_status returns a boolean but we treated it as an errno and then we have a bunch of dev_errs in case tps6598x_block_read fails but just continue along and return true. Fix that to correctly report errors to the callee.

Quoted 58 lines
---
 drivers/usb/typec/tipd/core.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/usb/typec/tipd/core.c +10 -5
index 2b1049c9a6f3c4300f4a25a97fe502c47e82a134..d0c86347251c5cc19a9b377550c00c27966f8329 100644
@@ -577,30 +577,36 @@ static bool cd321x_read_data_status(struct tps6598x *tps)
 	int ret;
 
 	ret = tps6598x_read_data_status(tps);
-	if (ret < 0)
+	if (!ret)
 		return false;
 
 	if (tps->data_status & TPS_DATA_STATUS_DP_CONNECTION) {
 		ret = tps6598x_block_read(tps, TPS_REG_DP_SID_STATUS,
 				&cd321x->dp_sid_status, sizeof(cd321x->dp_sid_status));
-		if (ret)
+		if (ret) {
 			dev_err(tps->dev, "Failed to read DP SID Status: %d\n",
 				ret);
+			return false;
+		}
 	}
 
 	if (tps->data_status & TPS_DATA_STATUS_TBT_CONNECTION) {
 		ret = tps6598x_block_read(tps, TPS_REG_INTEL_VID_STATUS,
 				&cd321x->intel_vid_status, sizeof(cd321x->intel_vid_status));
-		if (ret)
+		if (ret) {
 			dev_err(tps->dev, "Failed to read Intel VID Status: %d\n", ret);
+			return false;
+		}
 	}
 
 	if (tps->data_status & CD321X_DATA_STATUS_USB4_CONNECTION) {
 		ret = tps6598x_block_read(tps, TPS_REG_USB4_STATUS,
 				&cd321x->usb4_status, sizeof(cd321x->usb4_status));
-		if (ret)
+		if (ret) {
 			dev_err(tps->dev,
 				"Failed to read USB4 Status: %d\n", ret);
+			return false;
+		}
 	}
 
 	return true;
 
---

base-commit: a4e143636d5def935dd461539b67b61287a8dfef
change-id: 20250920-tipd-fix-0c50f9f99a5a

Best regards,

Signature · 1 line
Sven Peter <[email protected]>
Signature · 1 line
heikki