From patchwork Tue Jul 23 18:02:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 2832137 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DDB28C0319 for ; Tue, 23 Jul 2013 18:05:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C4878202EC for ; Tue, 23 Jul 2013 18:05:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9487D202F6 for ; Tue, 23 Jul 2013 18:05:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934196Ab3GWSEh (ORCPT ); Tue, 23 Jul 2013 14:04:37 -0400 Received: from sauhun.de ([89.238.76.85]:51174 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933840Ab3GWSEf (ORCPT ); Tue, 23 Jul 2013 14:04:35 -0400 Received: from p5b387ff2.dip0.t-ipconnect.de ([91.56.127.242]:8490 helo=localhost) by pokefinder.org with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1V1gwr-0001Tr-Ea; Tue, 23 Jul 2013 20:04:35 +0200 From: Wolfram Sang To: linux-kernel@vger.kernel.org Cc: Wolfram Sang , Eduardo Valentin , Zhang Rui , linux-pm@vger.kernel.org Subject: [PATCH 27/27] thermal: ti-bandgap: cleanup resource allocation Date: Tue, 23 Jul 2013 20:02:00 +0200 Message-Id: <1374602524-3398-28-git-send-email-wsa@the-dreams.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1374602524-3398-1-git-send-email-wsa@the-dreams.de> References: <1374602524-3398-1-git-send-email-wsa@the-dreams.de> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When cleaning up usage of devm_ioremap_resource, I found that resource allocation in this driver is ugly and buggy. If resource[0] is not found, bgp->base will end up NULL, so OOPS. All other resources get ioremapped, but their pointers are discarded, so why bother. So, let's keep things simple. Just remap resource[0] and pass the error, if any. Compile tested only, due to no hardware. Signed-off-by: Wolfram Sang --- Please apply via the subsystem-tree. drivers/thermal/ti-soc-thermal/ti-bandgap.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c index 9dfd471..416be5d 100644 --- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c +++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c @@ -1130,7 +1130,6 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev) const struct of_device_id *of_id; struct ti_bandgap *bgp; struct resource *res; - int i; /* just for the sake */ if (!node) { @@ -1156,21 +1155,10 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev) return ERR_PTR(-ENOMEM); } - i = 0; - do { - void __iomem *chunk; - - res = platform_get_resource(pdev, IORESOURCE_MEM, i); - if (!res) - break; - chunk = devm_ioremap_resource(&pdev->dev, res); - if (i == 0) - bgp->base = chunk; - if (IS_ERR(chunk)) - return ERR_CAST(chunk); - - i++; - } while (res); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + bgp->base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(bgp->base)) + return bgp->base; if (TI_BANDGAP_HAS(bgp, TSHUT)) { bgp->tshut_gpio = of_get_gpio(node, 0);