Skip to contentSkip to conversation

i2c/i2c-pxa: Fix possible NULL pointer dereference

PATCH In review Syam Sidhardhan 2 participants 3 messages Feb 24, 2013 – Feb 25, 2013 2 messages not in the archive I2C subsystem host drivers

lore
Share & tools
lore
#0 lore raw

PATCH 7/59 i2c/i2c-pxa: Fix possible NULL pointer dereference

When platform_get_resource() returns NULL, there is a possible NULL pointer dereference in release_mem_region(). Rearrange the goto lables appropriately.

---

Only compile tested.

 drivers/i2c/busses/i2c-pxa.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-pxa.c +5 -5
index 1034d93..7ddda5c 100644
@@ -1104,18 +1104,18 @@ static int i2c_pxa_probe(struct platform_device *dev)
 	if (ret > 0)
 		ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type);
 	if (ret < 0)
-		goto eclk;
+		goto emalloc;
 
 	res = platform_get_resource(dev, IORESOURCE_MEM, 0);
 	irq = platform_get_irq(dev, 0);
 	if (res == NULL || irq < 0) {
 		ret = -ENODEV;
-		goto eclk;
+		goto emalloc;
 	}
 
 	if (!request_mem_region(res->start, resource_size(res), res->name)) {
 		ret = -ENOMEM;
-		goto eclk;
+		goto emalloc;
 	}
 
 	i2c->adap.owner   = THIS_MODULE;
@@ -1209,9 +1209,9 @@ ereqirq:
 eremap:
 	clk_put(i2c->clk);
 eclk:
-	kfree(i2c);
-emalloc:
 	release_mem_region(res->start, resource_size(res));
+emalloc:
+	kfree(i2c);
 	return ret;
 }
 
Signature · 1 line
1.7.9.5

A message that is not in the archive (sent off-list or not yet received): 1361745852-28629-1-git-send-email-s.syam-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org

#2 lore raw
Quoted 5 lines · Syam Sidhardhan

When platform_get_resource() returns NULL, there is a possible NULL pointer dereference in release_mem_region(). Rearrange the goto lables appropriately.

I think this has been already addressed in [1],
but I don't know if it was applied already...

[1] https://patchwork.kernel.org/patch/2141301/

Quoted 46 lines

---

Only compile tested.

 drivers/i2c/busses/i2c-pxa.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-pxa.c +5 -5
index 1034d93..7ddda5c 100644
@@ -1104,18 +1104,18 @@ static int i2c_pxa_probe(struct platform_device *dev)
 	if (ret > 0)
 		ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type);
 	if (ret < 0)
-		goto eclk;
+		goto emalloc;
 
 	res = platform_get_resource(dev, IORESOURCE_MEM, 0);
 	irq = platform_get_irq(dev, 0);
 	if (res == NULL || irq < 0) {
 		ret = -ENODEV;
-		goto eclk;
+		goto emalloc;
 	}
 
 	if (!request_mem_region(res->start, resource_size(res), res->name)) {
 		ret = -ENOMEM;
-		goto eclk;
+		goto emalloc;
 	}
 
 	i2c->adap.owner   = THIS_MODULE;
@@ -1209,9 +1209,9 @@ ereqirq:
 eremap:
 	clk_put(i2c->clk);
 eclk:
-	kfree(i2c);
-emalloc:
 	release_mem_region(res->start, resource_size(res));
+emalloc:
+	kfree(i2c);
 	return ret;
 }
 
Signature · 2 lines
Regards,
Igor.

A message that is not in the archive (sent off-list or not yet received): 512B245A.1020703-UTxiZqZC01RS1MOuV/[email protected]

#4 lore raw

Hi Igor,

Quoted 44 lines · Igor Grinberg
Quoted 5 lines · Syam Sidhardhan

When platform_get_resource() returns NULL, there is a possible NULL pointer dereference in release_mem_region(). Rearrange the goto lables appropriately.

I think this has been already addressed in [1],
but I don't know if it was applied already...

[1] https://patchwork.kernel.org/patch/2141301/

Quoted 32 lines

---

Only compile tested.

 drivers/i2c/busses/i2c-pxa.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-pxa.c +3 -3
index 1034d93..7ddda5c 100644
@@ -1104,18 +1104,18 @@ static int i2c_pxa_probe(struct platform_device *dev)
      if (ret > 0)
              ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type);
      if (ret < 0)
-             goto eclk;
+             goto emalloc;
 
      res = platform_get_resource(dev, IORESOURCE_MEM, 0);
      irq = platform_get_irq(dev, 0);
      if (res == NULL || irq < 0) {
              ret = -ENODEV;
-             goto eclk;
+             goto emalloc;
      }
 
      if (!request_mem_region(res->start, resource_size(res), res->name)) {
              ret = -ENOMEM;
-             goto eclk;
+             goto emalloc;
      }
 
Quoted 13 lines

drivers/i2c/busses/i2c-pxa.c ereqirq: · line 1217

Quoted 13 lines
drivers/i2c/busses/i2c-pxa.c +2 -2
      i2c->adap.owner   = THIS_MODULE;
@@ -1209,9 +1209,9 @@ ereqirq:
 eremap:
      clk_put(i2c->clk);
 eclk:
-     kfree(i2c);
-emalloc:
      release_mem_region(res->start, resource_size(res));
+emalloc:
+     kfree(i2c);
      return ret;
 }
 

You are correct. It has been already posted by Cong Ding. Kindly ignore this patch.

Thanks,
Syam