Skip to content

Commit 6cc523c

Browse files
fancergregkh
authored andcommitted
hwmon: (bt1-pvt) Wait for the completion with timeout
[ Upstream commit 0ffd21d ] If the PVT sensor is suddenly powered down while a caller is waiting for the conversion completion, the request won't be finished and the task will hang up on this procedure until the power is back up again. Let's call the wait_for_completion_timeout() method instead to prevent that. The cached timeout is exactly what we need to predict for how long conversion could normally last. Fixes: 87976ce ("hwmon: Add Baikal-T1 PVT sensor driver") Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru> Link: https://lore.kernel.org/r/20200920110924.19741-4-Sergey.Semin@baikalelectronics.ru Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 82f27fd commit 6cc523c

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎drivers/hwmon/bt1-pvt.c‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ static int pvt_read_data(struct pvt_hwmon *pvt, enum pvt_sensor_type type,
477477
long *val)
478478
{
479479
struct pvt_cache *cache = &pvt->cache[type];
480+
unsigned long timeout;
480481
u32 data;
481482
int ret;
482483

@@ -500,7 +501,14 @@ static int pvt_read_data(struct pvt_hwmon *pvt, enum pvt_sensor_type type,
500501
pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, 0);
501502
pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, PVT_CTRL_EN);
502503

503-
wait_for_completion(&cache->conversion);
504+
/*
505+
* Wait with timeout since in case if the sensor is suddenly powered
506+
* down the request won't be completed and the caller will hang up on
507+
* this procedure until the power is back up again. Multiply the
508+
* timeout by the factor of two to prevent a false timeout.
509+
*/
510+
timeout = 2 * usecs_to_jiffies(ktime_to_us(pvt->timeout));
511+
ret = wait_for_completion_timeout(&cache->conversion, timeout);
504512

505513
pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0);
506514
pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID,
@@ -510,6 +518,9 @@ static int pvt_read_data(struct pvt_hwmon *pvt, enum pvt_sensor_type type,
510518

511519
mutex_unlock(&pvt->iface_mtx);
512520

521+
if (!ret)
522+
return -ETIMEDOUT;
523+
513524
if (type == PVT_TEMP)
514525
*val = pvt_calc_poly(&poly_N_to_temp, data);
515526
else

0 commit comments

Comments
 (0)