From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 944B5C433E1 for ; Mon, 1 Jun 2020 18:04:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C45F206E2 for ; Mon, 1 Jun 2020 18:04:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591034659; bh=WBCdEH8GKHz5nCd+RlGwF13pOXtU5+lvt/v8NAxJiKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Aqlh5D4eaTySKpziOPNuXtt1Cn8uE/Xvr1N3pJDsxQlo2+1yAHqqx13eH6ssmFThj 4fjKfqfOk3hXQJeI/aQUxooV4IuQqr2MkE5L41TGIfUubz625J9FrG3zHPnI2dK5+R L2VV6KgL4Hj/nqcIxMkFNhYX0i02YGqwLg/kFblQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730185AbgFASES (ORCPT ); Mon, 1 Jun 2020 14:04:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:48760 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730183AbgFASEQ (ORCPT ); Mon, 1 Jun 2020 14:04:16 -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 611A52077D; Mon, 1 Jun 2020 18:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591034655; bh=WBCdEH8GKHz5nCd+RlGwF13pOXtU5+lvt/v8NAxJiKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ssGeDVoQKSbYi1R9NBTOHx9pXaP6e8WY/dV98Z9gWzxFIA50nuLiCyjUWGoSD8qqG zMq0VDMlkSufpxDKGA6X5cfffl8z0fhSS0oRj/p1NCYqyvAhsxB3t/zQgda3RWxaxM +e2WsFplU89l/ps1vw8Nq4KQtdVRzFYLRfJiUGTY= 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 4.19 50/95] gpio: exar: Fix bad handling for ida_simple_get error path Date: Mon, 1 Jun 2020 19:53:50 +0200 Message-Id: <20200601174029.021922373@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200601174020.759151073@linuxfoundation.org> References: <20200601174020.759151073@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 a09d2f9ebacc..695c19901eff 100644 --- a/drivers/gpio/gpio-exar.c +++ b/drivers/gpio/gpio-exar.c @@ -148,8 +148,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; @@ -176,6 +178,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