Skip to content

Commit 9ba33f6

Browse files
committed
Input: zforce_ts - ensure that pm_stay_awake() and pm_relax() are balanced
There is a small chance that ts->suspending flag may change while the interrupt handler is running. To make sure call to pm_relax() is not skipped on accident use a temporary to hold the original value at the beginning of interrupt. Use READ_ONCE() so that the value is actually fetched at the right time. Tested-by: Andreas Kemnade <[email protected]> # Tolino Shine2HD Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent f388412 commit 9ba33f6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

drivers/input/touchscreen/zforce_ts.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ static irqreturn_t zforce_irq_thread(int irq, void *dev_id)
454454
int ret;
455455
u8 payload_buffer[FRAME_MAXSIZE];
456456
u8 *payload;
457+
bool suspending;
457458

458459
/*
459460
* When still suspended, return.
@@ -467,7 +468,8 @@ static irqreturn_t zforce_irq_thread(int irq, void *dev_id)
467468
dev_dbg(&client->dev, "handling interrupt\n");
468469

469470
/* Don't emit wakeup events from commands run by zforce_suspend */
470-
if (!ts->suspending && device_may_wakeup(&client->dev))
471+
suspending = READ_ONCE(ts->suspending);
472+
if (!suspending && device_may_wakeup(&client->dev))
471473
pm_stay_awake(&client->dev);
472474

473475
/*
@@ -495,7 +497,7 @@ static irqreturn_t zforce_irq_thread(int irq, void *dev_id)
495497
* Always report touch-events received while
496498
* suspending, when being a wakeup source
497499
*/
498-
if (ts->suspending && device_may_wakeup(&client->dev))
500+
if (suspending && device_may_wakeup(&client->dev))
499501
pm_wakeup_event(&client->dev, 500);
500502
zforce_touch_event(ts, &payload[RESPONSE_DATA]);
501503
break;
@@ -548,7 +550,7 @@ static irqreturn_t zforce_irq_thread(int irq, void *dev_id)
548550
}
549551
} while (gpiod_get_value_cansleep(ts->gpio_int));
550552

551-
if (!ts->suspending && device_may_wakeup(&client->dev))
553+
if (!suspending && device_may_wakeup(&client->dev))
552554
pm_relax(&client->dev);
553555

554556
dev_dbg(&client->dev, "finished interrupt\n");
@@ -584,7 +586,9 @@ static int zforce_suspend(struct device *dev)
584586
int ret = 0;
585587

586588
mutex_lock(&input->mutex);
587-
ts->suspending = true;
589+
590+
WRITE_ONCE(ts->suspending, true);
591+
smp_mb();
588592

589593
/*
590594
* When configured as a wakeup source device should always wake
@@ -615,7 +619,9 @@ static int zforce_suspend(struct device *dev)
615619
ts->suspended = true;
616620

617621
unlock:
618-
ts->suspending = false;
622+
smp_mb();
623+
WRITE_ONCE(ts->suspending, false);
624+
619625
mutex_unlock(&input->mutex);
620626

621627
return ret;

0 commit comments

Comments
 (0)