mtd/m25p80: fix test for end of loop

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Fri Aug 13 16:59:02 EDT 2010


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=f78ec6b2f32efad1fc6b2196e966dcec8122d689
Commit:     f78ec6b2f32efad1fc6b2196e966dcec8122d689
Parent:     b06cd21e2f0f75686f95afa5b71219b1408f5458
Author:     Dan Carpenter <error27 at gmail.com>
AuthorDate: Thu Aug 12 09:58:27 2010 +0200
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Thu Aug 12 12:31:39 2010 +0100

    mtd/m25p80: fix test for end of loop
    
    "plat_id" is always non-NULL here.  There is a zero element on the end
    of the m25p_ids[] array and if we hit the end of the loop then plat_id
    points to that.
    
    This would lead to a NULL pointer dereference later on in the function.
    
    Signed-off-by: Dan Carpenter <error27 at gmail.com>
    Acked-by: Anton Vorontsov <cbouatmailru at gmail.com>
    Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
 drivers/mtd/devices/m25p80.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 83c9086..6f512b5 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -793,7 +793,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
 			break;
 		}
 
-		if (plat_id)
+		if (i < ARRAY_SIZE(m25p_ids) - 1)
 			id = plat_id;
 		else
 			dev_warn(&spi->dev, "unrecognized id %s\n", data->type);



More information about the linux-mtd-cvs mailing list