From: Huang, Tao Date: Mon, 31 Oct 2016 07:58:33 +0000 (+0800) Subject: input: sensor-dev: fix smatch warning X-Git-Tag: firefly_0821_release~1282 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=firefly-linux-kernel-4.4.55.git;a=commitdiff_plain;h=b47b139d89065b8e669bd011a2f288286bd87917 input: sensor-dev: fix smatch warning fix below warnings: sensor-dev.c:1016 gyro_dev_ioctl() warn: inconsistent returns 'mutex:&sensor->operation_mutex'. Locked on: line 973 line 982 Unlocked on: line 919 line 1010 line 1016 sensor-dev.c:1905 sensor_probe() error: potential null dereference 'sensor->input_dev'. (input_allocate_device returns null) sensor-dev.c:1905 sensor_probe() error: we previously assumed 'sensor->input_dev' could be null (see line 1902) sensor-dev.c:2051 sensor_probe() error: don't call input_free_device() after input_unregister_device() sensor-dev.c:2080 sensor_remove() error: don't call input_free_device() after input_unregister_device() Change-Id: I7da8a337282df7f9b8e6474a68928fc53d4e6890 Signed-off-by: Huang, Tao (cherry picked from commit 08fd14ea02692f43eaa8a166791cdaaa4b6c0738) --- diff --git a/drivers/input/sensors/sensor-dev.c b/drivers/input/sensors/sensor-dev.c index 01bbf40ce2b8..052763173097 100755 --- a/drivers/input/sensors/sensor-dev.c +++ b/drivers/input/sensors/sensor-dev.c @@ -1052,6 +1052,7 @@ static long gyro_dev_ioctl(struct file *file, result = sensor->status_cur; if (copy_to_user(argp, &result, sizeof(result))) { + mutex_unlock(&sensor->operation_mutex); printk("%s:failed to copy sense data to user space.\n",__FUNCTION__); return -EFAULT; } @@ -1060,9 +1061,9 @@ static long gyro_dev_ioctl(struct file *file, DBG("%s:L3G4200D_IOCTL_SET_ENABLE OK\n", __func__); break; case L3G4200D_IOCTL_SET_DELAY: - mutex_lock(&sensor->operation_mutex); if (copy_from_user(&rate, argp, sizeof(rate))) return -EFAULT; + mutex_lock(&sensor->operation_mutex); if(sensor->status_cur == SENSOR_OFF) { if ( (result = sensor->ops->active(client, 1, rate) ) < 0 ) { @@ -2041,11 +2042,11 @@ int sensor_probe(struct i2c_client *client, const struct i2c_device_id *devid) if(result < 0) goto out_free_memory; - sensor->input_dev = input_allocate_device(); + sensor->input_dev = devm_input_allocate_device(&client->dev); if (!sensor->input_dev) { result = -ENOMEM; dev_err(&client->dev, - "Failed to allocate input device %s\n", sensor->input_dev->name); + "Failed to allocate input device\n"); goto out_free_memory; } @@ -2189,11 +2190,8 @@ int sensor_probe(struct i2c_client *client, const struct i2c_device_id *devid) return result; out_misc_device_register_device_failed: - input_unregister_device(sensor->input_dev); out_input_register_device_failed: - input_free_device(sensor->input_dev); out_free_memory: - //kfree(sensor); out_no_free: dev_err(&client->adapter->dev, "%s failed %d\n\n", __func__, result); return result; @@ -2219,9 +2217,6 @@ static int sensor_remove(struct i2c_client *client) cancel_delayed_work_sync(&sensor->delaywork); misc_deregister(&sensor->miscdev); - input_unregister_device(sensor->input_dev); - input_free_device(sensor->input_dev); - kfree(sensor); #ifdef CONFIG_HAS_EARLYSUSPEND if((sensor->ops->suspend) && (sensor->ops->resume)) unregister_early_suspend(&sensor->early_suspend);