Skip to contentSkip to conversation

mmc: wmt-sdmmc: fix potential NULL pointer dereference in wmt_mci_probe()

PATCH New Wei Yongjun 2 participants 2 messages Nov 29, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: wmt-sdmmc: fix potential NULL pointer dereference in wmt_mci_probe()

From: Wei Yongjun <[email protected]>

The dereference to 'of_id' should be moved below the NULL test.

---
 drivers/mmc/host/wmt-sdmmc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/wmt-sdmmc.c +2 -1
index 5ba4605..f737b0c 100644
@@ -773,7 +773,7 @@ static int __devinit wmt_mci_probe(struct platform_device *pdev)
 	struct device_node *np = pdev->dev.of_node;
 	const struct of_device_id *of_id =
 		of_match_device(wmt_mci_dt_ids, &pdev->dev);
-	const struct wmt_mci_caps *wmt_caps = of_id->data;
+	const struct wmt_mci_caps *wmt_caps;
 	int ret;
 	int regular_irq, dma_irq;
 
@@ -787,6 +787,7 @@ static int __devinit wmt_mci_probe(struct platform_device *pdev)
 		return -EFAULT;
 	}
 
+	wmt_caps = of_id->data;
 	regular_irq = irq_of_parse_and_map(np, 0);
 	dma_irq = irq_of_parse_and_map(np, 1);
 
#1 lore raw

PATCH 1/1 mmc: wmt-sdmmc: fix potential NULL pointer dereference in wmt_mci_probe()

Quoted 24 lines · Wei Yongjun

From: Wei Yongjun <[email protected]>

The dereference to 'of_id' should be moved below the NULL test.

---
 drivers/mmc/host/wmt-sdmmc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/wmt-sdmmc.c +1 -1
index 5ba4605..f737b0c 100644
@@ -773,7 +773,7 @@ static int __devinit wmt_mci_probe(struct platform_device *pdev)
 	struct device_node *np = pdev->dev.of_node;
 	const struct of_device_id *of_id =
 		of_match_device(wmt_mci_dt_ids, &pdev->dev);
-	const struct wmt_mci_caps *wmt_caps = of_id->data;
+	const struct wmt_mci_caps *wmt_caps;
 	int ret;
 	int regular_irq, dma_irq;
 

drivers/mmc/host/wmt-sdmmc.c static int __devinit wmt_mci_probe(struct platform_device *pdev) · line 793

Quoted 7 lines
drivers/mmc/host/wmt-sdmmc.c +1 -0
@@ -787,6 +787,7 @@ static int __devinit wmt_mci_probe(struct platform_device *pdev)
 		return -EFAULT;
 	}
 
+	wmt_caps = of_id->data;
 	regular_irq = irq_of_parse_and_map(np, 0);
 	dma_irq = irq_of_parse_and_map(np, 1);
 

Arguable this is unnecessary as of_id can never be NULL unless of_match_device return's NULL and since it matches against the same table as the probe that should never happen.

Given that there is a test at the start already for the NULL pointers, this does make sense however - I'm just not sure how it will ever happen. You could just remove the test instead.

Either way, this does fix a 'potential' bug, so if everyone else is happy:

Regards
Tony P