linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: rawnand: vf610: Fix to check for NULL pointer dereference
@ 2019-03-18 23:24 Aditya Pakki
  2019-04-01 15:26 ` Miquel Raynal
  0 siblings, 1 reply; 3+ messages in thread
From: Aditya Pakki @ 2019-03-18 23:24 UTC (permalink / raw)
  To: pakki001
  Cc: Boris Brezillon, Richard Weinberger, kjlu, linux-kernel,
	Stefan Agner, Marek Vasut, linux-mtd, Miquel Raynal,
	Brian Norris, David Woodhouse

of_match_device can return NULL if there is no matching device is found.
The patch avoids a potential NULL pointer dereference by checking for the
return value and passing the error upstream.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
 drivers/mtd/nand/raw/vf610_nfc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c
index a662ca1970e5..946abbb275c3 100644
--- a/drivers/mtd/nand/raw/vf610_nfc.c
+++ b/drivers/mtd/nand/raw/vf610_nfc.c
@@ -850,6 +850,8 @@ static int vf610_nfc_probe(struct platform_device *pdev)
 	}
 
 	of_id = of_match_device(vf610_nfc_dt_ids, &pdev->dev);
+	if (!of_id)
+		return -ENODEV;
 	nfc->variant = (enum vf610_nfc_variant)of_id->data;
 
 	for_each_available_child_of_node(nfc->dev->of_node, child) {
-- 
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mtd: rawnand: vf610: Fix to check for NULL pointer dereference
  2019-03-18 23:24 [PATCH] mtd: rawnand: vf610: Fix to check for NULL pointer dereference Aditya Pakki
@ 2019-04-01 15:26 ` Miquel Raynal
  2019-04-01 15:30   ` Boris Brezillon
  0 siblings, 1 reply; 3+ messages in thread
From: Miquel Raynal @ 2019-04-01 15:26 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: Boris Brezillon, Richard Weinberger, kjlu, linux-kernel,
	Stefan Agner, Marek Vasut, linux-mtd, Brian Norris,
	David Woodhouse

Hi Aditya,

Aditya Pakki <pakki001@umn.edu> wrote on Mon, 18 Mar 2019 18:24:34
-0500:

> of_match_device can return NULL if there is no matching device is found.
> The patch avoids a potential NULL pointer dereference by checking for the
> return value and passing the error upstream.
> 
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
>  drivers/mtd/nand/raw/vf610_nfc.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c
> index a662ca1970e5..946abbb275c3 100644
> --- a/drivers/mtd/nand/raw/vf610_nfc.c
> +++ b/drivers/mtd/nand/raw/vf610_nfc.c
> @@ -850,6 +850,8 @@ static int vf610_nfc_probe(struct platform_device *pdev)
>  	}
>  
>  	of_id = of_match_device(vf610_nfc_dt_ids, &pdev->dev);
> +	if (!of_id)
> +		return -ENODEV;
>  	nfc->variant = (enum vf610_nfc_variant)of_id->data;
>  
>  	for_each_available_child_of_node(nfc->dev->of_node, child) {


Applied to git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git
on nand/next with the title changed to

        mtd: rawnand: vf610: Avoid a potential NULL pointer dereference

and a space after the return statement.

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mtd: rawnand: vf610: Fix to check for NULL pointer dereference
  2019-04-01 15:26 ` Miquel Raynal
@ 2019-04-01 15:30   ` Boris Brezillon
  0 siblings, 0 replies; 3+ messages in thread
From: Boris Brezillon @ 2019-04-01 15:30 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Boris Brezillon, Richard Weinberger, kjlu, linux-kernel,
	Stefan Agner, Marek Vasut, linux-mtd, Aditya Pakki, Brian Norris,
	David Woodhouse

On Mon, 1 Apr 2019 17:26:51 +0200
Miquel Raynal <miquel.raynal@bootlin.com> wrote:

> Hi Aditya,
> 
> Aditya Pakki <pakki001@umn.edu> wrote on Mon, 18 Mar 2019 18:24:34
> -0500:
> 
> > of_match_device can return NULL if there is no matching device is found.
> > The patch avoids a potential NULL pointer dereference by checking for the
> > return value and passing the error upstream.
> > 
> > Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> > ---
> >  drivers/mtd/nand/raw/vf610_nfc.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c
> > index a662ca1970e5..946abbb275c3 100644
> > --- a/drivers/mtd/nand/raw/vf610_nfc.c
> > +++ b/drivers/mtd/nand/raw/vf610_nfc.c
> > @@ -850,6 +850,8 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> >  	}
> >  
> >  	of_id = of_match_device(vf610_nfc_dt_ids, &pdev->dev);
> > +	if (!of_id)
> > +		return -ENODEV;

For the record, this can't happen unless you have serious memory
corruption issues since you reached the ->probe() function (which means
a match was found before).

> >  	nfc->variant = (enum vf610_nfc_variant)of_id->data;
> >  
> >  	for_each_available_child_of_node(nfc->dev->of_node, child) {  
> 
> 
> Applied to git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git
> on nand/next with the title changed to
> 
>         mtd: rawnand: vf610: Avoid a potential NULL pointer dereference
> 
> and a space after the return statement.
> 
> Thanks,
> Miquèl


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-04-01 15:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-18 23:24 [PATCH] mtd: rawnand: vf610: Fix to check for NULL pointer dereference Aditya Pakki
2019-04-01 15:26 ` Miquel Raynal
2019-04-01 15:30   ` Boris Brezillon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).