public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Eddie James <eajames@linux.ibm.com>
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	jdelvare@suse.com
Subject: Re: [PATCH] hwmon: (occ) Fix poll rate limiting
Date: Thu, 29 Apr 2021 18:23:23 -0700	[thread overview]
Message-ID: <20210430012323.GA186319@roeck-us.net> (raw)
In-Reply-To: <20210429151336.18980-1-eajames@linux.ibm.com>

On Thu, Apr 29, 2021 at 10:13:36AM -0500, Eddie James wrote:
> The poll rate limiter time was initialized at zero. This breaks the
> comparison in time_after if jiffies is large. Switch to storing the
> next update time rather than the previous time, and initialize the
> time when the device is probed.
> 
> Fixes: c10e753d43eb ("hwmon (occ): Add sensor types and versions")
> Signed-off-by: Eddie James <eajames@linux.ibm.com>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/occ/common.c | 5 +++--
>  drivers/hwmon/occ/common.h | 2 +-
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hwmon/occ/common.c b/drivers/hwmon/occ/common.c
> index f1ac153d0b56..967532afb1c0 100644
> --- a/drivers/hwmon/occ/common.c
> +++ b/drivers/hwmon/occ/common.c
> @@ -217,9 +217,9 @@ int occ_update_response(struct occ *occ)
>  		return rc;
>  
>  	/* limit the maximum rate of polling the OCC */
> -	if (time_after(jiffies, occ->last_update + OCC_UPDATE_FREQUENCY)) {
> +	if (time_after(jiffies, occ->next_update)) {
>  		rc = occ_poll(occ);
> -		occ->last_update = jiffies;
> +		occ->next_update = jiffies + OCC_UPDATE_FREQUENCY;
>  	} else {
>  		rc = occ->last_error;
>  	}
> @@ -1165,6 +1165,7 @@ int occ_setup(struct occ *occ, const char *name)
>  		return rc;
>  	}
>  
> +	occ->next_update = jiffies + OCC_UPDATE_FREQUENCY;
>  	occ_parse_poll_response(occ);
>  
>  	rc = occ_setup_sensor_attrs(occ);
> diff --git a/drivers/hwmon/occ/common.h b/drivers/hwmon/occ/common.h
> index 67e6968b8978..e6df719770e8 100644
> --- a/drivers/hwmon/occ/common.h
> +++ b/drivers/hwmon/occ/common.h
> @@ -99,7 +99,7 @@ struct occ {
>  	u8 poll_cmd_data;		/* to perform OCC poll command */
>  	int (*send_cmd)(struct occ *occ, u8 *cmd);
>  
> -	unsigned long last_update;
> +	unsigned long next_update;
>  	struct mutex lock;		/* lock OCC access */
>  
>  	struct device *hwmon;

      reply	other threads:[~2021-04-30  1:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-29 15:13 [PATCH] hwmon: (occ) Fix poll rate limiting Eddie James
2021-04-30  1:23 ` 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=20210430012323.GA186319@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=eajames@linux.ibm.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox