All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Serge Semin <Sergey.Semin@baikalelectronics.ru>
Cc: Jean Delvare <jdelvare@suse.com>,
	Maxim Kaurkin <maxim.kaurkin@baikalelectronics.ru>,
	Serge Semin <fancer.lancer@gmail.com>,
	Alexey Malahov <Alexey.Malahov@baikalelectronics.ru>,
	Pavel Parkhomenko <Pavel.Parkhomenko@baikalelectronics.ru>,
	linux-mips@vger.kernel.org, linux-hwmon@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] hwmon: bt1-pvt: Wait for the completion with timeout
Date: Fri, 2 Oct 2020 09:15:59 -0700	[thread overview]
Message-ID: <20201002161559.GA44651@roeck-us.net> (raw)
In-Reply-To: <20200920110924.19741-4-Sergey.Semin@baikalelectronics.ru>

On Sun, Sep 20, 2020 at 02:09:23PM +0300, Serge Semin wrote:
> 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: 87976ce2825d ("hwmon: Add Baikal-T1 PVT sensor driver")
> Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/bt1-pvt.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/bt1-pvt.c b/drivers/hwmon/bt1-pvt.c
> index 2600426a3b21..3e1d56585b91 100644
> --- a/drivers/hwmon/bt1-pvt.c
> +++ b/drivers/hwmon/bt1-pvt.c
> @@ -477,6 +477,7 @@ static int pvt_read_data(struct pvt_hwmon *pvt, enum pvt_sensor_type type,
>  			 long *val)
>  {
>  	struct pvt_cache *cache = &pvt->cache[type];
> +	unsigned long timeout;
>  	u32 data;
>  	int ret;
>  
> @@ -500,7 +501,14 @@ static int pvt_read_data(struct pvt_hwmon *pvt, enum pvt_sensor_type type,
>  	pvt_update(pvt->regs + PVT_INTR_MASK, PVT_INTR_DVALID, 0);
>  	pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, PVT_CTRL_EN);
>  
> -	wait_for_completion(&cache->conversion);
> +	/*
> +	 * Wait with timeout since in case if the sensor is suddenly powered
> +	 * down the request won't be completed and the caller will hang up on
> +	 * this procedure until the power is back up again. Multiply the
> +	 * timeout by the factor of two to prevent a false timeout.
> +	 */
> +	timeout = 2 * usecs_to_jiffies(ktime_to_us(pvt->timeout));
> +	ret = wait_for_completion_timeout(&cache->conversion, timeout);
>  
>  	pvt_update(pvt->regs + PVT_CTRL, PVT_CTRL_EN, 0);
>  	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,
>  
>  	mutex_unlock(&pvt->iface_mtx);
>  
> +	if (!ret)
> +		return -ETIMEDOUT;
> +
>  	if (type == PVT_TEMP)
>  		*val = pvt_calc_poly(&poly_N_to_temp, data);
>  	else

      reply	other threads:[~2020-10-02 16:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-20 11:09 [PATCH 0/3] hwmon: bt1-pvt: Fix PVT sensor being unpowered Serge Semin
2020-09-20 11:09 ` [PATCH 1/3] hwmon: bt1-pvt: Test sensor power supply on probe Serge Semin
2020-10-02 16:15   ` Guenter Roeck
2020-09-20 11:09 ` [PATCH 2/3] hwmon: bt1-pvt: Cache current update timeout Serge Semin
2020-10-02 16:15   ` Guenter Roeck
2020-09-20 11:09 ` [PATCH 3/3] hwmon: bt1-pvt: Wait for the completion with timeout Serge Semin
2020-10-02 16:15   ` Guenter Roeck [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201002161559.GA44651@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=Alexey.Malahov@baikalelectronics.ru \
    --cc=Pavel.Parkhomenko@baikalelectronics.ru \
    --cc=Sergey.Semin@baikalelectronics.ru \
    --cc=fancer.lancer@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=maxim.kaurkin@baikalelectronics.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.