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 CED18C43219 for ; Thu, 2 May 2019 15:22:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E0B9217D7 for ; Thu, 2 May 2019 15:22:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556810573; bh=rPDTKpxLtWVx3Ngis1eC/2Bn9FdqpXs4F64UVxD6DTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=v4Z+3RGWI4HFS67EDfeX45d+MhV+XBSRcgs9GXYFWfwg3vI6gbSEe1SYFvP+vmz1M E/EdEvuSWmLb2XBnKEBScBf019oqmLkHqCqIfmas2rBZwkX9YItvwrHT1RJjcpQwEv kn8Ai0NCqfMRQ3CWjpCHcx6qDbUL5Unx5VdCEUFA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726865AbfEBPWw (ORCPT ); Thu, 2 May 2019 11:22:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:38236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726809AbfEBPWr (ORCPT ); Thu, 2 May 2019 11:22:47 -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 1687A20675; Thu, 2 May 2019 15:22:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556810566; bh=rPDTKpxLtWVx3Ngis1eC/2Bn9FdqpXs4F64UVxD6DTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MncP7KfghXYzgiWO5DUVbDo+iz3uSmwcxJ/hVuspJlxFsMYR4iBXRl2H0Y1twK3PX jEoX1tZVJOE6C5unDjWiIQFa/iTLZygqgjxcByjYQziYpKMNHOYJrhiMi+pmwpoUG2 JTqWuBz1yHpLQ7xiJRjBP8MtUz/5WEkAfKHC14yI= 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.9 29/32] gpio: of: Fix of_gpiochip_add() error path Date: Thu, 2 May 2019 17:21:15 +0200 Message-Id: <20190502143322.727461789@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190502143314.649935114@linuxfoundation.org> References: <20190502143314.649935114@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 aac84329c759..b863386be911 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -531,7 +531,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