drivers/staging/axis-fifo/axis-fifo.c | 76 +++++++++------------------ 1 file changed, 24 insertions(+), 52 deletions(-)
Refactor the device tree parsing logic in axis_fifo_probe() to reduce code duplication and improve readability.
Create a helper function axis_fifo_get_u32() to handle property reading and error checking, replacing repetitive of_property_read_u32() calls.
This change reduces the verbosity of the probe function and consolidates error logging for missing properties.
Signed-off-by: Gustavo Piaz da Silva <gustavopiazdasilva2102@gmail.com>
---
drivers/staging/axis-fifo/axis-fifo.c | 76 +++++++++------------------
1 file changed, 24 insertions(+), 52 deletions(-)
diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c
index 509d620d6ce7..258bb95f03d4 100644
--- a/drivers/staging/axis-fifo/axis-fifo.c
+++ b/drivers/staging/axis-fifo/axis-fifo.c
@@ -482,68 +482,41 @@ static void axis_fifo_debugfs_init(struct axis_fifo *fifo)
&axis_fifo_debugfs_regs_fops);
}
-static int axis_fifo_parse_dt(struct axis_fifo *fifo)
+static int axis_fifo_get_u32(struct axis_fifo *fifo, const char *prop, u32 *val)
{
- int ret;
- unsigned int value;
- struct device_node *node = fifo->dt_device->of_node;
+ int ret = of_property_read_u32(fifo->dt_device->of_node, prop, val);
- ret = of_property_read_u32(node, "xlnx,axi-str-rxd-tdata-width",
- &value);
if (ret) {
- dev_err(fifo->dt_device, "missing xlnx,axi-str-rxd-tdata-width property\n");
- goto end;
- } else if (value != 32) {
- dev_err(fifo->dt_device, "xlnx,axi-str-rxd-tdata-width only supports 32 bits\n");
- ret = -EIO;
- goto end;
+ dev_err(fifo->dt_device, "missing %s property\n", prop);
+ return ret;
}
+ return 0;
+}
- ret = of_property_read_u32(node, "xlnx,axi-str-txd-tdata-width",
- &value);
- if (ret) {
- dev_err(fifo->dt_device, "missing xlnx,axi-str-txd-tdata-width property\n");
- goto end;
- } else if (value != 32) {
- dev_err(fifo->dt_device, "xlnx,axi-str-txd-tdata-width only supports 32 bits\n");
- ret = -EIO;
- goto end;
- }
+static int axis_fifo_parse_dt(struct axis_fifo *fifo)
+{
+ u32 width;
- ret = of_property_read_u32(node, "xlnx,rx-fifo-depth",
- &fifo->rx_fifo_depth);
- if (ret) {
- dev_err(fifo->dt_device, "missing xlnx,rx-fifo-depth property\n");
- ret = -EIO;
+ if (axis_fifo_get_u32(fifo, "xlnx,axi-str-rxd-tdata-width", &width) || width != 32)
goto end;
- }
-
- ret = of_property_read_u32(node, "xlnx,tx-fifo-depth",
- &fifo->tx_fifo_depth);
- if (ret) {
- dev_err(fifo->dt_device, "missing xlnx,tx-fifo-depth property\n");
- ret = -EIO;
+ if (axis_fifo_get_u32(fifo, "xlnx,axi-str-txd-tdata-width", &width) || width != 32)
goto end;
- }
- ret = of_property_read_u32(node, "xlnx,use-rx-data",
- &fifo->has_rx_fifo);
- if (ret) {
- dev_err(fifo->dt_device, "missing xlnx,use-rx-data property\n");
- ret = -EIO;
- goto end;
- }
+ if (axis_fifo_get_u32(fifo, "xlnx,rx-fifo-depth", &fifo->rx_fifo_depth))
+ return -EIO;
+ if (axis_fifo_get_u32(fifo, "xlnx,tx-fifo-depth", &fifo->tx_fifo_depth))
+ return -EIO;
- ret = of_property_read_u32(node, "xlnx,use-tx-data",
- &fifo->has_tx_fifo);
- if (ret) {
- dev_err(fifo->dt_device, "missing xlnx,use-tx-data property\n");
- ret = -EIO;
- goto end;
- }
+ if (axis_fifo_get_u32(fifo, "xlnx,use-rx-data", (u32 *)&fifo->has_rx_fifo))
+ return -EIO;
+ if (axis_fifo_get_u32(fifo, "xlnx,use-tx-data", (u32 *)&fifo->has_tx_fifo))
+ return -EIO;
+
+ return 0;
end:
- return ret;
+ dev_err(fifo->dt_device, "tdata-width only supports 32 bits\n");
+ return -EIO;
}
static int axis_fifo_probe(struct platform_device *pdev)
@@ -646,8 +619,7 @@ static int axis_fifo_probe(struct platform_device *pdev)
static void axis_fifo_remove(struct platform_device *pdev)
{
- struct device *dev = &pdev->dev;
- struct axis_fifo *fifo = dev_get_drvdata(dev);
+ struct axis_fifo *fifo = platform_get_drvdata(pdev);
debugfs_remove(fifo->debugfs_dir);
misc_deregister(&fifo->miscdev);
--
2.52.0
On Sat, Jan 31, 2026 at 11:05:17AM -0300, Gustavo Piaz da Silva wrote:
> Refactor the device tree parsing logic in axis_fifo_probe() to reduce code duplication and improve readability.
>
> Create a helper function axis_fifo_get_u32() to handle property reading and error checking, replacing repetitive of_property_read_u32() calls.
>
> This change reduces the verbosity of the probe function and consolidates error logging for missing properties.
>
Line wrap the commit message at 72 characters.
> Signed-off-by: Gustavo Piaz da Silva <gustavopiazdasilva2102@gmail.com>
> ---
> drivers/staging/axis-fifo/axis-fifo.c | 76 +++++++++------------------
> 1 file changed, 24 insertions(+), 52 deletions(-)
>
> diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c
> index 509d620d6ce7..258bb95f03d4 100644
> --- a/drivers/staging/axis-fifo/axis-fifo.c
> +++ b/drivers/staging/axis-fifo/axis-fifo.c
> @@ -482,68 +482,41 @@ static void axis_fifo_debugfs_init(struct axis_fifo *fifo)
> &axis_fifo_debugfs_regs_fops);
> }
>
> -static int axis_fifo_parse_dt(struct axis_fifo *fifo)
> +static int axis_fifo_get_u32(struct axis_fifo *fifo, const char *prop, u32 *val)
> {
> - int ret;
> - unsigned int value;
> - struct device_node *node = fifo->dt_device->of_node;
> + int ret = of_property_read_u32(fifo->dt_device->of_node, prop, val);
>
> - ret = of_property_read_u32(node, "xlnx,axi-str-rxd-tdata-width",
> - &value);
> if (ret) {
> - dev_err(fifo->dt_device, "missing xlnx,axi-str-rxd-tdata-width property\n");
> - goto end;
> - } else if (value != 32) {
> - dev_err(fifo->dt_device, "xlnx,axi-str-rxd-tdata-width only supports 32 bits\n");
> - ret = -EIO;
> - goto end;
> + dev_err(fifo->dt_device, "missing %s property\n", prop);
> + return ret;
> }
> + return 0;
> +}
>
> - ret = of_property_read_u32(node, "xlnx,axi-str-txd-tdata-width",
> - &value);
> - if (ret) {
> - dev_err(fifo->dt_device, "missing xlnx,axi-str-txd-tdata-width property\n");
> - goto end;
> - } else if (value != 32) {
> - dev_err(fifo->dt_device, "xlnx,axi-str-txd-tdata-width only supports 32 bits\n");
> - ret = -EIO;
> - goto end;
> - }
> +static int axis_fifo_parse_dt(struct axis_fifo *fifo)
> +{
> + u32 width;
>
> - ret = of_property_read_u32(node, "xlnx,rx-fifo-depth",
> - &fifo->rx_fifo_depth);
> - if (ret) {
> - dev_err(fifo->dt_device, "missing xlnx,rx-fifo-depth property\n");
> - ret = -EIO;
> + if (axis_fifo_get_u32(fifo, "xlnx,axi-str-rxd-tdata-width", &width) || width != 32)
> goto end;
> - }
> -
> - ret = of_property_read_u32(node, "xlnx,tx-fifo-depth",
> - &fifo->tx_fifo_depth);
> - if (ret) {
> - dev_err(fifo->dt_device, "missing xlnx,tx-fifo-depth property\n");
> - ret = -EIO;
> + if (axis_fifo_get_u32(fifo, "xlnx,axi-str-txd-tdata-width", &width) || width != 32)
> goto end;
This goto end stuff is weird. I get why you did it (because the error
message is the same both times). But it's like I have to think about
why these have a goto and the others are direct returns and I don't like
that. I think I probably would have just changed the strings to be
slightly different which solves the problem in a different way.
> - }
>
> - ret = of_property_read_u32(node, "xlnx,use-rx-data",
> - &fifo->has_rx_fifo);
> - if (ret) {
> - dev_err(fifo->dt_device, "missing xlnx,use-rx-data property\n");
> - ret = -EIO;
> - goto end;
> - }
> + if (axis_fifo_get_u32(fifo, "xlnx,rx-fifo-depth", &fifo->rx_fifo_depth))
> + return -EIO;
> + if (axis_fifo_get_u32(fifo, "xlnx,tx-fifo-depth", &fifo->tx_fifo_depth))
> + return -EIO;
>
> - ret = of_property_read_u32(node, "xlnx,use-tx-data",
> - &fifo->has_tx_fifo);
> - if (ret) {
> - dev_err(fifo->dt_device, "missing xlnx,use-tx-data property\n");
> - ret = -EIO;
> - goto end;
> - }
> + if (axis_fifo_get_u32(fifo, "xlnx,use-rx-data", (u32 *)&fifo->has_rx_fifo))
> + return -EIO;
> + if (axis_fifo_get_u32(fifo, "xlnx,use-tx-data", (u32 *)&fifo->has_tx_fifo))
> + return -EIO;
These casts weren't there in the original code. I hate these casts.
We could just change the type from int to u32. Or we could leave the
casts out like the original code did.
> +
> + return 0;
>
> end:
> - return ret;
> + dev_err(fifo->dt_device, "tdata-width only supports 32 bits\n");
> + return -EIO;
> }
>
> static int axis_fifo_probe(struct platform_device *pdev)
> @@ -646,8 +619,7 @@ static int axis_fifo_probe(struct platform_device *pdev)
>
> static void axis_fifo_remove(struct platform_device *pdev)
> {
> - struct device *dev = &pdev->dev;
> - struct axis_fifo *fifo = dev_get_drvdata(dev);
> + struct axis_fifo *fifo = platform_get_drvdata(pdev);
This is unrelated.
regards,
dan carpenter
>
> debugfs_remove(fifo->debugfs_dir);
> misc_deregister(&fifo->miscdev);
> --
> 2.52.0
>
© 2016 - 2026 Red Hat, Inc.