aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/input/input.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c
index e2dd8858e19d..e2aad0a51826 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -1879,35 +1879,37 @@ static int input_open_file(struct inode *inode, struct file *file)
1879 const struct file_operations *old_fops, *new_fops = NULL; 1879 const struct file_operations *old_fops, *new_fops = NULL;
1880 int err; 1880 int err;
1881 1881
1882 lock_kernel(); 1882 err = mutex_lock_interruptible(&input_mutex);
1883 if (err)
1884 return err;
1885
1883 /* No load-on-demand here? */ 1886 /* No load-on-demand here? */
1884 handler = input_table[iminor(inode) >> 5]; 1887 handler = input_table[iminor(inode) >> 5];
1885 if (!handler || !(new_fops = fops_get(handler->fops))) { 1888 if (handler)
1886 err = -ENODEV; 1889 new_fops = fops_get(handler->fops);
1887 goto out; 1890
1888 } 1891 mutex_unlock(&input_mutex);
1889 1892
1890 /* 1893 /*
1891 * That's _really_ odd. Usually NULL ->open means "nothing special", 1894 * That's _really_ odd. Usually NULL ->open means "nothing special",
1892 * not "no device". Oh, well... 1895 * not "no device". Oh, well...
1893 */ 1896 */
1894 if (!new_fops->open) { 1897 if (!new_fops || !new_fops->open) {
1895 fops_put(new_fops); 1898 fops_put(new_fops);
1896 err = -ENODEV; 1899 err = -ENODEV;
1897 goto out; 1900 goto out;
1898 } 1901 }
1902
1899 old_fops = file->f_op; 1903 old_fops = file->f_op;
1900 file->f_op = new_fops; 1904 file->f_op = new_fops;
1901 1905
1902 err = new_fops->open(inode, file); 1906 err = new_fops->open(inode, file);
1903
1904 if (err) { 1907 if (err) {
1905 fops_put(file->f_op); 1908 fops_put(file->f_op);
1906 file->f_op = fops_get(old_fops); 1909 file->f_op = fops_get(old_fops);
1907 } 1910 }
1908 fops_put(old_fops); 1911 fops_put(old_fops);
1909out: 1912out:
1910 unlock_kernel();
1911 return err; 1913 return err;
1912} 1914}
1913 1915