Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2554707imu; Thu, 29 Nov 2018 06:49:55 -0800 (PST) X-Google-Smtp-Source: AFSGD/WNNLM7MV9F72sDzoijThGuaTxxlxIzfz6SaO0LXmc5n7GCHhlZcmTwSdZCH7Ma33n6Sm2+ X-Received: by 2002:a17:902:8f83:: with SMTP id z3mr1706902plo.328.1543502995402; Thu, 29 Nov 2018 06:49:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543502995; cv=none; d=google.com; s=arc-20160816; b=j/BEerOdL9bN92EE7mQOw0TxWFNX/Xw6SkQImhL2jHq5b4UUkceDx6C6GXBAJyyvSM RteKBPZFjGyYmtMeroAyXJJAs64hC9fnEKN5ntIq209Ykm/KAfwe4cgzjBSwHXtnd1zH 4h39uEXXWKgf3paDpFT+7pEB08i/Mla9VJ9kD4uuN9MLu2GjoYXd/m8N/7Kpwb2qX+1w tuUnO0ErN7WwF5C8gsO+iwKstpPXLF5M+AI5xHN1wEAShtubMCvh936geiiSSXf6r1bX ck2rJCFbKy+iFTTTexxnMrAYYTwzpJTgECWyEOJDh3hRDexnhktgDIO0nHEV8NGTrZlS RQEw== 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=6zJMLYCLXccZoQ4qpfdAk+BsXQ8rXT48nGIPSibPTu4=; b=1I6vW20f1EPKgbXpNOAm0TCnEJZMqHNW9Kp2PIH6nN28WS6fFAkR7wm7f+KDhYCmIO Tkqi1BKzYKUfjmWdM3ov1Zm4t06WlyPMsa6ZeFSsnGJpkmlRnbAkAyl1XX3g241h+Her O25d29HpnYYhh/81o0C1hBO/EZiVw24i+rEzgMUNf5rPnIZDZdF5AsMRqvdzbI5JZdRE JljP194v7Zcnz8EgWMHD1r2QAM00cmhBHh2lo90g/7HquIu/RtE1mWQH4gbBo44vRbBx Xje6qZ1gJNOSsTspz03E+irrwtbZGXokCryGVOdmcN0sQsOayDv8rBbBFtnBHN0sb/xF C2bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ukH/ZPQ+"; 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 f124si2416763pfa.1.2018.11.29.06.49.40; Thu, 29 Nov 2018 06:49:55 -0800 (PST) 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="ukH/ZPQ+"; 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 S1733196AbeK3Bbl (ORCPT + 99 others); Thu, 29 Nov 2018 20:31:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:59324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729984AbeK3Bbk (ORCPT ); Thu, 29 Nov 2018 20:31:40 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 3C34E213A2; Thu, 29 Nov 2018 14:26:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501567; bh=IL0jWB3ZAO1mAw3PVLElun1iU9Z9wgTk/5nPbNt5ky8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ukH/ZPQ+Zeru/WyNiRRfSu/VL8YNyBx+1Wa0iDCx6aVezewMZGzuUy8izxAWlm6pv F2Qo/gFVoKtn2bUT25r0c3mSH28KIMrcg68oboeM8xmO9rOJgQu0tZX8+hlRdrDApN bAZErEGzieYnqDcNqkggYOd2a7i6n+kdTecUPMkI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Zapolskiy , Linus Walleij Subject: [PATCH 4.14 015/100] gpio: dont free unallocated ida on gpiochip_add_data_with_key() error path Date: Thu, 29 Nov 2018 15:11:45 +0100 Message-Id: <20181129140100.199782296@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140058.768942700@linuxfoundation.org> References: <20181129140058.768942700@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vladimir Zapolskiy commit a05a14049999598a3bb6fab12db6b768a0215522 upstream. The change corrects the error path in gpiochip_add_data_with_key() by avoiding to call ida_simple_remove(), if ida_simple_get() returns an error. Note that ida_simple_remove()/ida_free() throws a BUG(), if id argument is negative, it allows to easily check the correctness of the fix by fuzzing the return value from ida_simple_get(). Fixes: ff2b13592299 ("gpio: make the gpiochip a real device") Cc: stable@vger.kernel.org # v4.6+ Signed-off-by: Vladimir Zapolskiy Signed-off-by: Linus Walleij Signed-off-by: Greg Kroah-Hartman --- drivers/gpio/gpiolib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1166,7 +1166,7 @@ int gpiochip_add_data(struct gpio_chip * gdev->descs = kcalloc(chip->ngpio, sizeof(gdev->descs[0]), GFP_KERNEL); if (!gdev->descs) { status = -ENOMEM; - goto err_free_gdev; + goto err_free_ida; } if (chip->ngpio == 0) { @@ -1298,8 +1298,9 @@ err_free_label: kfree(gdev->label); err_free_descs: kfree(gdev->descs); -err_free_gdev: +err_free_ida: ida_simple_remove(&gpio_ida, gdev->id); +err_free_gdev: /* failures here can mean systems won't boot... */ pr_err("%s: GPIOs %d..%d (%s) failed to register\n", __func__, gdev->base, gdev->base + gdev->ngpio - 1,