Skip to content

Commit

Permalink
misc: panel: properly restore atomic counter on error path
Browse files Browse the repository at this point in the history
commit 93dc177 upstream.

Commit f4757af ("staging: panel: Fix single-open policy race condition")
introduced in 3.19-rc1 attempted to fix a race condition on the open, but
failed to properly do it and used to exit without restoring the semaphore.

This results in -EBUSY being returned after the first open error until
the module is reloaded or the system restarted (ie: consecutive to a
dual open resulting in -EBUSY or to a permission error).

Fixes: f4757af # 3.19-rc1
Cc: Mariusz Gorski <marius.gorski@gmail.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
[wt: driver is in misc/panel in 4.9]
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Willy Tarreau authored and Greg Kroah-Hartman committed Nov 18, 2017
1 parent b2dbcb7 commit e81b96c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions drivers/misc/panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1423,17 +1423,25 @@ static ssize_t lcd_write(struct file *file,

static int lcd_open(struct inode *inode, struct file *file)
{
int ret;

ret = -EBUSY;
if (!atomic_dec_and_test(&lcd_available))
return -EBUSY; /* open only once at a time */
goto fail; /* open only once at a time */

ret = -EPERM;
if (file->f_mode & FMODE_READ) /* device is write-only */
return -EPERM;
goto fail;

if (lcd.must_clear) {
lcd_clear_display();
lcd.must_clear = false;
}
return nonseekable_open(inode, file);

fail:
atomic_inc(&lcd_available);
return ret;
}

static int lcd_release(struct inode *inode, struct file *file)
Expand Down Expand Up @@ -1696,14 +1704,21 @@ static ssize_t keypad_read(struct file *file,

static int keypad_open(struct inode *inode, struct file *file)
{
int ret;

ret = -EBUSY;
if (!atomic_dec_and_test(&keypad_available))
return -EBUSY; /* open only once at a time */
goto fail; /* open only once at a time */

ret = -EPERM;
if (file->f_mode & FMODE_WRITE) /* device is read-only */
return -EPERM;
goto fail;

keypad_buflen = 0; /* flush the buffer on opening */
return 0;
fail:
atomic_inc(&keypad_available);
return ret;
}

static int keypad_release(struct inode *inode, struct file *file)
Expand Down

0 comments on commit e81b96c

Please sign in to comment.