* [PATCH] mfd: mc13xxx: i2c/spi Fix to avoid NULL pointer dereference
@ 2019-03-18 23:15 Aditya Pakki
2019-04-02 6:13 ` Lee Jones
0 siblings, 1 reply; 2+ messages in thread
From: Aditya Pakki @ 2019-03-18 23:15 UTC (permalink / raw)
To: pakki001; +Cc: kjlu, Lee Jones, linux-kernel
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;
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 {
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mfd: mc13xxx: i2c/spi Fix to avoid NULL pointer dereference
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
0 siblings, 0 replies; 2+ messages in thread
From: Lee Jones @ 2019-04-02 6:13 UTC (permalink / raw)
To: Aditya Pakki; +Cc: kjlu, linux-kernel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-04-02 6:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.