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 C098AC43219 for ; Thu, 2 May 2019 15:42:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 89C3F204EC for ; Thu, 2 May 2019 15:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556811757; bh=Alr9sH/M7ds0/5QEGwxh0NjFl6J4vLY3AyeE9AIuLps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=GTrZ15mL6UIpg5nSKePbv6EbRe64awgnuL6+lGZQ2+jXyo3xlUh5cGqHG/jp0NKb7 pWEQ1luUTGUHZGZxi7r34zD4AkZzRcSl50e5P6yn+g3frUye0l0+Cy5VZcBvDBuFMf qkpR8hCkbPr9HFrbgJbraw6BAWTjYdLm1HswnLLs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727428AbfEBPmh (ORCPT ); Thu, 2 May 2019 11:42:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:45030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728092AbfEBP2B (ORCPT ); Thu, 2 May 2019 11:28:01 -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 EA25E20449; Thu, 2 May 2019 15:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556810880; bh=Alr9sH/M7ds0/5QEGwxh0NjFl6J4vLY3AyeE9AIuLps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xvbR1udWogHBL+ObR+DV2j5Ue8xMruOIjtb9fM5lyyHYSRR2TPyhnefrktggCZIlA UIVPO1gxaoSnY+diXFY5vrC/L4SIlfMFImvVNLzVU5Cfd9xhBSUcMMIyvraFr9IQnb wJ90aemF5IGmBIH7t0+seYOm/nCLC8QcUC4m1wAU= 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.19 65/72] gpio: of: Fix of_gpiochip_add() error path Date: Thu, 2 May 2019 17:21:27 +0200 Message-Id: <20190502143338.481786551@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190502143333.437607839@linuxfoundation.org> References: <20190502143333.437607839@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 d4e7a09598fa..e0f149bdf98f 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -646,7 +646,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