Skip to contentSkip to conversation

backlight: lp855x_bl: Checking platform data in lp855x_probe

PATCH New Axel Lin 1 participant 2 messages Feb 2, 2012

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/2 backlight: lp855x_bl: Checking platform data in lp855x_probe

The reset of the code assumes pdata is not NULL.
Add checking for pdata in lp855x_probe, this prevents NULL dereference if pdata is NULL.

---
 drivers/video/backlight/lp855x_bl.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
drivers/video/backlight/lp855x_bl.c +7 -1
index 8f628b8..5ab9ec8 100644
@@ -230,9 +230,14 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
 {
 	struct lp855x *lp;
 	struct lp855x_platform_data *pdata = cl->dev.platform_data;
-	enum lp855x_brightness_ctrl_mode mode = pdata->mode;
+	enum lp855x_brightness_ctrl_mode mode;
 	int ret;
 
+	if (!pdata) {
+		dev_err(&cl->dev, "no platform data supplied\n");
+		return -EINVAL;
+	}
+
 	if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
 		return -EIO;
 
@@ -240,6 +245,7 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
 	if (!lp)
 		return -ENOMEM;
 
+	mode = pdata->mode;
 	lp->client = cl;
 	lp->dev = &cl->dev;
 	lp->pdata = pdata;
Signature · 1 line
1.7.5.4
author
#1 lore raw

PATCH 2/2 backlight: lp855x_bl: Small cleanups

This patch includes below cleanups:
- Make lp855x_bl_update_status() return 0 instead of bl->props.brightness. It looks pointless to return bl->props.brightness for lp855x_bl_update_status. Make it return 0 on success.
- Use devm_kzalloc to save a few error handling code.
- Use module_i2c_driver

---
 drivers/video/backlight/lp855x_bl.c |   25 +++++--------------------
 1 files changed, 5 insertions(+), 20 deletions(-)
drivers/video/backlight/lp855x_bl.c +5 -20
index 5ab9ec8..c337b7a 100644
@@ -131,7 +131,7 @@ static int lp855x_bl_update_status(struct backlight_device *bl)
 		lp855x_write_byte(lp, BRIGHTNESS_CTRL, val);
 	}
 
-	return bl->props.brightness;
+	return 0;
 }
 
 static int lp855x_bl_get_brightness(struct backlight_device *bl)
@@ -241,7 +241,7 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
 	if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
 		return -EIO;
 
-	lp = kzalloc(sizeof(struct lp855x), GFP_KERNEL);
+	lp = devm_kzalloc(&cl->dev, sizeof(struct lp855x), GFP_KERNEL);
 	if (!lp)
 		return -ENOMEM;
 
@@ -275,14 +275,11 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
 	}
 
 	backlight_update_status(lp->bl);
-	return ret;
+	return 0;
 
-err_dev:
-	kfree(lp);
-	return ret;
 err_sysfs:
 	lp855x_backlight_unregister(lp);
-	kfree(lp);
+err_dev:
 	return ret;
 }
 
@@ -294,7 +291,6 @@ static int __devexit lp855x_remove(struct i2c_client *cl)
 	backlight_update_status(lp->bl);
 	sysfs_remove_group(&lp->dev->kobj, &lp855x_attr_group);
 	lp855x_backlight_unregister(lp);
-	kfree(lp);
 
 	return 0;
 }
@@ -318,18 +314,7 @@ static struct i2c_driver lp855x_driver = {
 	.id_table = lp855x_ids,
 };
 
-static int __init lp855x_init(void)
-{
-	return i2c_add_driver(&lp855x_driver);
-}
-
-static void __exit lp855x_exit(void)
-{
-	i2c_del_driver(&lp855x_driver);
-}
-
-module_init(lp855x_init);
-module_exit(lp855x_exit);
+module_i2c_driver(lp855x_driver);
 
 MODULE_DESCRIPTION("Texas Instruments LP855x Backlight driver");
 MODULE_AUTHOR("Milo Kim <[email protected]>");
Signature · 1 line
1.7.5.4