diff options
author | Steve Pfetsch <spfetsch@google.com> | 2019-06-25 13:42:53 -0700 |
---|---|---|
committer | Steve Pfetsch <spfetsch@google.com> | 2019-06-26 22:47:51 +0000 |
commit | 8f6a4e9f5649deff59174ffed1d5c2af196d9f63 (patch) | |
tree | 3b0a7255c3851f196d8762c601feed131b6a0e32 /fts_proc.c | |
parent | f84119eba35fef4f71b3bc7fcc4ad20ce3b90992 (diff) | |
download | fts_touch_s5-8f6a4e9f5649deff59174ffed1d5c2af196d9f63.tar.gz |
input: touchscreen: fts: procfs read/write do not acquire lock
The mutex behavior made it possible for the one client with access to
the procfs node (/proc/fts/driver_test) to fail read/write/lseek/release
if another client is attempting to open the node. Even worse, if the
client cannot acquire the lock during release, it will fail to clean-up
its ownership of the node and the node will become inaccessible.
Instead, rely on the initial lock in fts_driver_test_open to guarantee
there will only be one client using the other entry points and therefore
they do not need locking.
Bug: 136024296
Change-Id: I63a2c2addf54a9570a5677e64b0002d40e623d40
Signed-off-by: Steve Pfetsch <spfetsch@google.com>
Diffstat (limited to 'fts_proc.c')
-rw-r--r-- | fts_proc.c | 96 |
1 files changed, 8 insertions, 88 deletions
@@ -729,90 +729,18 @@ static int fts_driver_test_release(struct inode *inode, struct file *file) struct fts_ts_info *info = dev_get_drvdata(getDev()); int retval; - if (!info) { + if (info) + mutex_lock(&info->diag_cmd_lock); + else pr_err("%s: Unable to access driver data\n", __func__); - retval = -ENODEV; - goto exit; - } - - if (!mutex_trylock(&info->diag_cmd_lock)) { - pr_err("%s: Blocking concurrent access\n", __func__); - retval = -EBUSY; - goto exit; - } retval = seq_release(inode, file); - info->diag_node_open = false; - - mutex_unlock(&info->diag_cmd_lock); -exit: - return retval; -} - - -/** - * This function reads a sequential file - * @param file file associated to the file node - * @param buf userspace buffer where the newly read data should be placed - * @param count size of the requested transfer. - * @param pos start position from which data should be written in the file. - * @return error code, 0 if success - */ -static ssize_t fts_driver_test_read(struct file *file, char __user *buf, - size_t count, loff_t *pos) -{ - struct fts_ts_info *info = dev_get_drvdata(getDev()); - ssize_t bytes_read = -EINVAL; - - if (!info) { - pr_err("%s: Unable to access driver data\n", __func__); - bytes_read = -ENODEV; - goto exit; - } - - if (!mutex_trylock(&info->diag_cmd_lock)) { - pr_err("%s: Blocking concurrent access\n", __func__); - bytes_read = -EBUSY; - goto exit; - } - bytes_read = seq_read(file, buf, count, pos); - - mutex_unlock(&info->diag_cmd_lock); -exit: - return bytes_read; -} - -/** - * This function moves the cursor position within a file. - * @param file file associated to the file node - * @param offset offset relative to the current file position. - * @param whence defines where to seek from. - * @return error code, 0 if success - */ -static loff_t fts_driver_test_lseek(struct file *file, loff_t offset, - int whence) -{ - struct fts_ts_info *info = dev_get_drvdata(getDev()); - loff_t retval; - - if (!info) { - pr_err("%s: Unable to access driver data\n", __func__); - retval = -ENODEV; - goto exit; - } - - if (!mutex_trylock(&info->diag_cmd_lock)) { - pr_err("%s: Blocking concurrent access\n", __func__); - retval = -EBUSY; - goto exit; + if (info) { + info->diag_node_open = false; + mutex_unlock(&info->diag_cmd_lock); } - retval = seq_lseek(file, offset, whence); - - mutex_unlock(&info->diag_cmd_lock); - -exit: return retval; } @@ -883,12 +811,6 @@ static ssize_t fts_driver_test_write(struct file *file, const char __user *buf, goto exit; } - if (!mutex_trylock(&info->diag_cmd_lock)) { - pr_err("%s: Blocking concurrent access\n", __func__); - count = -EBUSY; - goto exit; - } - mess.dummy = 0; mess.action = 0; mess.msg_size = 0; @@ -3726,8 +3648,6 @@ ERROR: fts_set_bus_ref(info, FTS_BUS_REF_SYSFS, false); - mutex_unlock(&info->diag_cmd_lock); - exit: return count; } @@ -3740,9 +3660,9 @@ exit: */ static struct file_operations fts_driver_test_ops = { .open = fts_driver_test_open, - .read = fts_driver_test_read, + .read = seq_read, .write = fts_driver_test_write, - .llseek = fts_driver_test_lseek, + .llseek = seq_lseek, .release = fts_driver_test_release }; |