sensors:fix NULL pointer problem of compass
authorluowei <lw@rock-chips.com>
Mon, 11 Mar 2013 11:25:31 +0000 (19:25 +0800)
committerluowei <lw@rock-chips.com>
Mon, 11 Mar 2013 11:26:27 +0000 (19:26 +0800)
drivers/input/sensors/compass/ak8963.c
drivers/input/sensors/compass/ak8975.c

index bf3af24812e6d1f98b693ad096847071245d29a2..3979d66716cf366135aefdca187a3fb101366ea7 100755 (executable)
@@ -127,6 +127,7 @@ Defines a read-only address of the fuse ROM of the AK8963.*/
 \r
 #define AK8963_DEVICE_ID               0x48\r
 static struct i2c_client *this_client;\r
+static struct miscdevice compass_dev_device;\r
 \r
 static short g_akm_rbuf[12];\r
 \r
@@ -182,9 +183,15 @@ static int sensor_init(struct i2c_client *client)
        if((info & (0x0f<<3)) != AK8963_INFO_DATA)\r
        {\r
                printk("%s:info=0x%x,it is not %s\n",__func__, info, sensor->ops->name);\r
-               result = -1;\r
+               return -1;\r
        }\r
 \r
+       result = misc_register(&compass_dev_device);\r
+       if (result < 0) {\r
+               printk("%s:fail to register misc device %s\n", __func__, compass_dev_device.name);\r
+               result = -1;\r
+       }\r
+       \r
        DBG("%s:status_cur=%d\n",__func__, sensor->status_cur);\r
        return result;\r
 }\r
@@ -765,13 +772,7 @@ static int __init compass_akm8963_init(void)
        int result = 0;\r
        int type = ops->type;\r
        result = sensor_register_slave(type, NULL, NULL, compass_get_ops);\r
-\r
-       result = misc_register(&compass_dev_device);\r
-       if (result < 0) {\r
-               printk("%s:fail to register misc device %s\n", __func__, compass_dev_device.name);\r
-               goto error;\r
-       }\r
-error:                         \r
+                               \r
        return result;\r
 }\r
 \r
index cecf15fb5f5a390067fabeb413cd2ae51507c92e..dec87a8e7b7d6470a8f92c011cd3c54758e6b36f 100755 (executable)
@@ -112,6 +112,7 @@ Defines a read-only address of the fuse ROM of the AK8975.*/
 \r
 #define AK8975_DEVICE_ID               0x48\r
 static struct i2c_client *this_client;\r
+static struct miscdevice compass_dev_device;\r
 \r
 \r
 \r
@@ -168,6 +169,12 @@ static int sensor_init(struct i2c_client *client)
        \r
        {\r
                printk("%s:info=0x%x,it is not %s\n",__func__, info, sensor->ops->name);\r
+               return -1;\r
+       }\r
+\r
+       result = misc_register(&compass_dev_device);\r
+       if (result < 0) {\r
+               printk("%s:fail to register misc device %s\n", __func__, compass_dev_device.name);\r
                result = -1;\r
        }\r
        \r
@@ -647,13 +654,7 @@ static int __init compass_akm8975_init(void)
        int result = 0;\r
        int type = ops->type;\r
        result = sensor_register_slave(type, NULL, NULL, compass_get_ops);\r
-\r
-       result = misc_register(&compass_dev_device);\r
-       if (result < 0) {\r
-               printk("%s:fail to register misc device %s\n", __func__, compass_dev_device.name);\r
-               goto error;\r
-       }\r
-error:                         \r
+                               \r
        return result;\r
 }\r
 \r