Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2563039imu; Thu, 29 Nov 2018 06:58:10 -0800 (PST) X-Google-Smtp-Source: AFSGD/XnfaTcnQ8duQdDeFbF5dkkUG8HTQQtDmKwlQwzGD9hbCgInLeoy+pVz8xqEu7YImUDcWvz X-Received: by 2002:a63:4706:: with SMTP id u6mr1414203pga.95.1543503490885; Thu, 29 Nov 2018 06:58:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543503490; cv=none; d=google.com; s=arc-20160816; b=OjiAX7SxYkJHijzkKrCAwo8vUJ7frYr3exQC7U5st+n69vzrGgPDq5EpDYQdnKqi0o 3S4cTqCufu8A+87yLEvwsEUln3z8cWLaybv8kPyW72TtdlwTIlg39otAjAojkijsS2AZ 9eJVGN1kuMlb6nCxkhpI5IOYBLbneSoxC3udye/M2uPHumewdZQkGUxmusH6wT4EhmDX YLU+hjkJ3kzicChOLStwxl+vIMxZ4yWdBMc8L2eEJc7Jms+puJdSB0NpNAKQRM6FxeiP 8oTxdf12vzKNY2ACGehvKk6eciGL+zIzWXW0lX8uYSOsmdPqlYgAiZeUvuJgiMKYg6nb zPQA== 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=UJl3ndaYog/fW21+huqIO7XGIl8zuMmPtt+ofrcEczQ=; b=asifq6U6mJM0V/O3hb7JESnctqQHI2gSq97Rj5cZksw1jt5ClzW9G324tPBnyqR1X/ Iw4rtvkpZzjiCtOHCcCONLk5dVYkE7lAP1kp5w6UpDFh2YTZJwTlmyb0B3krb+yXmB0c IwfNHJbS8Bftgyi7wJ+jdA+nTmLBUP96BIy0kZC5LjazXzP2cQTWHij2OSESg6WSF/KB SwJs3Hut6L0Gpq7EVCU8iZs4KuGNfDraDLIf94dL5A5aaRg5WGx4ogX6933Vl4lz5fIz mia+9uXxqX0iZLbKLaqMlVjdzm00pV9LApANe5TOU235/E2W0bjXhmgI1TV8Ufd28qAR no/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rw9KwYZY; 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 w12si2278260pgl.122.2018.11.29.06.57.56; Thu, 29 Nov 2018 06:58:10 -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=rw9KwYZY; 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 S1731590AbeK3B0o (ORCPT + 99 others); Thu, 29 Nov 2018 20:26:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:50976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730453AbeK3B0n (ORCPT ); Thu, 29 Nov 2018 20:26:43 -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 AC6EE205C9; Thu, 29 Nov 2018 14:21:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501272; bh=iKuvD7zmvPLXYXxQxuv164In8l5Iuk/bePECyuJOR1A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rw9KwYZYF+cUUtQwfEdphGrt7wqsGzhS/d+l41pkUk7BbqEpPAvaPPGyXzKUvNBPw FislHV4yPtZR+D42cFGp5hQy7zojE62zMrWdCN0SgRwZD3o6XQt5PmzE7RTiIwFMI3 EUmuoSgECgeEC6UT03RR/AYREK+p84D7p5tPmUpc= 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.9 05/92] gpio: dont free unallocated ida on gpiochip_add_data_with_key() error path Date: Thu, 29 Nov 2018 15:11:34 +0100 Message-Id: <20181129140106.922908269@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140106.520639693@linuxfoundation.org> References: <20181129140106.520639693@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.9-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 @@ -1153,7 +1153,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) { @@ -1285,8 +1285,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,