Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp669508ybg; Mon, 1 Jun 2020 11:14:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHwz9Fh1IgW8H0SHhnFqotWvvi1AsaJ7YHnoT58BEQy2qC+rrk1O2IuohiLn9Yr0ijHf12 X-Received: by 2002:a17:906:7395:: with SMTP id f21mr9589960ejl.178.1591035252433; Mon, 01 Jun 2020 11:14:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591035252; cv=none; d=google.com; s=arc-20160816; b=HDgMXus6pLgaVS3fYzWVW2dwl3JfNM2BXL1KQ80gXUVVzbgE2OGsNsub+Va5VGriq3 +ZHyj0ErDrOgfmhqA4kqVR6x5x1fEpx9VvUomY9xio7O6zmObKZGi6roGdS40lk2O64U OIP6PyPvs/pexztOC0iMY73j+PKtAJMnQuNkCJeBS2mQQBkX49JUrHYCit/du/ZI5YjH r2fEyZ/k6wW5JVUahCuKUZ+NqraWI4olOU0xaNzsfzttuPlL0AK5qcTkZ3Erf86mdPh5 yhHvRI2230BsAxQa140U/mtTEbjZIBwUM7LbKcjOHkY/BjV1YGeLxZ+g5iNn4TLU8ywd uD4A== 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=0guP/+SgkHaurXa+ko0vRvtiGb73kCMKA7tImmPTA/o=; b=Jn0mF/KdtiWAUZ7XphwYsNQaRq9NU1EyIOO6vsI+WF9byMTL67QfBdfp6j3e+tE+Cd qlYE1iYpI6Th5iFQraIebQseCIr9ihiTRbe6JZJfa3N9Yd+rAyUMc4P3KX9WZ7JC1sH1 6eLEvBsPco0iaCIabJ7NvbvOTyvdYSGRXgelbk0o4c5BGjeoDZEwMkYAOFLCSQ897KIg bnB8fauliFwzbw6/zv1wYkPwTvDH8WQuSswcHWnT8p0/kSpyCRWvP0xvEm7/ODJSOVxe C0vNe9urIA2TAKLyVEfEPMTA+OYyuuLZ3B1h3iTha6PXuFcQZI0uzb9WicO3nG/qpsvI gpyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VUdEAOhw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id do2si152223ejc.178.2020.06.01.11.13.49; Mon, 01 Jun 2020 11:14:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VUdEAOhw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730788AbgFASIv (ORCPT + 99 others); Mon, 1 Jun 2020 14:08:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:55010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730770AbgFASIr (ORCPT ); Mon, 1 Jun 2020 14:08:47 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 B3EF92068D; Mon, 1 Jun 2020 18:08:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591034926; bh=3mXHuIbUAn2ZlS3EHaOUlbTu8JdHRMn00oCcVfkK2NQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VUdEAOhwG0sittEl/ivrRw3AVsjIx8WYnvx0ixPkTPEyKXAAtdk5o5o3sIlmMa46t fFBxAAnS8lAJ0vQ80opl6mwIpXNC1HSvH/rfJZLvjFbJNnXdbJZs4+CvcE3u6tsBwY eTSehGxah3IORDn0GGr0fVWyP0JAvuqtSkLHhGd8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Bartosz Golaszewski , Sasha Levin Subject: [PATCH 5.4 075/142] gpio: exar: Fix bad handling for ida_simple_get error path Date: Mon, 1 Jun 2020 19:53:53 +0200 Message-Id: <20200601174045.626573803@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200601174037.904070960@linuxfoundation.org> References: <20200601174037.904070960@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Takashi Iwai [ Upstream commit 333830aa149a87cabeb5d30fbcf12eecc8040d2c ] The commit 7ecced0934e5 ("gpio: exar: add a check for the return value of ida_simple_get fails") added a goto jump to the common error handler for ida_simple_get() error, but this is wrong in two ways: it doesn't set the proper return code and, more badly, it invokes ida_simple_remove() with a negative index that shall lead to a kernel panic via BUG_ON(). This patch addresses those two issues. Fixes: 7ecced0934e5 ("gpio: exar: add a check for the return value of ida_simple_get fails") Cc: Signed-off-by: Takashi Iwai Signed-off-by: Bartosz Golaszewski Signed-off-by: Sasha Levin --- drivers/gpio/gpio-exar.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c index fae327d5b06e..6890d32d9f25 100644 --- a/drivers/gpio/gpio-exar.c +++ b/drivers/gpio/gpio-exar.c @@ -145,8 +145,10 @@ static int gpio_exar_probe(struct platform_device *pdev) mutex_init(&exar_gpio->lock); index = ida_simple_get(&ida_index, 0, 0, GFP_KERNEL); - if (index < 0) - goto err_destroy; + if (index < 0) { + ret = index; + goto err_mutex_destroy; + } sprintf(exar_gpio->name, "exar_gpio%d", index); exar_gpio->gpio_chip.label = exar_gpio->name; @@ -173,6 +175,7 @@ static int gpio_exar_probe(struct platform_device *pdev) err_destroy: ida_simple_remove(&ida_index, index); +err_mutex_destroy: mutex_destroy(&exar_gpio->lock); return ret; } -- 2.25.1