Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp714828ybi; Fri, 2 Aug 2019 03:05:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqydxedhCb9LJeDxoJ44mAgkUt1QJ1A4iw9L4q9TlCiRJindcHZtewwfp9hWJ+NwtjK/hDHD X-Received: by 2002:a65:430a:: with SMTP id j10mr46372666pgq.374.1564740349472; Fri, 02 Aug 2019 03:05:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564740349; cv=none; d=google.com; s=arc-20160816; b=ZqLXDLFdDY95YRDXQ2X/j+fqdf8kqpjNyaILZbQnpcodGwEOD0CjdWldqlgT7x7og/ OXSmmNl0KxE1YJax4ZeT11AzJYYpXFT1PI2dkdVvplN5/Q0VsdR76k/hlH1usBk9dfCS 69b35OShRbPbFjMXyEex8Ohm1nN7Vq5lq8t26CMXM2+HamWWvETvnpHZpNmpcCinY8BD yGEsteWobnJ3EgKtNeu8yQMj4euy9DhefC02bMxXPSt/5ZsKM+F2t7ol4R16DyheP5LF djw9d7Arb3HkKmGJtEo20D2116CkVD0XMju2t8f09Vgf+uTE3fdpRLtrqA6VhcrzJtps Oczw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=gjfklnZC2Y7bgn8V1Ft36keFD0p4b7WYoumIYH1Qe1I=; b=vK3wFPwZaFdWbwnLji1mMAya4EFK1rkV4z3DQTpU7lXvYu1YQTurxlMVenO/XmDvLL KXOlEU5atT6CJLM5HwzMgHsnRSETIkTkoRZKl/lBrTVrT/gNInK5elq1Uzw2KU7zNqKO zQJtK1gooPct5I+W6pUjXuwLDmfldlk3Tdm6RXWZCF3QSZa8siy5Nz6REzkaPBCC4rDD Xn8Rnb5wNG1PyMs0+klhoZSB4tVVRdmx4Q1xgqEt+ghRnIK/S1E6QhlTVnrXvYTSrnH4 VnMtMOHnsS7wK5GCmB4wegGMwyxsvX22TGGE2Dr63/YOHLJ2vZLFXQjMeRLfN+5SxoGj Fvxw== ARC-Authentication-Results: i=1; mx.google.com; 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 a10si37700348pfc.215.2019.08.02.03.05.33; Fri, 02 Aug 2019 03:05:49 -0700 (PDT) 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; 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 S2407198AbfHBKE2 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 2 Aug 2019 06:04:28 -0400 Received: from skedge03.snt-world.com ([91.208.41.68]:58098 "EHLO skedge03.snt-world.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390359AbfHBKEN (ORCPT ); Fri, 2 Aug 2019 06:04:13 -0400 Received: from sntmail14r.snt-is.com (unknown [10.203.32.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by skedge03.snt-world.com (Postfix) with ESMTPS id D95F5603D2C; Fri, 2 Aug 2019 12:04:10 +0200 (CEST) Received: from sntmail12r.snt-is.com (10.203.32.182) by sntmail14r.snt-is.com (10.203.32.184) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Fri, 2 Aug 2019 12:04:10 +0200 Received: from sntmail12r.snt-is.com ([fe80::e551:8750:7bba:3305]) by sntmail12r.snt-is.com ([fe80::e551:8750:7bba:3305%3]) with mapi id 15.01.1713.004; Fri, 2 Aug 2019 12:04:10 +0200 From: Schrempf Frieder To: "u.kleine-koenig@pengutronix.de" , "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "kernel@pengutronix.de" , "festevam@gmail.com" , "linux-imx@nxp.com" , Greg Kroah-Hartman CC: "linux-arm-kernel@lists.infradead.org" , "geert+renesas@glider.be" , Schrempf Frieder , Jiri Slaby , "linux-serial@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH v3 2/4] serial: mctrl_gpio: Add a NULL check to mctrl_gpio_to_gpiod() Thread-Topic: [PATCH v3 2/4] serial: mctrl_gpio: Add a NULL check to mctrl_gpio_to_gpiod() Thread-Index: AQHVSRmhj6XM1Buz9UqFmvYk2hHNCA== Date: Fri, 2 Aug 2019 10:04:10 +0000 Message-ID: <20190802100349.8659-2-frieder.schrempf@kontron.de> References: <20190802100349.8659-1-frieder.schrempf@kontron.de> In-Reply-To: <20190802100349.8659-1-frieder.schrempf@kontron.de> Accept-Language: de-DE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.17.1 x-originating-ip: [172.25.9.193] x-c2processedorg: 51b406b7-48a2-4d03-b652-521f56ac89f3 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-SnT-MailScanner-Information: Please contact the ISP for more information X-SnT-MailScanner-ID: D95F5603D2C.AF9B6 X-SnT-MailScanner: Not scanned: please contact your Internet E-Mail Service Provider for details X-SnT-MailScanner-SpamCheck: X-SnT-MailScanner-From: frieder.schrempf@kontron.de X-SnT-MailScanner-To: festevam@gmail.com, geert+renesas@glider.be, gregkh@linuxfoundation.org, jslaby@suse.com, kernel@pengutronix.de, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, s.hauer@pengutronix.de, shawnguo@kernel.org, u.kleine-koenig@pengutronix.de X-Spam-Status: No Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Frieder Schrempf As it is allowed to use the mctrl_gpio_* functions before initialization (as the 8250 driver does according to 434be0ae7aa7), it seems appropriate to have a NULL check in all of the functions. Otherwise the mctrl_gpio_to_gpiod() function is prone to be used in a context that can lead to a NULL pointer dereference. Signed-off-by: Frieder Schrempf --- Changes in v3 ============= * Move the changes in mctrl_gpio_to_gpiod() to a separate patch --- drivers/tty/serial/serial_mctrl_gpio.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c index 2b400189be91..54c43e02e375 100644 --- a/drivers/tty/serial/serial_mctrl_gpio.c +++ b/drivers/tty/serial/serial_mctrl_gpio.c @@ -61,6 +61,9 @@ EXPORT_SYMBOL_GPL(mctrl_gpio_set); struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios, enum mctrl_gpio_idx gidx) { + if (gpios == NULL) + return NULL; + return gpios->gpio[gidx]; } EXPORT_SYMBOL_GPL(mctrl_gpio_to_gpiod); -- 2.17.1