[PATCH] regulator: max1586 - fix a memory leak inmax1586_pmic_remove()

From: Axel Lin
Date: Fri Aug 06 2010 - 01:31:58 EST


In max1586_pmic_probe(), we allocate memory for max1586.
In max1586_pmic_remove(), current implementation only free rdev
which is a member of struct max1586_data.
Thus, there is a small memory leak when we unload the module.

This patch fixes the memory leak by passing max1586 to i2c clientdata,
and properly kfree(max1586) in max1586_pmic_remove().

Signed-off-by: Axel Lin <axel.lin@xxxxxxxxx>
---
drivers/regulator/max1586.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index 2b54d9d..8867c27 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -223,7 +223,7 @@ static int __devinit max1586_pmic_probe(struct i2c_client *client,
}
}

- i2c_set_clientdata(client, rdev);
+ i2c_set_clientdata(client, max1586);
dev_info(&client->dev, "Maxim 1586 regulator driver loaded\n");
return 0;

@@ -238,13 +238,13 @@ out:

static int __devexit max1586_pmic_remove(struct i2c_client *client)
{
- struct regulator_dev **rdev = i2c_get_clientdata(client);
+ struct max1586_data *max1586 = i2c_get_clientdata(client);
int i;

for (i = 0; i <= MAX1586_V6; i++)
- if (rdev[i])
- regulator_unregister(rdev[i]);
- kfree(rdev);
+ if (max1586->rdev[i])
+ regulator_unregister(max1586->rdev[i]);
+ kfree(max1586);

return 0;
}
--
1.5.4.3



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/