From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-co1nam03on0122.outbound.protection.outlook.com ([104.47.40.122]:59200 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933458AbeCSPrg (ORCPT ); Mon, 19 Mar 2018 11:47:36 -0400 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Vladimir Zapolskiy , Linus Walleij , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 027/124] gpiolib: don't dereference a desc before validation Date: Mon, 19 Mar 2018 15:47:26 +0000 Message-ID: <20180319154645.11350-27-alexander.levin@microsoft.com> References: <20180319154645.11350-1-alexander.levin@microsoft.com> In-Reply-To: <20180319154645.11350-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Vladimir Zapolskiy [ Upstream commit 30322bcf82d74cad0d6e1cf9ba7fa7fa48c7a026 ] The fix restores a proper validation of an input gpio desc, which might be needed to deal with optional GPIOs correctly. Fixes: 02e479808b5d ("gpio: Alter semantics of *raw* operations to actually= be raw") Signed-off-by: Vladimir Zapolskiy Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/gpio/gpiolib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f6efcf94f6ad..8abdd0035091 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2459,7 +2459,7 @@ EXPORT_SYMBOL_GPL(gpiod_direction_output_raw); */ int gpiod_direction_output(struct gpio_desc *desc, int value) { - struct gpio_chip *gc =3D desc->gdev->chip; + struct gpio_chip *gc; int ret; =20 VALIDATE_DESC(desc); @@ -2476,6 +2476,7 @@ int gpiod_direction_output(struct gpio_desc *desc, in= t value) return -EIO; } =20 + gc =3D desc->gdev->chip; if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) { /* First see if we can enable open drain in hardware */ ret =3D gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc), --=20 2.14.1