Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752295AbbKPMOu (ORCPT ); Mon, 16 Nov 2015 07:14:50 -0500 Received: from metis.ext.4.pengutronix.de ([92.198.50.35]:54082 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751636AbbKPMOt (ORCPT ); Mon, 16 Nov 2015 07:14:49 -0500 Date: Mon, 16 Nov 2015 13:14:45 +0100 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: LABBE Corentin Cc: gregkh@linuxfoundation.org, jslaby@suse.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: Re: [PATCH] serial: imx: fix a possible NULL dereference Message-ID: <20151116121445.GC22022@pengutronix.de> References: <1447314381-31145-1-git-send-email-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1447314381-31145-1-git-send-email-clabbe.montjoie@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1706 Lines: 57 Hello, On Thu, Nov 12, 2015 at 08:46:21AM +0100, LABBE Corentin wrote: > of_match_device could return NULL, and so cause a NULL pointer > dereference later. > > Signed-off-by: LABBE Corentin > --- > drivers/tty/serial/imx.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c > index 016e4be..22e91f7 100644 > --- a/drivers/tty/serial/imx.c > +++ b/drivers/tty/serial/imx.c > @@ -1857,8 +1857,7 @@ static int serial_imx_probe_dt(struct imx_port *sport, > struct platform_device *pdev) > { > struct device_node *np = pdev->dev.of_node; > - const struct of_device_id *of_id = > - of_match_device(imx_uart_dt_ids, &pdev->dev); > + const struct of_device_id *of_id; > int ret; > > if (!np) > @@ -1878,6 +1877,9 @@ static int serial_imx_probe_dt(struct imx_port *sport, > if (of_get_property(np, "fsl,dte-mode", NULL)) > sport->dte_mode = 1; > > + of_id = of_match_device(imx_uart_dt_ids, &pdev->dev); > + if (!of_id) > + return -ENODEV; > sport->devdata = of_id->data; > > return 0; I'd do something like: - if (!np) + sport->devdata = of_device_get_match_data(&pdev->dev); + if (!sport->devdata) /* no device tree device */ return 1; instead. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ | -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/