Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2543774imu; Thu, 29 Nov 2018 06:39:49 -0800 (PST) X-Google-Smtp-Source: AFSGD/UVvslx2Ev7w1lf6BYWxKsiGpwwOmyMFGlIc95QBamP4dWlIqmNRtJ8kBgXbQ+PRv/2l+ow X-Received: by 2002:a62:f54f:: with SMTP id n76mr1632507pfh.59.1543502389584; Thu, 29 Nov 2018 06:39:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543502389; cv=none; d=google.com; s=arc-20160816; b=ngJv4Bv2whGQLZY1NAm3swgxkz0pWaLQXd0VuybY8qa7TUQfHi77m7n4Vybpv1SzUM lIYZH/qoYKOw3rxbbL42GieHalP33w9kdDePQCRrFuIj0J7Ix/Np/drPygJiD0DoDOPK fTiu/yGNqveNXbVK+A3DtyDWX4AN5usVDHcS0vVf1nnPBVd9+7hHktQHoC0/MbHkZ79Q SzjzM9woaVVId7qaRcISCn7QEEL6i2NNQJMkrmcX6vLuuBtjMIAyJ1bPS1AdjG08zzy2 csekCdki3RL0sx8MQsmm3HtPfDaAez4CwzkgLlfHlpvtNBzpKzGnsw1hYdxrTciGU8e8 GL1A== 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=j5/9IB0jpZwh86jBW5kTW52NcoIGziPmuQKwWbym0+4=; b=djjw3PQKVWa9aHgqEC5tbKkXyvALrse6WO6OGPZgNvytYN71/994y4vRCa/W4MNaan HtdTWUbPbg+6e3dtaEFlcNqZRLYNDR3nUqOTEKiGbpCFebfvLqU6yaZBgSZShMoGrjkq k/tMbK3tT9SuyBM/jf3KqqZWIawAi/nDwVWrwSCqousisw0uE1ziecAMQophm6DkAYsd Tjf4vrqxy4ZICpv/u/Je501h5n5wYNGPE1ECr5r08Aj0yrc9KDBmIOzQGI3R8fugh4gT vMF61P7xxZL7zu5j07EoUi63cLZCJXXJhSRGyuoOoIm6oKqvSxtmN9539Bz86ki1TV5E U1jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SJ8784UH; 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 76si2360097pfw.66.2018.11.29.06.39.30; Thu, 29 Nov 2018 06:39:49 -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=SJ8784UH; 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 S2388759AbeK3Bf4 (ORCPT + 99 others); Thu, 29 Nov 2018 20:35:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:37976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728991AbeK3Bfz (ORCPT ); Thu, 29 Nov 2018 20:35:55 -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 3912C2145D; Thu, 29 Nov 2018 14:30:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501822; bh=B4sb9X+S5TgnVwWRckFR4ENon+1eK0JZA39+d4J7rqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SJ8784UHgXI+3X3qggNqJYlJCshwr33cub87bpgpPVCkbAi8KuqJfAjypGr5UIiLg cgUaFpwHtwpb4qOo/sDzG4FtbFE2cEYG4O0sJ/gF2k45UA7WoZJdM0HxRrSgHMrbkn 7M8ihNpDhv7y4lO4Qkk2AvQApfSbw/0OYLYWQIyQ= 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.19 021/110] gpio: dont free unallocated ida on gpiochip_add_data_with_key() error path Date: Thu, 29 Nov 2018 15:11:52 +0100 Message-Id: <20181129135922.111070538@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129135921.231283053@linuxfoundation.org> References: <20181129135921.231283053@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.19-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 @@ -1285,7 +1285,7 @@ int gpiochip_add_data_with_key(struct gp 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) { @@ -1413,8 +1413,9 @@ err_free_label: kfree_const(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, %d\n", __func__, gdev->base, gdev->base + gdev->ngpio - 1,