* [PATCH] fpga: bridge: return errors in the show() method of the "state" attribute
@ 2023-01-25 14:06 Marco Pagani
2023-01-27 14:03 ` Xu Yilun
0 siblings, 1 reply; 2+ messages in thread
From: Marco Pagani @ 2023-01-25 14:06 UTC (permalink / raw)
To: Moritz Fischer, Wu Hao, Xu Yilun, Tom Rix
Cc: Marco Pagani, linux-fpga, linux-kernel
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
Signed-off-by: Marco Pagani <marpagan@redhat.com>
---
drivers/fpga/fpga-bridge.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c
index 727704431f61..5cd40acab5bf 100644
--- a/drivers/fpga/fpga-bridge.c
+++ b/drivers/fpga/fpga-bridge.c
@@ -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);
--
2.39.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] fpga: bridge: return errors in the show() method of the "state" attribute
2023-01-25 14:06 [PATCH] fpga: bridge: return errors in the show() method of the "state" attribute Marco Pagani
@ 2023-01-27 14:03 ` Xu Yilun
0 siblings, 0 replies; 2+ messages in thread
From: Xu Yilun @ 2023-01-27 14:03 UTC (permalink / raw)
To: Marco Pagani; +Cc: Moritz Fischer, Wu Hao, Tom Rix, linux-fpga, linux-kernel
On 2023-01-25 at 15:06:22 +0100, Marco Pagani wrote:
> 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
Removed this line, and applied to for-next.
Acked-by: Xu Yilun <yilun.xu@intel.com>
>
> Signed-off-by: Marco Pagani <marpagan@redhat.com>
> ---
> drivers/fpga/fpga-bridge.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c
> index 727704431f61..5cd40acab5bf 100644
> --- a/drivers/fpga/fpga-bridge.c
> +++ b/drivers/fpga/fpga-bridge.c
> @@ -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);
> --
> 2.39.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-01-27 14:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-25 14:06 [PATCH] fpga: bridge: return errors in the show() method of the "state" attribute Marco Pagani
2023-01-27 14:03 ` Xu Yilun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).