From: Thorsten Blum <blum@kernel.org>
To: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Nicolas Ferre <nicolas.ferre@microchip.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Claudiu Beznea <claudiu.beznea@tuxon.dev>
Cc: Thorsten Blum <blum@kernel.org>,
linux-crypto@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] crypto: atmel-tdes - simplify DMA buffer initialization
Date: Thu, 3 Sep 2026 23:08:46 +0200 [thread overview]
Message-ID: <20260903210845.162790-2-blum@kernel.org> (raw)
Calculate the buffer length in a single statement and simplify the error
handling. Inline the dma_mapping_error() checks and return -ENOMEM from
the common error path. If mapping the output buffer fails, unmap the
previously mapped input buffer first.
Also use dev_err() to log errors and %zu to format size_t, and clarify
the error messages.
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
drivers/crypto/atmel-tdes.c | 36 ++++++++++++------------------------
1 file changed, 12 insertions(+), 24 deletions(-)
diff --git a/drivers/crypto/atmel-tdes.c b/drivers/crypto/atmel-tdes.c
index 7d17cdf9eef4..5cef4e2793f0 100644
--- a/drivers/crypto/atmel-tdes.c
+++ b/drivers/crypto/atmel-tdes.c
@@ -308,45 +308,33 @@ static int atmel_tdes_crypt_pdc_stop(struct atmel_tdes_dev *dd)
static int atmel_tdes_buff_init(struct atmel_tdes_dev *dd)
{
- int err = -ENOMEM;
-
dd->buf_in = (void *)__get_free_page(GFP_KERNEL);
dd->buf_out = (void *)__get_free_page(GFP_KERNEL);
- dd->buflen = PAGE_SIZE;
- dd->buflen &= ~(DES_BLOCK_SIZE - 1);
+ dd->buflen = PAGE_SIZE & ~(DES_BLOCK_SIZE - 1);
if (!dd->buf_in || !dd->buf_out) {
- dev_dbg(dd->dev, "unable to alloc pages.\n");
+ dev_err(dd->dev, "failed to allocate DMA buffers\n");
goto err_alloc;
}
- /* MAP here */
- dd->dma_addr_in = dma_map_single(dd->dev, dd->buf_in,
- dd->buflen, DMA_TO_DEVICE);
- err = dma_mapping_error(dd->dev, dd->dma_addr_in);
- if (err) {
- dev_dbg(dd->dev, "dma %zd bytes error\n", dd->buflen);
- goto err_map_in;
- }
+ dd->dma_addr_in = dma_map_single(dd->dev, dd->buf_in, dd->buflen, DMA_TO_DEVICE);
+ if (dma_mapping_error(dd->dev, dd->dma_addr_in))
+ goto err_map;
- dd->dma_addr_out = dma_map_single(dd->dev, dd->buf_out,
- dd->buflen, DMA_FROM_DEVICE);
- err = dma_mapping_error(dd->dev, dd->dma_addr_out);
- if (err) {
- dev_dbg(dd->dev, "dma %zd bytes error\n", dd->buflen);
- goto err_map_out;
+ dd->dma_addr_out = dma_map_single(dd->dev, dd->buf_out, dd->buflen, DMA_FROM_DEVICE);
+ if (dma_mapping_error(dd->dev, dd->dma_addr_out)) {
+ dma_unmap_single(dd->dev, dd->dma_addr_in, dd->buflen, DMA_TO_DEVICE);
+ goto err_map;
}
return 0;
-err_map_out:
- dma_unmap_single(dd->dev, dd->dma_addr_in, dd->buflen,
- DMA_TO_DEVICE);
-err_map_in:
+err_map:
+ dev_err(dd->dev, "failed to map %zu bytes for DMA\n", dd->buflen);
err_alloc:
free_page((unsigned long)dd->buf_out);
free_page((unsigned long)dd->buf_in);
- return err;
+ return -ENOMEM;
}
static void atmel_tdes_buff_cleanup(struct atmel_tdes_dev *dd)
reply other threads:[~2026-09-03 21:10 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=20260903210845.162790-2-blum@kernel.org \
--to=blum@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.ferre@microchip.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
all inboxes | Powered by JetHome®