Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2845419yba; Mon, 22 Apr 2019 14:08:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqyghrpDo0z36QdKqFPIflCn6tFh0UEPpXt55Xz1M6ojboDvwOwPFuBEB2EZjqj9OgtdQc+G X-Received: by 2002:a63:e045:: with SMTP id n5mr19932231pgj.230.1555967331814; Mon, 22 Apr 2019 14:08:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555967331; cv=none; d=google.com; s=arc-20160816; b=Epqivyavc1mDX9Gj31aJDugIrGYkHt+nZFKnEyKuTXoyxE1kPjEceI32zMsPzKsSLL GhkE/C9M5RiepdKndSg8P6AYRvtdEDxTtLdX8wfxnKZxKlT2jz3EdRbcBFF+q2uQJxgW jtCx8HJDb+SeV37CbKG8BbirY66EKtpEqszO80cGZyH1WEAqFoAW8RDxONiyRF2sGbGw peLiD5r97aO/J1m+MHysooWKiILB8PBr7Ognt2ERsgKd1mvJ+gRncy4Za1+upbosguPw aw5YrLJ+YIES6NVldrT4hD112Zq47DtF3tR8u8FlmTJ7tAVxA7CNMY7MOyHGM8EUIqZE R+jw== 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=Xo4JscluI58xRfZyJF0yRCLh+nJIzJxrI/C1lewup/o=; b=JISv2otdDiNRs7izksao745pu8Aot6sYMWcskfWwq4133mNw2OjXDbWqHCFgMSCP+A NGC58GGfdaVlGUYixOPRSTfKmS56KVq+Bkaw/uGNlxGqu4hPLH9elCUuP5j4W/7ZyTW9 bmPp8xe1/Zlw1yJoH5iDFCrcKnjeMHduJZzokn/eFbiGcvDJK9sVqxJMeJ9hG2J0tff9 xdCPtt7F/SKEqZC9ikY/q3EtNJn9PU1YP3oCTwQsXxOqhwwzSbnZXG2AJax1rJ4SZDiG qPjYajATlFwrZtR2CKbeNSM5Q8efIWWkm1yXACzVoJJWxNrhUhj1IfqYvdQzRx83yBBv LbUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g4wjUE4z; 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 m13si13782891pga.331.2019.04.22.14.08.35; Mon, 22 Apr 2019 14:08: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; dkim=pass header.i=@kernel.org header.s=default header.b=g4wjUE4z; 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 S1730232AbfDVTrR (ORCPT + 99 others); Mon, 22 Apr 2019 15:47:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:49946 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730203AbfDVTrO (ORCPT ); Mon, 22 Apr 2019 15:47:14 -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 AC09F21907; Mon, 22 Apr 2019 19:47:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962433; bh=STXnvD7+O9XDC6PbZemY3Ed7xwcNi5uiHo5oLxd1/ts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g4wjUE4zfTd9CTIXQ5tZGOQ0Foi9wndjVZMaVaTf1fQ9bPsiL0BaUzKzuMQ5tC6SK O7aJghfStTbLAoUwlAXwZHylzw6WHpUXiYjdxm3ICOO/z7KHQueJJZSljbZjCj6VoW pUYpYIZom9hc9h1ehL2ZGO9wSznTa35LMmDaDHTM= 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 4.19 61/68] gpio: of: Fix of_gpiochip_add() error path Date: Mon, 22 Apr 2019 15:45:09 -0400 Message-Id: <20190422194516.11634-61-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194516.11634-1-sashal@kernel.org> References: <20190422194516.11634-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 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