fpga: bridge: return errors in the show() method of the "state" attribute
RFC 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 return an error if the bridge's enable_show() op returns an error code. In this way, the userspace can distinguish between when the bridge is actually "enabled" (i.e., allowing signals to pass) or "disabled" (i.e., gating signals), or when there is an error (e.g., the state of the bridge cannot be determined).
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.
Another possibility could be to change the signature of enable_show() to return a bool for symmetry with the enable_set() "setter" method. However, this would prevent enable_show() from returning error codes and may break the HPS bridge driver (altera-hps2fpga.c +53).
Thanks
--- drivers/fpga/fpga-bridge.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/fpga/fpga-bridge.c +7 -4
@@ -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
Xu Yilun
maintainerQuoted 6 lines · Marco Pagani
This patch changes the
show()method of the "state" sysfs attribute to return an error if the bridge'senable_show()op returns an error code. In this way, the userspace can distinguish between when the bridge is actually "enabled" (i.e., allowing signals to pass) or "disabled" (i.e., gating signals), or when there is an error (e.g., the state of the bridge cannot be determined).
Maybe we remove the example for "error" here. This patch is just to propagate the errors from low level drivers.
Quoted 10 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 instate_show()as a bool, resulting in the method printing "enabled" (i.e., the bridge allows signals to pass), without propagating the error, even whenenable_show()returns an error code.Another possibility could be to change the signature of
enable_show()to return a bool for symmetry with theenable_set()"setter" method. However, this would preventenable_show()from returning error codes
Returning error codes is good to me.
Quoted 20 lines
and may break the HPS bridge driver (
altera-hps2fpga.c+53).Thanks
Signed-off-by Marco Pagani <[email protected]>--- drivers/fpga/fpga-bridge.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)drivers/fpga/fpga-bridge.c +1
-1@@ -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 ;
drivers/fpga/fpga-bridge.c static ssize_t state_show(struct device *dev, · line 304
Quoted 10 lines
drivers/fpga/fpga-bridge.c +6
-3-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" );
The code looks good to me. You may remove RFC prefix in next version.
Thanks,
Yilun
Quoted 6 lines
drivers/fpga/fpga-bridge.c +0
-0}static DEVICE_ATTR_RO (name);Signature · 1 line
2.39.1