Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp835734imj; Fri, 15 Feb 2019 07:36:07 -0800 (PST) X-Google-Smtp-Source: AHgI3IZy/QueeNh2lEtyoymItwohyzPYTj8hGpztvmLAf7NvLJBSYDH6oQ81chOWEHP7egRSy1uk X-Received: by 2002:a63:d157:: with SMTP id c23mr5911309pgj.170.1550244967283; Fri, 15 Feb 2019 07:36:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550244967; cv=none; d=google.com; s=arc-20160816; b=JHyeqXJKn+FmsNrRj2/4OiZJSwHjlXh3ftoj2ia5NsdO7toEx3Rmfkak+DrT+YSWRI JfWbx2+gFXqw+tlT1wzeKsQQN2HkrdIDRquNjGT6YT6IsmIe2sJf7j9xTF+3goud8fOv qqNpMMQkuJDYipVYtRxidjYn+0IWAzQO79iUoWJMercQWyMFxyAF5557fs/zTazpw57N 1AObIpASoKR+2clEkSyHh51pPwPaVVcPBLyIiGk6lLZb8SUqZa52ZX1sfRG9XPYHUFFb pKW0of0uuaagm29EDnoyERthitZYd11oEsWaiUpzhTIcPVJ1RU1DjeoNPfve3a0sTt4W g3SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=1xcxi4Zr4aaPTy57CWjvbD7ZyvLCvnjLBec3BAsIsjM=; b=BbadUWviTMUw1B4VUOzUlkBOTO3Tyt0ycn/3vBXs4PHEKRaTTXtOtvk/1XwuZLVeri 6qHxMsFsBM/O1sgayID4U4XEE7RUcgu3GYy+ucXBRNZafINIGKdYwT1Aom15zB2Y+aKX kml/7DjW3cCzXPeXpA1sAkLGStVlt53q7x4mkbbuNJfW77tUK6dfN+wGfl7yP3G8+ou4 CUru5rqswPHrrrxrxDhwyjVqIjao6ZhqfcOXLRN60YjfHZraBrmdvH8VczLYz53xlLYU uYWkulRnz6L2kFvcbeoXCqEPaOuxxU0jiOCv+QTBMfHTczFhRrByjTXnSck+g0Wx0x7R FtrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=pRnaMg1h; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q10si5947951pls.280.2019.02.15.07.35.51; Fri, 15 Feb 2019 07:36:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=pRnaMg1h; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391023AbfBOIB7 (ORCPT + 99 others); Fri, 15 Feb 2019 03:01:59 -0500 Received: from m12-14.163.com ([220.181.12.14]:45804 "EHLO m12-14.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726008AbfBOIB7 (ORCPT ); Fri, 15 Feb 2019 03:01:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=1xcxi4Zr4aaPTy57CW jvbD7ZyvLCvnjLBec3BAsIsjM=; b=pRnaMg1hm66xPFgwm1Q3PVweWIrXSWD+/a TZZFPji0TJEnyKfzoNoR3ZODelxlNL8csKzgHiNU9QotHHj/wDWP7Wr+JwOOtmfR cwUBfbK64jOWTntmariCi8SVNPZ13bDeQ872wJBhV9NcZ07TyeoxhTbMSNZzcOUD uWAPD+ZMY= Received: from localhost.localdomain (unknown [182.139.212.12]) by smtp10 (Coremail) with SMTP id DsCowADn7+PicWZcXym0Fw--.3412S2; Fri, 15 Feb 2019 16:01:39 +0800 (CST) From: WangBo To: linux-kernel@vger.kernel.org Cc: linus.walleij@linaro.org, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, wang.bo116@zte.com.cn Subject: [PATCH] pinctrl: nomadik: fix possible object reference leak Date: Fri, 15 Feb 2019 16:01:36 +0800 Message-Id: <1550217696-3006-1-git-send-email-wdjjwb@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: DsCowADn7+PicWZcXym0Fw--.3412S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Cry7AF1ftryxGFWUCrW7Arb_yoW8Cr18pF W7JFWagryUtF47K34rGa1fZrWSk3WI9w42q3s2939Fgay3Jr93Gr48KFyavrZ5CF93G3y3 JrWUtFy8ZF4DAFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jyKZXUUUUU= X-Originating-IP: [182.139.212.12] X-CM-SenderInfo: xzgmy4re6rljoofrz/1tbiOwNcGVXlh4wh-QAAsa Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The of_find_device_by_node takes a reference to the struct device when find the match device ,we should release it when fail. Signed-off-by: WangBo --- drivers/pinctrl/nomadik/pinctrl-nomadik.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/nomadik/pinctrl-nomadik.c b/drivers/pinctrl/nomadik/pinctrl-nomadik.c index 4cc2c47f8778..ec02739bd21b 100644 --- a/drivers/pinctrl/nomadik/pinctrl-nomadik.c +++ b/drivers/pinctrl/nomadik/pinctrl-nomadik.c @@ -1056,17 +1056,22 @@ static struct nmk_gpio_chip *nmk_gpio_populate_chip(struct device_node *np, } if (of_property_read_u32(np, "gpio-bank", &id)) { dev_err(&pdev->dev, "populate: gpio-bank property not found\n"); + platform_device_put(gpio_pdev); return ERR_PTR(-EINVAL); } /* Already populated? */ nmk_chip = nmk_gpio_chips[id]; - if (nmk_chip) + if (nmk_chip) { + platform_device_put(gpio_pdev); return nmk_chip; + } nmk_chip = devm_kzalloc(&pdev->dev, sizeof(*nmk_chip), GFP_KERNEL); - if (!nmk_chip) + if (!nmk_chip) { + platform_device_put(gpio_pdev); return ERR_PTR(-ENOMEM); + } nmk_chip->bank = id; chip = &nmk_chip->chip; @@ -1077,13 +1082,17 @@ static struct nmk_gpio_chip *nmk_gpio_populate_chip(struct device_node *np, res = platform_get_resource(gpio_pdev, IORESOURCE_MEM, 0); base = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(base)) + if (IS_ERR(base)) { + platform_device_put(gpio_pdev); return ERR_CAST(base); + } nmk_chip->addr = base; clk = clk_get(&gpio_pdev->dev, NULL); - if (IS_ERR(clk)) + if (IS_ERR(clk)) { + platform_device_put(gpio_pdev); return (void *) clk; + } clk_prepare(clk); nmk_chip->clk = clk; -- 2.15.2