From 9aa47e216ead9c25ba31fd014be390193c693ab7 Mon Sep 17 00:00:00 2001 From: luowei Date: Mon, 11 Mar 2013 19:25:31 +0800 Subject: [PATCH] sensors:fix NULL pointer problem of compass --- drivers/input/sensors/compass/ak8963.c | 17 +++++++++-------- drivers/input/sensors/compass/ak8975.c | 15 ++++++++------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/input/sensors/compass/ak8963.c b/drivers/input/sensors/compass/ak8963.c index bf3af24812e6..3979d66716cf 100755 --- a/drivers/input/sensors/compass/ak8963.c +++ b/drivers/input/sensors/compass/ak8963.c @@ -127,6 +127,7 @@ Defines a read-only address of the fuse ROM of the AK8963.*/ #define AK8963_DEVICE_ID 0x48 static struct i2c_client *this_client; +static struct miscdevice compass_dev_device; static short g_akm_rbuf[12]; @@ -182,9 +183,15 @@ static int sensor_init(struct i2c_client *client) if((info & (0x0f<<3)) != AK8963_INFO_DATA) { printk("%s:info=0x%x,it is not %s\n",__func__, info, sensor->ops->name); - result = -1; + return -1; } + result = misc_register(&compass_dev_device); + if (result < 0) { + printk("%s:fail to register misc device %s\n", __func__, compass_dev_device.name); + result = -1; + } + DBG("%s:status_cur=%d\n",__func__, sensor->status_cur); return result; } @@ -765,13 +772,7 @@ static int __init compass_akm8963_init(void) int result = 0; int type = ops->type; result = sensor_register_slave(type, NULL, NULL, compass_get_ops); - - result = misc_register(&compass_dev_device); - if (result < 0) { - printk("%s:fail to register misc device %s\n", __func__, compass_dev_device.name); - goto error; - } -error: + return result; } diff --git a/drivers/input/sensors/compass/ak8975.c b/drivers/input/sensors/compass/ak8975.c index cecf15fb5f5a..dec87a8e7b7d 100755 --- a/drivers/input/sensors/compass/ak8975.c +++ b/drivers/input/sensors/compass/ak8975.c @@ -112,6 +112,7 @@ Defines a read-only address of the fuse ROM of the AK8975.*/ #define AK8975_DEVICE_ID 0x48 static struct i2c_client *this_client; +static struct miscdevice compass_dev_device; @@ -168,6 +169,12 @@ static int sensor_init(struct i2c_client *client) { printk("%s:info=0x%x,it is not %s\n",__func__, info, sensor->ops->name); + return -1; + } + + result = misc_register(&compass_dev_device); + if (result < 0) { + printk("%s:fail to register misc device %s\n", __func__, compass_dev_device.name); result = -1; } @@ -647,13 +654,7 @@ static int __init compass_akm8975_init(void) int result = 0; int type = ops->type; result = sensor_register_slave(type, NULL, NULL, compass_get_ops); - - result = misc_register(&compass_dev_device); - if (result < 0) { - printk("%s:fail to register misc device %s\n", __func__, compass_dev_device.name); - goto error; - } -error: + return result; } -- 2.34.1