mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hwrng: amd - simplify control flow in amd_rng_mod_init()
@ 2026-10-02 14:19 Thorsten Blum
  0 siblings, 0 replies; only message in thread
From: Thorsten Blum @ 2026-10-02 14:19 UTC (permalink / raw)
  To: Olivia Mackall, Herbert Xu,
	Uwe Kleine-König (The Capable Hub),
	Kees Cook
  Cc: Thorsten Blum, linux-crypto, linux-kernel

Replace the goto found statement with a break and check pdev after the
loop. Also consolidate the cleanup paths.

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 drivers/char/hw_random/amd-rng.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/char/hw_random/amd-rng.c b/drivers/char/hw_random/amd-rng.c
index dff80daae587..a4c027dd8df2 100644
--- a/drivers/char/hw_random/amd-rng.c
+++ b/drivers/char/hw_random/amd-rng.c
@@ -129,19 +129,15 @@ static int __init amd_rng_mod_init(void)
 {
 	int err;
 	struct pci_dev *pdev = NULL;
-	const struct pci_device_id *ent;
 	u32 pmbase;
 	struct amd768_priv *priv;
 
-	for_each_pci_dev(pdev) {
-		ent = pci_match_id(pci_tbl, pdev);
-		if (ent)
-			goto found;
-	}
-	/* Device not found. */
-	return -ENODEV;
+	for_each_pci_dev(pdev)
+		if (pci_match_id(pci_tbl, pdev))
+			break;
+	if (!pdev)
+		return -ENODEV;
 
-found:
 	err = pci_read_config_dword(pdev, 0x58, &pmbase);
 	if (err) {
 		err = pcibios_err_to_errno(err);
@@ -171,7 +167,7 @@ static int __init amd_rng_mod_init(void)
 	if (!priv->iobase) {
 		pr_err(DRV_NAME "Cannot map ioport\n");
 		err = -EINVAL;
-		goto err_iomap;
+		goto err;
 	}
 
 	amd_rng.priv = (unsigned long)priv;
@@ -182,13 +178,12 @@ static int __init amd_rng_mod_init(void)
 	err = hwrng_register(&amd_rng);
 	if (err) {
 		pr_err(DRV_NAME " registering failed (%d)\n", err);
-		goto err_hwrng;
+		ioport_unmap(priv->iobase);
+		goto err;
 	}
 	return 0;
 
-err_hwrng:
-	ioport_unmap(priv->iobase);
-err_iomap:
+err:
 	release_region(pmbase + PMBASE_OFFSET, PMBASE_SIZE);
 out:
 	kfree(priv);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-02 14:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-02 14:19 [PATCH] hwrng: amd - simplify control flow in amd_rng_mod_init() Thorsten Blum

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®