* [PATCH] i2c: dereference of NULL if request_irq() failsin sh_mobile_i2c_hook_irqs()
@ 2010-02-19 20:14 Roel Kluin
0 siblings, 0 replies; only message in thread
From: Roel Kluin @ 2010-02-19 20:14 UTC (permalink / raw)
To: Ben Dooks, linux-i2c-u79uwXL29TY76Z2rM5mHXA, Andrew Morton, LKML
In the last iteration k equals 0, so we call platform_get_resource() with
-1 as a third argument. Since platform_get_resource() uses an unsigned it
is converted to 0xffffffff. platform_get_resource() fails for every index
and returns NULL. A test is lacking and we dereference NULL.
Also the variable q was assigned but not used.
Signed-off-by: Roel Kluin <roel.kluin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/i2c/busses/i2c-sh_mobile.c | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index ccc4641..5871335 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -496,7 +496,7 @@ static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook)
{
struct resource *res;
int ret = -ENXIO;
- int q, m;
+ int m;
int k = 0;
int n = 0;
@@ -516,12 +516,16 @@ static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook)
ret = 0;
rollback:
- for (q = k; k >= 0; k--) {
- for (m = n; m >= res->start; m--)
- free_irq(m, dev);
+ for (m = n; m >= res->start; m--)
+ free_irq(m, dev);
+ while (k--) {
res = platform_get_resource(dev, IORESOURCE_IRQ, k - 1);
- m = res->end;
+ if (res == NULL)
+ break;
+
+ for (m = res->end; m >= res->start; m--)
+ free_irq(m, dev);
}
return ret;
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2010-02-19 20:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-19 20:14 [PATCH] i2c: dereference of NULL if request_irq() failsin sh_mobile_i2c_hook_irqs() Roel Kluin
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).