From patchwork Sun Sep 11 15:23:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: PrasannaKumar Muralidharan X-Patchwork-Id: 9325455 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A3A336048B for ; Sun, 11 Sep 2016 15:24:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E4E628A57 for ; Sun, 11 Sep 2016 15:24:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E1C328ACB; Sun, 11 Sep 2016 15:24:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A078128A57 for ; Sun, 11 Sep 2016 15:24:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755606AbcIKPYM (ORCPT ); Sun, 11 Sep 2016 11:24:12 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:32794 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750912AbcIKPYL (ORCPT ); Sun, 11 Sep 2016 11:24:11 -0400 Received: by mail-pf0-f194.google.com with SMTP id 128so6786244pfb.0 for ; Sun, 11 Sep 2016 08:24:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=2s/07Pf8PJ2iMG4I+KjRZib/Z9KOVeHOrswdN/qxd3c=; b=yh+Z63hRkjX6QvuoTPXjaR6veKgxdMfkNIur3hZV3y7PVwx5eNnM8IWo/mzkHdgLx0 0Vmhk5RNTa+SQXWjaAJG4eMCHYsSLOU8sgWCyXwH8o0mvqbBoCkhZszXHJQmPHOfIdXh WTEWehxaniI5datksv2hOEFzlmFNkdRWsiT+uqb+bK3hBA+p3M6QNlnWCCPVLulfz+JN btmWv3r67CCMCW1myZ6LkV3TKEwwYiNBFE2jcYNk7sUe9mD5NhNR/SpP33UVdCfQiRDq 7Ugra0/WRbpDLuZYRAW+Rig3XnxnSrcnky0OUYDm1t/w1HbnV2ouYtYmkFnrdVitr5DB 2vvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=2s/07Pf8PJ2iMG4I+KjRZib/Z9KOVeHOrswdN/qxd3c=; b=SXZpeWQGnd3SqW2rurwI8bAmJKpVMSOiLY7yVIIu2E90qYtzFgbWHezytaMz4ncrxi Lcl0idcl/zmFwSF8OvopxxPRokUK6JC32h5uk5aQa/5ZlEkRbH6OWjPdGZMowfRV2K9t MJB6Et19M5IRKf7RE4P2j27tt20XX3Zq8DIgo/U1qgS9a4z/2LW+AT+N5o5Lv1q/PzLC 3TpW9BlrPxZyFX2NIqNrE7/IKCHBt/o554isD9w4iuusclSSeORVumhCKmBHHMVAGtRC deeZeff6552qw42DxKX+tItIDuppG0NFPWXPNUYEUNVoe/+rLIYa76pNrlYWI5PotRce JswQ== X-Gm-Message-State: AE9vXwOAPORlewUfN0q/lLXg7f5DXs2i/vCc17tcOHcMf0as/ugFEfKMtD+3bJca4pdELw== X-Received: by 10.98.113.135 with SMTP id m129mr25305655pfc.41.1473607450500; Sun, 11 Sep 2016 08:24:10 -0700 (PDT) Received: from localhost.localdomain ([1.23.10.241]) by smtp.gmail.com with ESMTPSA id k66sm18303519pfc.30.2016.09.11.08.24.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 11 Sep 2016 08:24:09 -0700 (PDT) From: PrasannaKumar Muralidharan To: herbert@gondor.apana.org.au, mpm@selenic.com, linux-geode@lists.infradead.org, linux-crypto@vger.kernel.org Cc: PrasannaKumar Muralidharan Subject: [PATCH] hwrng: geode-rng - Migrate to managed API Date: Sun, 11 Sep 2016 20:53:21 +0530 Message-Id: <1473607401-25873-1-git-send-email-prasannatsmkumar@gmail.com> X-Mailer: git-send-email 2.5.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use devm_ioremap and devm_hwrng_register instead of ioremap and hwrng_register. This removes error handling code. Also moved code around by removing goto statements. This improves code readability. Signed-off-by: PrasannaKumar Muralidharan --- drivers/char/hw_random/geode-rng.c | 50 ++++++++++++-------------------------- 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/drivers/char/hw_random/geode-rng.c b/drivers/char/hw_random/geode-rng.c index 0d0579f..79e7482 100644 --- a/drivers/char/hw_random/geode-rng.c +++ b/drivers/char/hw_random/geode-rng.c @@ -31,9 +31,6 @@ #include #include - -#define PFX KBUILD_MODNAME ": " - #define GEODE_RNG_DATA_REG 0x50 #define GEODE_RNG_STATUS_REG 0x54 @@ -85,7 +82,6 @@ static struct hwrng geode_rng = { static int __init mod_init(void) { - int err = -ENODEV; struct pci_dev *pdev = NULL; const struct pci_device_id *ent; void __iomem *mem; @@ -93,43 +89,27 @@ static int __init mod_init(void) for_each_pci_dev(pdev) { ent = pci_match_id(pci_tbl, pdev); - if (ent) - goto found; - } - /* Device not found. */ - goto out; - -found: - rng_base = pci_resource_start(pdev, 0); - if (rng_base == 0) - goto out; - err = -ENOMEM; - mem = ioremap(rng_base, 0x58); - if (!mem) - goto out; - geode_rng.priv = (unsigned long)mem; - - pr_info("AMD Geode RNG detected\n"); - err = hwrng_register(&geode_rng); - if (err) { - pr_err(PFX "RNG registering failed (%d)\n", - err); - goto err_unmap; + if (ent) { + rng_base = pci_resource_start(pdev, 0); + if (rng_base == 0) + return -ENODEV; + + mem = devm_ioremap(&pdev->dev, rng_base, 0x58); + if (IS_ERR(mem)) + return PTR_ERR(mem); + geode_rng.priv = (unsigned long)mem; + + pr_info("AMD Geode RNG detected\n"); + return devm_hwrng_register(&pdev->dev, &geode_rng); + } } -out: - return err; -err_unmap: - iounmap(mem); - goto out; + /* Device not found. */ + return -ENODEV; } static void __exit mod_exit(void) { - void __iomem *mem = (void __iomem *)geode_rng.priv; - - hwrng_unregister(&geode_rng); - iounmap(mem); } module_init(mod_init);