Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2908676yba; Mon, 22 Apr 2019 15:29:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwLg5EX5zLZJuzNTD3yAlaAHjrQ371ehiLCpBvTfSDWXkxj9o1Cpn7hlFyA3kAwxVnhSfcQ X-Received: by 2002:aa7:9e9e:: with SMTP id p30mr23477631pfq.255.1555972166457; Mon, 22 Apr 2019 15:29:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555972166; cv=none; d=google.com; s=arc-20160816; b=DRouGQ/sEYeEWmbnlVhgSGzctQ2Qdsv8P1gfErds/6V4/d5wKUNycw3GsHBglSuY3n 6v8aNEEkqkP1sNkXD1rPRRD2kRn2wZbnEkR4uvRPAwiORWYIr6qwGwPX6Toi4AZBVUjb RZXfuinnevWFIIm1X7l5nvBz+JLSHEYhed/HblnAlJbLxVXyrR7kEQtaCTKhExPmSqnJ OTMfmr8/BioN2gU8mKYpxqrP6hxuDQH9pFfgVXR2cnbS9foeNwjxVvdgEfFIH+oDSsfM 73vwIAjLGpPvRblZdsVl08s12OsqSbEk8P/pN1vvsKg3gLRG/jo7rP1+sv7EwLLylQhS k0MA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Tf1u6GRJdhQpfMDnlZvyvnJmX56fraFaNS4vGM3eatY=; b=flF+a41EbBL8mj69G55vG6XzT6+LfQ6674QJG202y0frE1aOVwpLcNQtZMdt/iqTr2 YUstP/gYL8ZZvB2zvf0ysbfBdUUm2kez29BHakIuZjIp7trg+fgMaeiv38Q+OJPIsuYK mKD4nl75m9uPmVSHy0rtMeKil4OmqbsvpjW/OxD4KDBOriLWjRJcMNOLpTaWkMAtFZde rUf7/lODdAay6aZm9cjcivRLew/YDaEzSwiNetCMS3puamsh4uar/EwiGr4n304fozuq h7RKTFTuc/797Ajg4t3cB7XZKt07B79NH0PgYA2GyCTRXzcHWHE05DlqjI0MPJpbJKsy oUPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LanXFLxL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y66si13193112pgy.186.2019.04.22.15.29.11; Mon, 22 Apr 2019 15:29:26 -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=LanXFLxL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729637AbfDVTo7 (ORCPT + 99 others); Mon, 22 Apr 2019 15:44:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:46234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729604AbfDVToz (ORCPT ); Mon, 22 Apr 2019 15:44:55 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8C5D6218D9; Mon, 22 Apr 2019 19:44:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962294; bh=9ZKgMnykbdl8AnOdWSoisUwfW1SZ65yD0XzTdlMfVsQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LanXFLxLuz7YYkh3pChfHHdW3X/iBRsEinWQb/3KJUF0ohYaaLntwJybjrQiW3jTv waymMRvztxsMykpa92UMjRgY4r5cWSK2/TKxTkU2KOM4KfpXdB9UAWv+tnOln5eutu apf3mP35OuMnf0V3IO/cyUSJMBSTda7s8RFtidw4= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Geert Uytterhoeven , Linus Walleij , Sasha Levin , linux-gpio@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 87/98] gpio: of: Fix of_gpiochip_add() error path Date: Mon, 22 Apr 2019 15:41:54 -0400 Message-Id: <20190422194205.10404-87-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194205.10404-1-sashal@kernel.org> References: <20190422194205.10404-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Geert Uytterhoeven [ 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 f1ae28289a67..13a402ede07a 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -712,7 +712,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