Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp468758ybb; Thu, 28 Mar 2019 06:14:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8BB++fGeqh4yITFHm4ybySF6/nr8d1zBSLegGsNzX8vt2Ymuzo8M0MNHDaVDMnWrnJ1fr X-Received: by 2002:a62:524e:: with SMTP id g75mr21620241pfb.106.1553778891296; Thu, 28 Mar 2019 06:14:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553778891; cv=none; d=google.com; s=arc-20160816; b=F2dX5WGzwrOBE1SZkKhlBwt0SpQnbGmXpnAusUa3VORjk4j/fH1ilVAazvXsZtMzyY 4t3aw2r4OndCSOc3RPN+f/SdUXx4IXpHfZIlVXmMomlFYV64/cv9uaFhhQnF+T1ZZ0A0 Kiv4L3K0V/Ek7XRYKeEltAmRusgMRhuq6MDkTYGwEEURd0zbaRb1mnKvJBCpdjEHnvDD up+kOFHD8CMftBXvVh5I1yL7KWIt1WvtUWeUVdc7QiUg6lxraXc0TNha03MKSYKYB5GK RL4wMBdap8mlAU/lkI4XjGmPWE16wis3+VDNPKGcKMq+Kz66rau5uhMtIZpo60AZcblg lz6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=QbUzZWm8E0b8SKmvUxR2I9wsMcAwVdIaOIx7erYXnGc=; b=kzZVHUHv8XhVYh0DuDN5Ml7u+s+gCZT/84ynG8EbP5b8Tyk8ZH2N/M+964V3dXRJmL 6JF6byxQZzKcdAU0Pkk2VxDjNgalCKbfX6HyLM+gy+q2TdiMdF9933eX6GlUolYvlTfy e0IJK9sC7+H5UVSclCG1oUuLXxCAcBVrCfQHsCU+s80GUejQabeKPeQKBTGEtgrMwuXP 4ZFabPo4C4ilWw2E5fOAbQ8vVPIfMetTqZK1Bl3Iif+xmZgZiswEwRZL8x85o2I4Zt5B WyzwSzJFt3XrusVbc1nHIepaAAbhjpOIdtGzUqc6on2vZf4s/De6/ZGMdqvMv4IbwF4E XwMw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12si20438859pgr.104.2019.03.28.06.14.35; Thu, 28 Mar 2019 06:14:51 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726281AbfC1NNz (ORCPT + 99 others); Thu, 28 Mar 2019 09:13:55 -0400 Received: from laurent.telenet-ops.be ([195.130.137.89]:45908 "EHLO laurent.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726173AbfC1NNy (ORCPT ); Thu, 28 Mar 2019 09:13:54 -0400 Received: from ramsan ([84.194.111.163]) by laurent.telenet-ops.be with bizsmtp id tRDr1z0033XaVaC01RDr6A; Thu, 28 Mar 2019 14:13:51 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1h9Uqt-0005Fj-1J; Thu, 28 Mar 2019 14:13:51 +0100 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1h9Uqt-0004ue-0E; Thu, 28 Mar 2019 14:13:51 +0100 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski Cc: Benoit Parrot , Laxman Dewangan , Tomeu Vizoso , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 1/3] gpio: of: Fix of_gpiochip_add() error path Date: Thu, 28 Mar 2019 14:13:47 +0100 Message-Id: <20190328131349.18838-2-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190328131349.18838-1-geert+renesas@glider.be> References: <20190328131349.18838-1-geert+renesas@glider.be> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 8b9c3ab70f6eade4..257be7bac032a855 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -717,7 +717,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.17.1