Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp59223pxj; Mon, 17 May 2021 20:54:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLq6AKuVl+ztr9LvkkOjCRezzMdwS5h76FqptwkDqYxnazwdOQMllZCga1CBicWKfkkTDZ X-Received: by 2002:a05:6602:2596:: with SMTP id p22mr2614442ioo.184.1621310076218; Mon, 17 May 2021 20:54:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621310076; cv=none; d=google.com; s=arc-20160816; b=jTgKT7dl9d59IhRQ21i10q0ea6VpUfimLD+7mao8OUX/UvQAqkRuEoac7gIU3EKMYM GrQ/whuM9tPRYE/uwiF+LuQiDk9aYWLK+zYQWQ6rMRmQypid0UdAM2/NfR1JVBFvEY/t Kcfj+E8Ja16ejVE50aHgkFBJSGt/VbDlpCwUSELleFgAXUZM/uLldm1PlySHdescqWTY UkFGGsXA6qNinDYUTpxZd6alHdXrx+w4ymtpmovvrTy3Q+yj37F0HZ2tYDbtlSJW4Wck 8wcHgShI84UyvZBOXN/IyEnfP/WcNr1V/L+UjPednSKm/xVLAIRTd5Uz/03CYfHma8W/ fGVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LNMbxRlfJmt+5mr/adMovcmEWHj6KWe2MGh4Y3wgA0c=; b=KvV87HYQU841lcw2gW74mTuTMw09H86yjt8iSVP72dPtKX0KBcBB/VFsYMe/h82LuO cckT/EEFJQjD+86xo1WlinJD4SCVbK9WtKFKSlmJHVSLD13V+sAl9ylDmCCJPHzMMlhK AqUjb32LTHFW76Mwqlo2RPdahJvV0eAGXy7aj8PkbhZ9niv550tjqz6VdxuigbIJpUpV gkkgk6pLY587kSm/N+ZC8T6piWVHLdN8iIXzWdbuTtWyG2SfvA47IsN+yqrSKIqrxVo3 Y2UCkIgdXzUZ0EfK59oMwvI3GWJgW9Vt84blmyB9cdi9aG1BSuBFKGRru/5P9bJRAuXY IYQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wKGO2zI7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i16si20267306iow.64.2021.05.17.20.53.50; Mon, 17 May 2021 20:54:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wKGO2zI7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239210AbhEQOkb (ORCPT + 99 others); Mon, 17 May 2021 10:40:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:33968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240830AbhEQOfS (ORCPT ); Mon, 17 May 2021 10:35:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F2AFA61407; Mon, 17 May 2021 14:16:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261018; bh=KXTQBfakH0BrCa8TE9zTPkNFh6ESzzSdqNu5g8TZeeE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wKGO2zI7cySQQwE4wTyymaRL+w9c/IATlUrNOl+1Aky7bc6d2l+HpWfiogPMA3UcI EZnH5opTd0L8K3uRifabTiEkMAOOWdlCO0fyY/Ts0hJYqFuArAe3xMAqK9Tg6/uK9f nZKJY2StgyU5kz62+sUSh8LHcD2Cwzsg39kI67Hg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eddie James , Guenter Roeck , Sasha Levin Subject: [PATCH 5.12 291/363] hwmon: (occ) Fix poll rate limiting Date: Mon, 17 May 2021 16:02:37 +0200 Message-Id: <20210517140312.437348221@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eddie James [ Upstream commit 5216dff22dc2bbbbe6f00335f9fd2879670e753b ] 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 Link: https://lore.kernel.org/r/20210429151336.18980-1-eajames@linux.ibm.com Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- 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 7a5e539b567b..580e63d7daa0 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; } @@ -1164,6 +1164,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; -- 2.30.2