From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,T_DKIMWL_WL_HIGH,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00CFAC43219 for ; Thu, 2 May 2019 15:25:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B984E20675 for ; Thu, 2 May 2019 15:24:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556810699; bh=B/P93hTHP71MZC3G562cIshOy7HeUCLMgN4xrTDuKv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=RNKU7rD/JAN4Ij9PEoSuTDdt7mg/nohiD/xVKNSosZ2vUbOdLx7a99wuUyLwHswvL UflmCaXEzyLW6p/8aWZVpAYSTsEz6G27xlwz97BV20f8N3CSrJ6snPkOzSpR3nWiBo Ml4cJL5emu8jOcDBWL8d4awyyeCoxpH0WEF3k/c4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727416AbfEBPY6 (ORCPT ); Thu, 2 May 2019 11:24:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:40948 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726501AbfEBPY5 (ORCPT ); Thu, 2 May 2019 11:24:57 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F16BB20675; Thu, 2 May 2019 15:24:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556810696; bh=B/P93hTHP71MZC3G562cIshOy7HeUCLMgN4xrTDuKv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0HHWiacHGY8bajhMME1RFcOolV2udMCkxZVhgO/tzVTPl4ERc74xsAXHAhfFWqPc7 a9BMOtJQYU1nlQ3SZTFQ14H5HPesfS0bQrbXm3Ttp8Z9dkETD/6L+dh+KnBVsZvE1F nrv70uZDkNzGS/DXqVsiUw4Mb5552TcaKjHSGh/A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Geert Uytterhoeven , Mukesh Ojha , Linus Walleij , "Sasha Levin (Microsoft)" Subject: [PATCH 4.14 45/49] gpio: of: Fix of_gpiochip_add() error path Date: Thu, 2 May 2019 17:21:22 +0200 Message-Id: <20190502143329.586626969@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190502143323.397051088@linuxfoundation.org> References: <20190502143323.397051088@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit f7299d441a4da8a5088e651ea55023525a793a13 ] If the call to of_gpiochip_scan_gpios() in of_gpiochip_add() fails, no error handling is performed. This lead to the need of callers to call of_gpiochip_remove() on failure, which causes "BAD of_node_put() on ..." if the failure happened before the call to of_node_get(). Fix this by adding proper error handling. Note that calling gpiochip_remove_pin_ranges() multiple times causes no harm: subsequent calls are a no-op. Fixes: dfbd379ba9b7431e ("gpio: of: Return error if gpio hog configuration failed") Signed-off-by: Geert Uytterhoeven Reviewed-by: Mukesh Ojha Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin (Microsoft) --- drivers/gpio/gpiolib-of.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index ee8c046cab62..d6ed4e891b34 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -499,7 +499,13 @@ int of_gpiochip_add(struct gpio_chip *chip) of_node_get(chip->of_node); - return of_gpiochip_scan_gpios(chip); + status = of_gpiochip_scan_gpios(chip); + if (status) { + of_node_put(chip->of_node); + gpiochip_remove_pin_ranges(chip); + } + + return status; } void of_gpiochip_remove(struct gpio_chip *chip) -- 2.19.1