From: Rosen Penev <rosenp@gmail.com>
To: linux-crypto@vger.kernel.org
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH 1/2] crypto: img-hash: fetch resources into locals before probe body
Date: Tue, 11 Aug 2026 14:20:29 -0700 [thread overview]
Message-ID: <20260811212030.20057-2-rosenp@gmail.com> (raw)
In-Reply-To: <20260811212030.20057-1-rosenp@gmail.com>
Fetch the IRQ, iomem resources, and clocks at the start of img_hash_probe
and assign them to locals, then copy into hdev after it is allocated. This
keeps resource acquisition together at the top of probe and allows
direct return instead of having to use goto. These can also return
-EPROBE_DEFER so that helps to avoid pointless work.
Assisted-by: opencode:deepseek-v4-flash-free
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/crypto/img-hash.c | 65 ++++++++++++++++++++-------------------
1 file changed, 33 insertions(+), 32 deletions(-)
diff --git a/drivers/crypto/img-hash.c b/drivers/crypto/img-hash.c
index 1ccfc0eccc73..f7265347901c 100644
--- a/drivers/crypto/img-hash.c
+++ b/drivers/crypto/img-hash.c
@@ -923,9 +923,37 @@ static int img_hash_probe(struct platform_device *pdev)
struct img_hash_dev *hdev;
struct device *dev = &pdev->dev;
struct resource *hash_res;
- int irq;
+ void __iomem *cpu_addr;
+ void __iomem *io_base;
+ struct clk *hash_clk;
+ struct clk *sys_clk;
+ int irq;
int err;
+ irq = platform_get_irq(pdev, 0);
+ if (irq < 0)
+ return irq;
+
+ io_base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(io_base))
+ return PTR_ERR(io_base);
+
+ cpu_addr = devm_platform_get_and_ioremap_resource(pdev, 1, &hash_res);
+ if (IS_ERR(cpu_addr))
+ return PTR_ERR(cpu_addr);
+
+ hash_clk = devm_clk_get_enabled(&pdev->dev, "hash");
+ if (IS_ERR(hash_clk)) {
+ dev_err(dev, "clock initialization failed.\n");
+ return PTR_ERR(hash_clk);
+ }
+
+ sys_clk = devm_clk_get_enabled(&pdev->dev, "sys");
+ if (IS_ERR(sys_clk)) {
+ dev_err(dev, "clock initialization failed.\n");
+ return PTR_ERR(sys_clk);
+ }
+
hdev = devm_kzalloc(dev, sizeof(*hdev), GFP_KERNEL);
if (hdev == NULL)
return -ENOMEM;
@@ -944,25 +972,12 @@ static int img_hash_probe(struct platform_device *pdev)
crypto_init_queue(&hdev->queue, IMG_HASH_QUEUE_LENGTH);
/* Register bank */
- hdev->io_base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(hdev->io_base)) {
- err = PTR_ERR(hdev->io_base);
- goto res_err;
- }
-
+ hdev->io_base = io_base;
/* Write port (DMA or CPU) */
- hdev->cpu_addr = devm_platform_get_and_ioremap_resource(pdev, 1, &hash_res);
- if (IS_ERR(hdev->cpu_addr)) {
- err = PTR_ERR(hdev->cpu_addr);
- goto res_err;
- }
+ hdev->cpu_addr = cpu_addr;
hdev->bus_addr = hash_res->start;
-
- irq = platform_get_irq(pdev, 0);
- if (irq < 0) {
- err = irq;
- goto res_err;
- }
+ hdev->hash_clk = hash_clk;
+ hdev->sys_clk = sys_clk;
err = devm_request_irq(dev, irq, img_irq_handler, 0,
dev_name(dev), hdev);
@@ -970,20 +985,6 @@ static int img_hash_probe(struct platform_device *pdev)
goto res_err;
dev_dbg(dev, "using IRQ channel %d\n", irq);
- hdev->hash_clk = devm_clk_get_enabled(&pdev->dev, "hash");
- if (IS_ERR(hdev->hash_clk)) {
- dev_err(dev, "clock initialization failed.\n");
- err = PTR_ERR(hdev->hash_clk);
- goto res_err;
- }
-
- hdev->sys_clk = devm_clk_get_enabled(&pdev->dev, "sys");
- if (IS_ERR(hdev->sys_clk)) {
- dev_err(dev, "clock initialization failed.\n");
- err = PTR_ERR(hdev->sys_clk);
- goto res_err;
- }
-
err = img_hash_dma_init(hdev);
if (err)
goto res_err;
--
2.55.0
next prev parent reply other threads:[~2026-08-11 21:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 21:20 [PATCH 0/2] crypto: img-hash: clean up probe Rosen Penev
2026-08-11 21:20 ` Rosen Penev [this message]
2026-08-11 21:20 ` [PATCH 2/2] crypto: img-hash: fix IRQ teardown ordering and fetch clocks early Rosen Penev
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=20260811212030.20057-2-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.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