From acd77ec58bc88096a6ab7f4cc8a50b4f35ce0651 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E9=BB=84=E6=B6=9B?= Date: Wed, 9 Nov 2011 09:44:26 +0800 Subject: [PATCH] input: gsensor: mma8452: initialize data early 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 [] (__mutex_lock_slowpath+0x4c/0x154) from [] (mma8452_get_data+0x1fc/0x238) [] (mma8452_get_data+0x1fc/0x238) from [] (mma8452_delaywork_func+0x10/0x30) [] (mma8452_delaywork_func+0x10/0x30) from [] (process_one_work+0x258/0x3ac) [] (process_one_work+0x258/0x3ac) from [] (worker_thread+0x238/0x440) [] (worker_thread+0x238/0x440) from [] (kthread+0x80/0x88) [] (kthread+0x80/0x88) from [] (kernel_thread_exit+0x0/0x8) --- drivers/input/gsensor/mma8452.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/input/gsensor/mma8452.c b/drivers/input/gsensor/mma8452.c index 079cc0f504ae..1b2247062026 100755 --- a/drivers/input/gsensor/mma8452.c +++ b/drivers/input/gsensor/mma8452.c @@ -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); -- 2.34.1