From: Rosen Penev <rosenp@gmail.com>
To: dmaengine@vger.kernel.org
Cc: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] dmaengine: mv_xor_v2: simplify allocation
Date: Mon, 6 Apr 2026 20:52:45 -0700 [thread overview]
Message-ID: <20260407035245.99145-1-rosenp@gmail.com> (raw)
Use a flexible array member to create a single allocation of sw_desq and
xor_dev.
Move mv_xor_v2_sw_desc definition above as flexible array members
require a full definition compared to pointers.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/dma/mv_xor_v2.c | 43 ++++++++++++++++-------------------------
1 file changed, 17 insertions(+), 26 deletions(-)
diff --git a/drivers/dma/mv_xor_v2.c b/drivers/dma/mv_xor_v2.c
index cad4d4fb51ac..4c4d627ef991 100644
--- a/drivers/dma/mv_xor_v2.c
+++ b/drivers/dma/mv_xor_v2.c
@@ -132,6 +132,20 @@ struct mv_xor_v2_descriptor {
u32 reserved[MV_XOR_V2_DESC_RESERVED_SIZE];
};
+/**
+ * struct mv_xor_v2_sw_desc - implements a xor SW descriptor
+ * @idx: descriptor index
+ * @async_tx: support for the async_tx api
+ * @hw_desc: associated HW descriptor
+ * @free_list: node of the free SW descriprots list
+*/
+struct mv_xor_v2_sw_desc {
+ int idx;
+ struct dma_async_tx_descriptor async_tx;
+ struct mv_xor_v2_descriptor hw_desc;
+ struct list_head free_list;
+};
+
/**
* struct mv_xor_v2_device - implements a xor device
* @lock: lock for the engine
@@ -164,25 +178,11 @@ struct mv_xor_v2_device {
struct dma_chan dmachan;
dma_addr_t hw_desq;
struct mv_xor_v2_descriptor *hw_desq_virt;
- struct mv_xor_v2_sw_desc *sw_desq;
int desc_size;
unsigned int npendings;
unsigned int hw_queue_idx;
unsigned int irq;
-};
-
-/**
- * struct mv_xor_v2_sw_desc - implements a xor SW descriptor
- * @idx: descriptor index
- * @async_tx: support for the async_tx api
- * @hw_desc: associated HW descriptor
- * @free_list: node of the free SW descriprots list
-*/
-struct mv_xor_v2_sw_desc {
- int idx;
- struct dma_async_tx_descriptor async_tx;
- struct mv_xor_v2_descriptor hw_desc;
- struct list_head free_list;
+ struct mv_xor_v2_sw_desc sw_desq[];
};
/*
@@ -716,12 +716,12 @@ static int mv_xor_v2_probe(struct platform_device *pdev)
struct mv_xor_v2_device *xor_dev;
int i, ret = 0;
struct dma_device *dma_dev;
- struct mv_xor_v2_sw_desc *sw_desc;
BUILD_BUG_ON(sizeof(struct mv_xor_v2_descriptor) !=
MV_XOR_V2_EXT_DESC_SIZE);
- xor_dev = devm_kzalloc(&pdev->dev, sizeof(*xor_dev), GFP_KERNEL);
+ xor_dev = devm_kzalloc(&pdev->dev, struct_size(xor_dev, sw_desq,
+ MV_XOR_V2_DESC_NUM), GFP_KERNEL);
if (!xor_dev)
return -ENOMEM;
@@ -780,15 +780,6 @@ static int mv_xor_v2_probe(struct platform_device *pdev)
goto free_msi_irqs;
}
- /* alloc memory for the SW descriptors */
- xor_dev->sw_desq = devm_kcalloc(&pdev->dev,
- MV_XOR_V2_DESC_NUM, sizeof(*sw_desc),
- GFP_KERNEL);
- if (!xor_dev->sw_desq) {
- ret = -ENOMEM;
- goto free_hw_desq;
- }
-
spin_lock_init(&xor_dev->lock);
/* init the free SW descriptors list */
--
2.53.0
reply other threads:[~2026-04-07 3:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260407035245.99145-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vkoul@kernel.org \
/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