Skip to contentSkip to conversation

hwrng: amd - simplify control flow in amd_rng_mod_init()

PATCH In review Thorsten Blum 2 participants 2 messages Oct 2 – Oct 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwrng: amd - simplify control flow in amd_rng_mod_init()

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

---
 drivers/char/hw_random/amd-rng.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)
drivers/char/hw_random/amd-rng.c +9 -14
index dff80daae587..a4c027dd8df2 100644
@@ -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);
maintainer
#1 lore raw
Quoted 7 lines · Thorsten Blum

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

---
 drivers/char/hw_random/amd-rng.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt