From patchwork Sat Jul 9 13:41:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 9222109 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 DF7F06089D for ; Sat, 9 Jul 2016 13:41:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5A752870D for ; Sat, 9 Jul 2016 13:41:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7F4D28710; Sat, 9 Jul 2016 13:41:50 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 180222870D for ; Sat, 9 Jul 2016 13:41:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751866AbcGINlt (ORCPT ); Sat, 9 Jul 2016 09:41:49 -0400 Received: from mga04.intel.com ([192.55.52.120]:30789 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751545AbcGINls (ORCPT ); Sat, 9 Jul 2016 09:41:48 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP; 09 Jul 2016 06:41:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,336,1464678000"; d="scan'208";a="1013694892" Received: from black.fi.intel.com ([10.237.72.93]) by orsmga002.jf.intel.com with ESMTP; 09 Jul 2016 06:41:46 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 09CA8CF; Sat, 9 Jul 2016 16:41:44 +0300 (EEST) From: Andy Shevchenko To: Adrian Hunter , linux-mmc@vger.kernel.org, Ulf Hansson Cc: Andy Shevchenko Subject: [PATCH v1 1/1] mmc: sdhci-pci: Convert to use managed functions pcim_* and devm_* Date: Sat, 9 Jul 2016 16:41:43 +0300 Message-Id: <1468071703-77301-1-git-send-email-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.8.1 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This makes the error handling much more simpler than open-coding everything and in addition makes the probe function smaller an tidier. Signed-off-by: Andy Shevchenko Acked-by: Adrian Hunter --- drivers/mmc/host/sdhci-pci-core.c | 42 ++++++++++----------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c index 6fbf708..773532d 100644 --- a/drivers/mmc/host/sdhci-pci-core.c +++ b/drivers/mmc/host/sdhci-pci-core.c @@ -1819,15 +1819,13 @@ static int sdhci_pci_probe(struct pci_dev *pdev, return -ENODEV; } - ret = pci_enable_device(pdev); + ret = pcim_enable_device(pdev); if (ret) return ret; - chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL); - if (!chip) { - ret = -ENOMEM; - goto err; - } + chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; chip->pdev = pdev; chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data; @@ -1843,7 +1841,7 @@ static int sdhci_pci_probe(struct pci_dev *pdev, if (chip->fixes && chip->fixes->probe) { ret = chip->fixes->probe(chip); if (ret) - goto free; + return ret; } slots = chip->num_slots; /* Quirk may have changed this */ @@ -1853,8 +1851,7 @@ static int sdhci_pci_probe(struct pci_dev *pdev, if (IS_ERR(slot)) { for (i--; i >= 0; i--) sdhci_pci_remove_slot(chip->slots[i]); - ret = PTR_ERR(slot); - goto free; + return PTR_ERR(slot); } chip->slots[i] = slot; @@ -1864,35 +1861,18 @@ static int sdhci_pci_probe(struct pci_dev *pdev, sdhci_pci_runtime_pm_allow(&pdev->dev); return 0; - -free: - pci_set_drvdata(pdev, NULL); - kfree(chip); - -err: - pci_disable_device(pdev); - return ret; } static void sdhci_pci_remove(struct pci_dev *pdev) { int i; - struct sdhci_pci_chip *chip; - - chip = pci_get_drvdata(pdev); - - if (chip) { - if (chip->allow_runtime_pm) - sdhci_pci_runtime_pm_forbid(&pdev->dev); + struct sdhci_pci_chip *chip = pci_get_drvdata(pdev); - for (i = 0; i < chip->num_slots; i++) - sdhci_pci_remove_slot(chip->slots[i]); - - pci_set_drvdata(pdev, NULL); - kfree(chip); - } + if (chip->allow_runtime_pm) + sdhci_pci_runtime_pm_forbid(&pdev->dev); - pci_disable_device(pdev); + for (i = 0; i < chip->num_slots; i++) + sdhci_pci_remove_slot(chip->slots[i]); } static struct pci_driver sdhci_driver = {