fpga: bridge: return errors in the show() method of the "state" attribute
authorMarco Pagani <marpagan@redhat.com>
Wed, 25 Jan 2023 14:06:22 +0000 (15:06 +0100)
committerXu Yilun <yilun.xu@intel.com>
Sat, 28 Jan 2023 15:34:06 +0000 (23:34 +0800)
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.

Signed-off-by: Marco Pagani <marpagan@redhat.com>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20230125140622.176870-1-marpagan@redhat.com
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
drivers/fpga/fpga-bridge.c

index 727704431f618411a4172842a4e81b2ce4f39c56..5cd40acab5bfb85f52302ea244c2906af1213f1f 100644 (file)
@@ -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);