input: gsensor: mma8452: initialize data early
author黄涛 <huangtao@rock-chips.com>
Wed, 9 Nov 2011 01:44:26 +0000 (09:44 +0800)
committer黄涛 <huangtao@rock-chips.com>
Wed, 9 Nov 2011 01:44:26 +0000 (09:44 +0800)
fix this bug:
Unable to handle kernel NULL pointer dereference at virtual address 00000000
PC is at __mutex_lock_slowpath+0x4c/0x154
LR is at mma8452_get_data+0x1fc/0x238
[<c07e4f2c>] (__mutex_lock_slowpath+0x4c/0x154) from [<c066d9c4>] (mma8452_get_data+0x1fc/0x238)
[<c066d9c4>] (mma8452_get_data+0x1fc/0x238) from [<c066da10>] (mma8452_delaywork_func+0x10/0x30)
[<c066da10>] (mma8452_delaywork_func+0x10/0x30) from [<c0466600>] (process_one_work+0x258/0x3ac)
[<c0466600>] (process_one_work+0x258/0x3ac) from [<c0468f60>] (worker_thread+0x238/0x440)
[<c0468f60>] (worker_thread+0x238/0x440) from [<c046c9ac>] (kthread+0x80/0x88)
[<c046c9ac>] (kthread+0x80/0x88) from [<c0433190>] (kernel_thread_exit+0x0/0x8)

drivers/input/gsensor/mma8452.c

index 079cc0f504ae9f8432ffdbfa3c6d1ed6c401f794..1b2247062026df98d7353f31cf6e51f80bf5324d 100755 (executable)
@@ -724,6 +724,17 @@ static int  mma8452_probe(struct i2c_client *client, const struct i2c_device_id
        INIT_WORK(&mma8452->work, mma8452_work_func);
        INIT_DELAYED_WORK(&mma8452->delaywork, mma8452_delaywork_func);
 
+       memset(&(mma8452->sense_data), 0, sizeof(struct mma8452_axis) );
+       mutex_init(&(mma8452->sense_data_mutex) );
+
+       atomic_set(&(mma8452->data_ready), 0);
+       init_waitqueue_head(&(mma8452->data_ready_wq) );
+
+       mma8452->start_count = 0;
+       mutex_init(&(mma8452->operation_mutex) );
+
+       mma8452->status = MMA8452_CLOSE;
+
        mma8452->client = client;
        i2c_set_clientdata(client, mma8452);
 
@@ -794,17 +805,6 @@ static int  mma8452_probe(struct i2c_client *client, const struct i2c_device_id
 #endif
 
        printk(KERN_INFO "mma8452 probe ok\n");
-    memset(&(mma8452->sense_data), 0, sizeof(struct mma8452_axis) );
-    mutex_init(&(mma8452->sense_data_mutex) );
-    
-       atomic_set(&(mma8452->data_ready), 0);
-    init_waitqueue_head(&(mma8452->data_ready_wq) );
-
-    mma8452->start_count = 0;
-    mutex_init(&(mma8452->operation_mutex) );
-    
-       // mma8452->status = -1;
-       mma8452->status = MMA8452_CLOSE;
 #if  0 
 //     mma8452_start_test(this_client);
        mma8452_start(client, MMA8452_RATE_12P5);