Skip to contentSkip to conversation

fpga: bridge: return errors in the show() method of the "state" attribute

PATCH In review Marco Pagani 2 participants 2 messages Jan 25, 2023 – Jan 27, 2023 FPGA manager framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fpga: bridge: return errors in the show() method of the "state" attribute

This patch changes the show() method of the "state" sysfs attribute to propagate errors returned by the enable_show() op. In this way, userspace can distinguish between when the bridge is actually "enabled" (i.e., allowing signals) or "disabled" (i.e., gating signals), or when there is an error.

Currently, enable_show() returns an integer representing the bridge's state (enabled or disabled) or an error code. However, this integer value is interpreted in state_show() as a bool, resulting in the method printing "enabled" (i.e., the bridge allows signals to pass), without propagating the error, even when enable_show() returns an error code.

Thanks

---
 drivers/fpga/fpga-bridge.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/fpga/fpga-bridge.c +7 -4
index 727704431f61..5cd40acab5bf 100644
@@ -293,12 +293,15 @@ static ssize_t state_show(struct device *dev,
 			  struct device_attribute *attr, char *buf)
 {
 	struct fpga_bridge *bridge = to_fpga_bridge(dev);
-	int enable = 1;
+	int state = 1;
 
-	if (bridge->br_ops && bridge->br_ops->enable_show)
-		enable = bridge->br_ops->enable_show(bridge);
+	if (bridge->br_ops && bridge->br_ops->enable_show) {
+		state = bridge->br_ops->enable_show(bridge);
+		if (state < 0)
+			return state;
+	}
 
-	return sprintf(buf, "%s\n", enable ? "enabled" : "disabled");
+	return sysfs_emit(buf, "%s\n", state ? "enabled" : "disabled");
 }
 
 static DEVICE_ATTR_RO(name);
Signature · 1 line
2.39.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Marco Pagani

This patch changes the show() method of the "state" sysfs attribute to propagate errors returned by the enable_show() op. In this way, userspace can distinguish between when the bridge is actually "enabled" (i.e., allowing signals) or "disabled" (i.e., gating signals), or when there is an error.

Quoted 7 lines

Currently, enable_show() returns an integer representing the bridge's state (enabled or disabled) or an error code. However, this integer value is interpreted in state_show() as a bool, resulting in the method printing "enabled" (i.e., the bridge allows signals to pass), without propagating the error, even when enable_show() returns an error code.

Thanks

Removed this line, and applied to for-next.

Quoted 33 lines
---
 drivers/fpga/fpga-bridge.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/fpga/fpga-bridge.c +7 -4
index 727704431f61..5cd40acab5bf 100644
@@ -293,12 +293,15 @@ static ssize_t state_show(struct device *dev,
 			  struct device_attribute *attr, char *buf)
 {
 	struct fpga_bridge *bridge = to_fpga_bridge(dev);
-	int enable = 1;
+	int state = 1;
 
-	if (bridge->br_ops && bridge->br_ops->enable_show)
-		enable = bridge->br_ops->enable_show(bridge);
+	if (bridge->br_ops && bridge->br_ops->enable_show) {
+		state = bridge->br_ops->enable_show(bridge);
+		if (state < 0)
+			return state;
+	}
 
-	return sprintf(buf, "%s\n", enable ? "enabled" : "disabled");
+	return sysfs_emit(buf, "%s\n", state ? "enabled" : "disabled");
 }
 
 static DEVICE_ATTR_RO(name);
Signature · 1 line
2.39.1