From: Gustavo Piaz da Silva <gustavopiazdasilva2102@gmail.com>
To: gregkh@linuxfoundation.org
Cc: dan.carpenter@linaro.org, ovidiu.panait.oss@gmail.com,
gshahrouzi@gmail.com, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org,
Gustavo Piaz da Silva <gustavopiazdasilva2102@gmail.com>
Subject: [PATCH v2] staging: axis-fifo: refactor device tree parsing
Date: Sat, 31 Jan 2026 12:56:30 -0300 [thread overview]
Message-ID: <20260131155630.41587-1-gustavopiazdasilva2102@gmail.com> (raw)
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.
Also change has_rx_fifo and has_tx_fifo types from int to u32 in struct axis_fifo to avoid pointer type mismatch warnings, as of_property_read_u32 expects u32 pointers.
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>
---
Changes in v2:
- Changed has_rx_fifo and has_tx_fifo to u32 in struct axis_fifo to avoid casting.
- Removed goto logic in axis_fifo_parse_dt() to simplify error handling.
- Reverted unrelated changes in axis_fifo_remove().
- Wrapped commit message to 72 characters.
drivers/staging/axis-fifo/axis-fifo.c | 79 +++++++++------------------
1 file changed, 26 insertions(+), 53 deletions(-)
diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c
index 509d620d6ce7..f46cd211d359 100644
--- a/drivers/staging/axis-fifo/axis-fifo.c
+++ b/drivers/staging/axis-fifo/axis-fifo.c
@@ -121,8 +121,8 @@ struct axis_fifo {
unsigned int rx_fifo_depth; /* max words in the receive fifo */
unsigned int tx_fifo_depth; /* max words in the transmit fifo */
- int has_rx_fifo; /* whether the IP has the rx fifo enabled */
- int has_tx_fifo; /* whether the IP has the tx fifo enabled */
+ u32 has_rx_fifo; /* whether the IP has the rx fifo enabled */
+ u32 has_tx_fifo; /* whether the IP has the tx fifo enabled */
wait_queue_head_t read_queue; /* wait queue for asynchronos read */
struct mutex read_lock; /* lock for reading */
@@ -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;
- goto end;
+ if (axis_fifo_get_u32(fifo, "xlnx,axi-str-rxd-tdata-width", &width) || width != 32) {
+ dev_err(fifo->dt_device, "tdata-width only supports 32 bits\n");
+ return -EIO;
}
-
- 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;
- goto end;
+ if (axis_fifo_get_u32(fifo, "xlnx,axi-str-txd-tdata-width", &width) || width != 32) {
+ dev_err(fifo->dt_device, "tdata-width only supports 32 bits\n");
+ return -EIO;
}
- 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", &fifo->has_rx_fifo))
+ return -EIO;
+ if (axis_fifo_get_u32(fifo, "xlnx,use-tx-data", &fifo->has_tx_fifo))
+ return -EIO;
-end:
- return ret;
+ return 0;
}
static int axis_fifo_probe(struct platform_device *pdev)
--
2.52.0
next reply other threads:[~2026-01-31 15:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-31 15:56 Gustavo Piaz da Silva [this message]
2026-01-31 17:41 ` [PATCH v2] staging: axis-fifo: refactor device tree parsing Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260131155630.41587-1-gustavopiazdasilva2102@gmail.com \
--to=gustavopiazdasilva2102@gmail.com \
--cc=dan.carpenter@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=gshahrouzi@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=ovidiu.panait.oss@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox