summaryrefslogtreecommitdiffstats
path: root/drivers/w1
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2012-02-15 18:21:42 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-02-15 17:17:50 -0800
commit9f3519d2ed26d2ede5b6432fb64af0e7e8ed13e3 (patch)
tree21c794c3dcc559208a1d161382e39b5b07e41564 /drivers/w1
parentbc5bca53cca350eb90fc9f84c2e37ba6383807c3 (diff)
w1: Fix w1_bq27000
w1_bq27000 adds a bq27000-battery platform device but does not provide platform data for it. This causes the bq27x00 driver to dereference a NULL pointer. So provide the appropriate platform data. This requires modifying w1_bq27000_read so that it find the w1 device as the parent of the bq device. Also there is no point exporting w1_bq27000_read as nothing else uses it or could use it. So make it static. Finally, as there is no way to track how many batteries have been found, and we will probably only find one, use an id number of '-1' to assert that this is a unique instance. Signed-off-by: NeilBrown <neilb@suse.de> Tested-by: Thomas Weber <weber@corscience.de> Acked-by: Evgeniy Polyakov <zbr@ioremap.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/w1')
-rw-r--r--drivers/w1/slaves/w1_bq27000.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/drivers/w1/slaves/w1_bq27000.c b/drivers/w1/slaves/w1_bq27000.c
index 8f4c91f6c68..8f10fd2630a 100644
--- a/drivers/w1/slaves/w1_bq27000.c
+++ b/drivers/w1/slaves/w1_bq27000.c
@@ -15,6 +15,7 @@
#include <linux/types.h>
#include <linux/platform_device.h>
#include <linux/mutex.h>
+#include <linux/power/bq27x00_battery.h>
#include "../w1.h"
#include "../w1_int.h"
@@ -39,10 +40,10 @@ void w1_bq27000_write(struct device *dev, u8 buf, u8 reg)
}
EXPORT_SYMBOL(w1_bq27000_write);
-int w1_bq27000_read(struct device *dev, u8 reg)
+static int w1_bq27000_read(struct device *dev, unsigned int reg)
{
u8 val;
- struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
+ struct w1_slave *sl = container_of(dev->parent, struct w1_slave, dev);
if (!dev)
return 0;
@@ -52,19 +53,25 @@ int w1_bq27000_read(struct device *dev, u8 reg)
return val;
}
-EXPORT_SYMBOL(w1_bq27000_read);
+
+static struct bq27000_platform_data bq27000_battery_info = {
+ .read = w1_bq27000_read,
+ .name = "bq27000-battery",
+};
static int w1_bq27000_add_slave(struct w1_slave *sl)
{
int ret;
- int id = 1;
struct platform_device *pdev;
- pdev = platform_device_alloc("bq27000-battery", id);
+ pdev = platform_device_alloc("bq27000-battery", -1);
if (!pdev) {
ret = -ENOMEM;
return ret;
}
+ ret = platform_device_add_data(pdev,
+ &bq27000_battery_info,
+ sizeof(bq27000_battery_info));
pdev->dev.parent = &sl->dev;
ret = platform_device_add(pdev);