Skip to content

Commit e8d6505

Browse files
wtarreaugregkh
authored andcommitted
misc: panel: properly restore atomic counter on error path
commit 93dc1774d2a4c7a298d5cdf78cc8acdcb7b1428d 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 staging/panel in 4.4] Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 01000c5 commit e8d6505

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

drivers/staging/panel/panel.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,17 +1431,25 @@ static ssize_t lcd_write(struct file *file,
14311431

14321432
static int lcd_open(struct inode *inode, struct file *file)
14331433
{
1434+
int ret;
1435+
1436+
ret = -EBUSY;
14341437
if (!atomic_dec_and_test(&lcd_available))
1435-
return -EBUSY; /* open only once at a time */
1438+
goto fail; /* open only once at a time */
14361439

1440+
ret = -EPERM;
14371441
if (file->f_mode & FMODE_READ) /* device is write-only */
1438-
return -EPERM;
1442+
goto fail;
14391443

14401444
if (lcd.must_clear) {
14411445
lcd_clear_display();
14421446
lcd.must_clear = false;
14431447
}
14441448
return nonseekable_open(inode, file);
1449+
1450+
fail:
1451+
atomic_inc(&lcd_available);
1452+
return ret;
14451453
}
14461454

14471455
static int lcd_release(struct inode *inode, struct file *file)
@@ -1704,14 +1712,21 @@ static ssize_t keypad_read(struct file *file,
17041712

17051713
static int keypad_open(struct inode *inode, struct file *file)
17061714
{
1715+
int ret;
1716+
1717+
ret = -EBUSY;
17071718
if (!atomic_dec_and_test(&keypad_available))
1708-
return -EBUSY; /* open only once at a time */
1719+
goto fail; /* open only once at a time */
17091720

1721+
ret = -EPERM;
17101722
if (file->f_mode & FMODE_WRITE) /* device is read-only */
1711-
return -EPERM;
1723+
goto fail;
17121724

17131725
keypad_buflen = 0; /* flush the buffer on opening */
17141726
return 0;
1727+
fail:
1728+
atomic_inc(&keypad_available);
1729+
return ret;
17151730
}
17161731

17171732
static int keypad_release(struct inode *inode, struct file *file)

0 commit comments

Comments
 (0)