2006-09-27 09:40:22

by Amol Lad

[permalink] [raw]
Subject: [PATCH] ioremap balanced with iounmap for drivers/sbus

ioremap must be balanced by an iounmap and failing to do so can result
in a memory leak.

Tested (compilation only) with:
- Modifying arch/i386/Kconfig and other Makefiles to make sure that the
changed file is compiling ok.

Signed-off-by: Amol Lad <[email protected]>
---
vfc_dev.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletion(-)
---
diff -uprN -X linux-2.6.18-orig/Documentation/dontdiff linux-2.6.18-orig/drivers/sbus/char/vfc_dev.c linux-2.6.18/drivers/sbus/char/vfc_dev.c
--- linux-2.6.18-orig/drivers/sbus/char/vfc_dev.c 2006-09-21 10:15:38.000000000 +0530
+++ linux-2.6.18/drivers/sbus/char/vfc_dev.c 2006-09-27 14:46:59.000000000 +0530
@@ -678,8 +678,14 @@ static int vfc_probe(void)
if (strcmp(sdev->prom_name, "vfc") == 0) {
vfc_dev_lst[instance]=(struct vfc_dev *)
kmalloc(sizeof(struct vfc_dev), GFP_KERNEL);
- if (vfc_dev_lst[instance] == NULL)
+ if (vfc_dev_lst[instance] == NULL) {
+ int i;
+ for (i = 0; i < instance; i++) {
+ if (vfc_dev_lst[i]->regs)
+ sbus_iounmap(vfc_dev_lst[i]->regs, sizeof(struct vfc_regs));
+ }
return -ENOMEM;
+ }
ret = init_vfc_device(sdev,
vfc_dev_lst[instance],
instance);