Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp7370255yba; Thu, 2 May 2019 08:44:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqwOwNt127koTfJNYjy36VKit3ugHTIcAeHLXCDQT9YRsR7zwgKymwQVqYESu8hgBjDsgvkq X-Received: by 2002:a63:5c25:: with SMTP id q37mr4792635pgb.263.1556811842193; Thu, 02 May 2019 08:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556811842; cv=none; d=google.com; s=arc-20160816; b=CnhB6/B8Gsq7hec/3qEDgEheFhkntyB6tVRXGPWvlSdbXNSCS6V/aCGV+LMGg2Vrji DoxLM4UVArbea+edVbdBdJb8GqeXLK3CR8w5ds9un8Z4dx9FUIblzH9t8jSozbRwLxPx ge4JROLHABrnJozFxlavltfF3si91QB3vdE09cSk14eqhOeB9g2DBmxZQc1lC/8p7MC0 JJIhVgXwEUofQz1Ki562OeKyCrW5CLjUJZ5TalR1a4wOagJ63QMiQSmp7bvCC+LxDzJH YMLu1ktoRBDYxEUDVVT+P12NRPGFYt6oZs9Oo0nAZVxZsSsbp0BKBFBexvrFjw/tNg3m 2LfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VFpey5q25Wf71mz0uqWoFmUlaydxnlQCesZdoPh2baU=; b=DV2tc1YBNFLWdJNaP7io+b8Fea5HxEcmu8yKpp+wXEEO5OH03xSc1d9wJxqAHkaP4+ sfh/+T8lnvu2NTzL5UmzRvglyDmgwH7hS84d7cabxbjC6dtARHM/0G+7z4E4+iVeh/bm sqAbacJ2DRzbB4jYQgRgO4+kz9y9z1Q3xGSdflIRinn9q8+gkiUzLvJFhkQ5eqRCu7Mt q77hAO//PvVsA79lKecNJMl6+YELCL4mPmHXKncsY5owcTQBaYTLF6MCuH0jEENe8AtM wmdw7DFdaG5IaL6IoKCUwPFX65Uag6MBbGpXIm3ZJbbNe6bjaWPyctoSq2NN0ADLnqiC 7tMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xvbR1udW; 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 o187si27830092pga.16.2019.05.02.08.43.46; Thu, 02 May 2019 08:44:02 -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; dkim=pass header.i=@kernel.org header.s=default header.b=xvbR1udW; 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 S1728126AbfEBPmh (ORCPT + 99 others); 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: 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 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