2012-11-27 06:05:18

by Sachin Kamat

[permalink] [raw]
Subject: [PATCH 0/3] power: bq2415x_charger: Some cleanup

This series is build tested againt the linux-next tree (20121126)

Sachin Kamat (3):
power: bq2415x_charger: Remove unneeded version.h inclusion
power: bq2415x_charger: Use module_i2c_driver
power: bq2415x_charger: Use devm_kzalloc()

drivers/power/bq2415x_charger.c | 28 +++++++---------------------
1 files changed, 7 insertions(+), 21 deletions(-)

--
1.7.4.1


2012-11-27 06:05:23

by Sachin Kamat

[permalink] [raw]
Subject: [PATCH 1/3] power: bq2415x_charger: Remove unneeded version.h inclusion

<linux/version.h> is not required here.

Signed-off-by: Sachin Kamat <[email protected]>
---
drivers/power/bq2415x_charger.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index ee842b3..2d1b568 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -28,7 +28,6 @@
* http://www.ti.com/product/bq24155
*/

-#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/param.h>
--
1.7.4.1

2012-11-27 06:05:28

by Sachin Kamat

[permalink] [raw]
Subject: [PATCH 3/3] power: bq2415x_charger: Use devm_kzalloc()

devm_kzalloc is device managed and makes error handling
and code cleanup a bit simpler.

Signed-off-by: Sachin Kamat <[email protected]>
---
drivers/power/bq2415x_charger.c | 15 ++++++---------
1 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index 54c4ebf..f93359b 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -1522,7 +1522,7 @@ static int bq2415x_probe(struct i2c_client *client,
goto error_1;
}

- bq = kzalloc(sizeof(*bq), GFP_KERNEL);
+ bq = devm_kzalloc(&client->dev, sizeof(*bq), GFP_KERNEL);
if (!bq) {
dev_err(&client->dev, "failed to allocate device data\n");
ret = -ENOMEM;
@@ -1548,19 +1548,19 @@ static int bq2415x_probe(struct i2c_client *client,
ret = bq2415x_power_supply_init(bq);
if (ret) {
dev_err(bq->dev, "failed to register power supply: %d\n", ret);
- goto error_3;
+ goto error_2;
}

ret = bq2415x_sysfs_init(bq);
if (ret) {
dev_err(bq->dev, "failed to create sysfs entries: %d\n", ret);
- goto error_4;
+ goto error_3;
}

ret = bq2415x_set_defaults(bq);
if (ret) {
dev_err(bq->dev, "failed to set default values: %d\n", ret);
- goto error_5;
+ goto error_4;
}

if (bq->init_data.set_mode_hook) {
@@ -1584,12 +1584,10 @@ static int bq2415x_probe(struct i2c_client *client,
dev_info(bq->dev, "driver registered\n");
return 0;

-error_5:
- bq2415x_sysfs_exit(bq);
error_4:
- bq2415x_power_supply_exit(bq);
+ bq2415x_sysfs_exit(bq);
error_3:
- kfree(bq);
+ bq2415x_power_supply_exit(bq);
error_2:
kfree(name);
error_1:
@@ -1621,7 +1619,6 @@ static int bq2415x_remove(struct i2c_client *client)
dev_info(bq->dev, "driver unregistered\n");

kfree(bq->name);
- kfree(bq);

return 0;
}
--
1.7.4.1

2012-11-27 06:05:26

by Sachin Kamat

[permalink] [raw]
Subject: [PATCH 2/3] power: bq2415x_charger: Use module_i2c_driver

module_i2c_driver() makes the code simpler by eliminating
module_init and module_exit calls.

Signed-off-by: Sachin Kamat <[email protected]>
---
drivers/power/bq2415x_charger.c | 12 +-----------
1 files changed, 1 insertions(+), 11 deletions(-)

diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index 2d1b568..54c4ebf 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -1652,17 +1652,7 @@ static struct i2c_driver bq2415x_driver = {
.id_table = bq2415x_i2c_id_table,
};

-static int __init bq2415x_init(void)
-{
- return i2c_add_driver(&bq2415x_driver);
-}
-module_init(bq2415x_init);
-
-static void __exit bq2415x_exit(void)
-{
- i2c_del_driver(&bq2415x_driver);
-}
-module_exit(bq2415x_exit);
+module_i2c_driver(bq2415x_driver);

MODULE_AUTHOR("Pali Rohár <[email protected]>");
MODULE_DESCRIPTION("bq2415x charger driver");
--
1.7.4.1