From patchwork Fri Sep 9 07:58:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: PrasannaKumar Muralidharan X-Patchwork-Id: 9322625 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 8CE4D60231 for ; Fri, 9 Sep 2016 07:59:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 824EA29CC1 for ; Fri, 9 Sep 2016 07:59:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76C8829CC4; Fri, 9 Sep 2016 07:59:12 +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 0D18E29CC1 for ; Fri, 9 Sep 2016 07:59:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752436AbcIIH7L (ORCPT ); Fri, 9 Sep 2016 03:59:11 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34677 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751981AbcIIH7K (ORCPT ); Fri, 9 Sep 2016 03:59:10 -0400 Received: by mail-pf0-f196.google.com with SMTP id g202so3647176pfb.1 for ; Fri, 09 Sep 2016 00:59:09 -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=JiaIc5/9XfOhdPZ7022Ke6RokAg/ISHdg5zsWW1+ZIQ=; b=pdEfGD108s4WEhxGgfF5Bkgwapqig+EvDRUFTHPK/7+WR8TeHp/NSSGFSLJreEuS25 pF+dzd5aQpv/O4LHqci8j4tGfQuNfaQln1RCJtIpdqc26/bBaK1827IcVgWvFNJdwki2 rboQhAovZFJv6hTgbixjb/7aQdw2PciCBZlH8hggzAqdl5fBw4hvW+00ivP1jX0DnGBV 6ZLUXe3vRHHVowmcnTSMfZ7uh4jGlxQBvXKqFBgKtNpH/jC29W94tUA8ISfemBRldn15 wR91YmEQ5TTzlDAb+zikGKkUZ3yxfCE6eVIJEBkM2aLP6uhPRh4Od1GG9AL+wd8IQCwK OKuw== 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=JiaIc5/9XfOhdPZ7022Ke6RokAg/ISHdg5zsWW1+ZIQ=; b=L4l5JUQwb9N8gGzBndfWfTcWRFEGsrUma6b50TgUGoRpdV7ukwIWtn2nVwqvMToI+i ssYmeJwN2JmbFZ+lELws8S7pLdDMx770OXRgJXOzJmAF/EO64eQvy+BY/adXju9i4mkA LJUFvZoEFLKVilj6mM6cBdQVQbomncFpXAi8re5j9SBKw2KBf0hF/p1+WMWHlUEfhn72 7yT2jiZRs9qZJ7FZOR0a5SL2xipAEzzfwr8guVA5BbCOaD4J6UU3Bx3JCKPCscuUirj0 yBeDX1HGbeEYRwaY84rcwME4QnjAEcrCVOn8GHbwczvWg+UREcYHKgLVX13Mj4jIfsxY BvtA== X-Gm-Message-State: AE9vXwMKLTUzWCB3ea2MYeuegKZ8s1vxAPS0Q1IIiTXTYHNJxzz0Q2FFIN7r0E9wi/GgWg== X-Received: by 10.98.64.193 with SMTP id f62mr4154306pfd.141.1473407949181; Fri, 09 Sep 2016 00:59:09 -0700 (PDT) Received: from localhost.localdomain ([1.22.68.181]) by smtp.gmail.com with ESMTPSA id bx9sm2950907pab.17.2016.09.09.00.59.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Sep 2016 00:59:08 -0700 (PDT) From: PrasannaKumar Muralidharan To: mpm@selenic.com, herbert@gondor.apana.org.au, clabbe.montjoie@gmail.com, linux-crypto@vger.kernel.org Cc: PrasannaKumar Muralidharan Subject: [PATCH] hwrng: amd-rng - Migrate to managed API Date: Fri, 9 Sep 2016 13:28:23 +0530 Message-Id: <1473407903-12470-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 Managed API eliminates error handling code, thus reduces several lines of code. Signed-off-by: PrasannaKumar Muralidharan --- drivers/char/hw_random/amd-rng.c | 48 +++++++++------------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/drivers/char/hw_random/amd-rng.c b/drivers/char/hw_random/amd-rng.c index 9959c76..4dbc5aa 100644 --- a/drivers/char/hw_random/amd-rng.c +++ b/drivers/char/hw_random/amd-rng.c @@ -55,7 +55,6 @@ MODULE_DEVICE_TABLE(pci, pci_tbl); struct amd768_priv { void __iomem *iobase; struct pci_dev *pcidev; - u32 pmbase; }; static int amd_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) @@ -149,58 +148,33 @@ found: if (pmbase == 0) return -EIO; - priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (IS_ERR(priv)) + return PTR_ERR(priv); - if (!request_region(pmbase + PMBASE_OFFSET, PMBASE_SIZE, DRV_NAME)) { + if (!devm_request_region(&pdev->dev, pmbase + PMBASE_OFFSET, + PMBASE_SIZE, DRV_NAME)) { dev_err(&pdev->dev, DRV_NAME " region 0x%x already in use!\n", pmbase + 0xF0); - err = -EBUSY; - goto out; + return -EBUSY; } - priv->iobase = ioport_map(pmbase + PMBASE_OFFSET, PMBASE_SIZE); - if (!priv->iobase) { + priv->iobase = devm_ioport_map(&pdev->dev, pmbase + PMBASE_OFFSET, + PMBASE_SIZE); + if (IS_ERR(priv->iobase)) { pr_err(DRV_NAME "Cannot map ioport\n"); - err = -EINVAL; - goto err_iomap; + return PTR_ERR(priv->iobase); } amd_rng.priv = (unsigned long)priv; - priv->pmbase = pmbase; priv->pcidev = pdev; pr_info(DRV_NAME " detected\n"); - err = hwrng_register(&amd_rng); - if (err) { - pr_err(DRV_NAME " registering failed (%d)\n", err); - goto err_hwrng; - } - return 0; - -err_hwrng: - ioport_unmap(priv->iobase); -err_iomap: - release_region(pmbase + PMBASE_OFFSET, PMBASE_SIZE); -out: - kfree(priv); - return err; + return devm_hwrng_register(&pdev->dev, &amd_rng); } static void __exit mod_exit(void) { - struct amd768_priv *priv; - - priv = (struct amd768_priv *)amd_rng.priv; - - hwrng_unregister(&amd_rng); - - ioport_unmap(priv->iobase); - - release_region(priv->pmbase + PMBASE_OFFSET, PMBASE_SIZE); - - kfree(priv); } module_init(mod_init);