input: sensor-dev: fix smatch warning
authorHuang, Tao <huangtao@rock-chips.com>
Mon, 31 Oct 2016 07:58:33 +0000 (15:58 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Fri, 11 Nov 2016 08:20:46 +0000 (16:20 +0800)
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 <huangtao@rock-chips.com>
(cherry picked from commit 08fd14ea02692f43eaa8a166791cdaaa4b6c0738)

drivers/input/sensors/sensor-dev.c

index 01bbf40..0527631 100755 (executable)
@@ -1052,6 +1052,7 @@ static long gyro_dev_ioctl(struct file *file,
                result = sensor->status_cur;\r
                if (copy_to_user(argp, &result, sizeof(result)))\r
                {\r
+                       mutex_unlock(&sensor->operation_mutex);\r
                        printk("%s:failed to copy sense data to user space.\n",__FUNCTION__);\r
                        return -EFAULT;\r
                }\r
@@ -1060,9 +1061,9 @@ static long gyro_dev_ioctl(struct file *file,
                DBG("%s:L3G4200D_IOCTL_SET_ENABLE OK\n", __func__);\r
                break;\r
        case L3G4200D_IOCTL_SET_DELAY:                                  \r
-               mutex_lock(&sensor->operation_mutex);\r
                if (copy_from_user(&rate, argp, sizeof(rate)))\r
                return -EFAULT;\r
+               mutex_lock(&sensor->operation_mutex);\r
                if(sensor->status_cur == SENSOR_OFF)\r
                {\r
                        if ( (result = sensor->ops->active(client, 1, rate) ) < 0 ) {\r
@@ -2041,11 +2042,11 @@ int sensor_probe(struct i2c_client *client, const struct i2c_device_id *devid)
        if(result < 0)\r
                goto out_free_memory;\r
        \r
-       sensor->input_dev = input_allocate_device();\r
+       sensor->input_dev = devm_input_allocate_device(&client->dev);\r
        if (!sensor->input_dev) {\r
                result = -ENOMEM;\r
                dev_err(&client->dev,\r
-                       "Failed to allocate input device %s\n", sensor->input_dev->name);\r
+                       "Failed to allocate input device\n");\r
                goto out_free_memory;\r
        }       \r
 \r
@@ -2189,11 +2190,8 @@ int sensor_probe(struct i2c_client *client, const struct i2c_device_id *devid)
        return result;\r
        \r
 out_misc_device_register_device_failed:\r
-       input_unregister_device(sensor->input_dev);     \r
 out_input_register_device_failed:\r
-       input_free_device(sensor->input_dev);   \r
 out_free_memory:\r
-       //kfree(sensor);\r
 out_no_free:\r
        dev_err(&client->adapter->dev, "%s failed %d\n\n", __func__, result);\r
        return result;\r
@@ -2219,9 +2217,6 @@ static int sensor_remove(struct i2c_client *client)
        \r
        cancel_delayed_work_sync(&sensor->delaywork);\r
        misc_deregister(&sensor->miscdev);\r
-       input_unregister_device(sensor->input_dev);     \r
-       input_free_device(sensor->input_dev);   \r
-       kfree(sensor);\r
 #ifdef CONFIG_HAS_EARLYSUSPEND\r
        if((sensor->ops->suspend) && (sensor->ops->resume))\r
                unregister_early_suspend(&sensor->early_suspend);\r