From: Lee Jones <lee.jones@linaro.org>
To: Aditya Pakki <pakki001@umn.edu>
Cc: kjlu@umn.edu, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mfd: mc13xxx: i2c/spi Fix to avoid NULL pointer dereference
Date: Tue, 2 Apr 2019 07:13:48 +0100 [thread overview]
Message-ID: <20190402061348.GT4187@dell> (raw)
In-Reply-To: <20190318231554.8862-1-pakki001@umn.edu>
On Mon, 18 Mar 2019, Aditya Pakki wrote:
> of_match_device can return NULL if no matching device is found. The patches
> avoids a scenario causing null pointer dereference.
>
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
> drivers/mfd/mc13xxx-i2c.c | 2 ++
> drivers/mfd/mc13xxx-spi.c | 2 ++
> 2 files changed, 4 insertions(+)
>
> diff --git a/drivers/mfd/mc13xxx-i2c.c b/drivers/mfd/mc13xxx-i2c.c
> index 67e4c9aa7d18..1fbc9713bb9a 100644
> --- a/drivers/mfd/mc13xxx-i2c.c
> +++ b/drivers/mfd/mc13xxx-i2c.c
> @@ -80,6 +80,8 @@ 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)
> + return -ENODEV;
Are you sure this can happen?
I don't think this is possible if client->dev.of_node is non-NULL.
The 'if (client->dev.of_node)' above should see to that.
> 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 ee3411cc5ce4..c044a02bdb64 100644
> --- a/drivers/mfd/mc13xxx-spi.c
> +++ b/drivers/mfd/mc13xxx-spi.c
> @@ -158,6 +158,8 @@ 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)
> + return -ENODEV;
>
> mc13xxx->variant = of_id->data;
> } else {
--
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
prev parent reply other threads:[~2019-04-02 6:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-18 23:15 [PATCH] mfd: mc13xxx: i2c/spi Fix to avoid NULL pointer dereference Aditya Pakki
2019-04-02 6:13 ` Lee Jones [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190402061348.GT4187@dell \
--to=lee.jones@linaro.org \
--cc=kjlu@umn.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=pakki001@umn.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox