From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755285AbdBGQc0 (ORCPT ); Tue, 7 Feb 2017 11:32:26 -0500 Received: from mail-wm0-f51.google.com ([74.125.82.51]:34966 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751540AbdBGQcZ (ORCPT ); Tue, 7 Feb 2017 11:32:25 -0500 Date: Tue, 7 Feb 2017 16:32:21 +0000 From: Lee Jones To: Shailendra Verma Cc: linux-kernel@vger.kernel.org, p.shailesh@samsung.com, ashish.kalra@samsung.com, Shailendra Verma Subject: Re: [PATCH] Mfd - Fix possible NULL derefrence. Message-ID: <20170207163221.jvvbctrqjsjxkldw@dell> References: <1485515805-3598-1-git-send-email-shailendra.v@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1485515805-3598-1-git-send-email-shailendra.v@samsung.com> User-Agent: Mutt/1.6.2-neo (2016-08-21) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 27 Jan 2017, Shailendra Verma wrote: > of_match_device could return NULL, and so can cause a NULL > pointer dereference later. I don't think it can. Did this actually happen to you? > Signed-off-by: Shailendra Verma > --- > drivers/mfd/mc13xxx-i2c.c | 4 ++++ > drivers/mfd/mc13xxx-spi.c | 5 ++++- > 2 files changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/mfd/mc13xxx-i2c.c b/drivers/mfd/mc13xxx-i2c.c > index 67e4c9a..e03f454 100644 > --- a/drivers/mfd/mc13xxx-i2c.c > +++ b/drivers/mfd/mc13xxx-i2c.c > @@ -80,6 +80,10 @@ static int mc13xxx_i2c_probe(struct i2c_client *client, > if (client->dev.of_node) { > const struct of_device_id *of_id = > of_match_device(mc13xxx_dt_ids, &client->dev); > + if (!of_id) { > + dev_err(&client->dev, "Error: No device match found\n"); > + return -ENODEV; > + } > mc13xxx->variant = of_id->data; > } else { > mc13xxx->variant = (void *)id->driver_data; > diff --git a/drivers/mfd/mc13xxx-spi.c b/drivers/mfd/mc13xxx-spi.c > index cbc1e5e..97ab19c 100644 > --- a/drivers/mfd/mc13xxx-spi.c > +++ b/drivers/mfd/mc13xxx-spi.c > @@ -157,7 +157,10 @@ static int mc13xxx_spi_probe(struct spi_device *spi) > if (spi->dev.of_node) { > const struct of_device_id *of_id = > of_match_device(mc13xxx_dt_ids, &spi->dev); > + if (!of_id) { > + dev_err(&spi->dev, "Error: No device match found\n"); > + return -ENODEV; > + } > mc13xxx->variant = of_id->data; > } else { > const struct spi_device_id *id_entry = spi_get_device_id(spi); -- Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog