Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2337648ybz; Thu, 23 Apr 2020 16:17:12 -0700 (PDT) X-Google-Smtp-Source: APiQypK7I0QV1Lg5FEe9XhAXwPjzdmb+CiQcPPZSkM938UMatUnMnkkcQ86oTUwuoeGwDviq9BoB X-Received: by 2002:aa7:cb56:: with SMTP id w22mr5004665edt.345.1587683831973; Thu, 23 Apr 2020 16:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587683831; cv=none; d=google.com; s=arc-20160816; b=uocI6AgUaTJghBjOUVQ2zIz+83DcdthcqdYRGz5IYFEkI3tzj5X/cm1LFu8LbtKPf+ 7yOb16jRtdB3+Kf60oFGK22gcCVxmyILn2nFKqG9LMqnR6x/yCJniLHkmpugdnVznKK4 VQzq3Qh5FocvS5LnTKB8SQ8LGtZGuq7gig39ZJ2Q9emQdKz/o6GmROB4jTh0iQ4RPMmK 49OFYP/4/zoWC6eRGe6iVACdQ4SgMH8qERim4RN8aCIoiBtRJwa0fnQ5vENOsluJVvp/ D+3qj1FSeyiMlJsc8r5fXUalYfOe+jJTM7jKmQrivgNgbF5x54tZ/0kYsiG/8Lhw8M0j ERgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=Jdb0EeTJTp3tRxvOVI2rVn7SAD9LSb41kPWwBHVGKCU=; b=xRPMyQ54gEmp8TEm0ZlXhqWSCKbUpof/9MGlHMR1XzYye6nzzWIbXX4ziXXmiSnP5R sm32Uv4PaaAinxDFj3L0iv9uQcsojUxp/CmbKngnvgXRvbdfLgBP9pyqt00eozO+LsmY thUPk9yQ7ZRGmpv7j3PQwU0+o+1LNUPfqJg/uABNaTtie5ESb9vkwLkb0AAFRQHP9C84 JOSbnJmMcF8Dy5I7zCdKBy3ZqQkkaQKed5El0WxiXfZnWaV/90tzpNcclKxaeKkIZuBZ jRHmHNPvkT0FGFJZeLKehBOHlGbDmozctLuPwPE1HDL1Tbl08D1Qp6KqI0Qeiij9wBr6 XxxA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o19si2047046ejm.258.2020.04.23.16.16.48; Thu, 23 Apr 2020 16:17:11 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729043AbgDWXMT (ORCPT + 99 others); Thu, 23 Apr 2020 19:12:19 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:50104 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728518AbgDWXGv (ORCPT ); Thu, 23 Apr 2020 19:06:51 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jRkvY-0004mB-JC; Fri, 24 Apr 2020 00:06:40 +0100 Received: from ben by deadeye with local (Exim 4.93) (envelope-from ) id 1jRkvX-00E6xk-U1; Fri, 24 Apr 2020 00:06:39 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Guenter Roeck" , "Luuk Paulussen" Date: Fri, 24 Apr 2020 00:07:05 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 198/245] hwmon: (adt7475) Make volt2reg return same reg as reg2volt input In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.83-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Luuk Paulussen commit cf3ca1877574a306c0207cbf7fdf25419d9229df upstream. reg2volt returns the voltage that matches a given register value. Converting this back the other way with volt2reg didn't return the same register value because it used truncation instead of rounding. This meant that values read from sysfs could not be written back to sysfs to set back the same register value. With this change, volt2reg will return the same value for every voltage previously returned by reg2volt (for the set of possible input values) Signed-off-by: Luuk Paulussen Link: https://lore.kernel.org/r/20191205231659.1301-1-luuk.paulussen@alliedtelesis.co.nz Signed-off-by: Guenter Roeck Signed-off-by: Ben Hutchings --- drivers/hwmon/adt7475.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -268,9 +268,10 @@ static inline u16 volt2reg(int channel, long reg; if (bypass_attn & (1 << channel)) - reg = (volt * 1024) / 2250; + reg = DIV_ROUND_CLOSEST(volt * 1024, 2250); else - reg = (volt * r[1] * 1024) / ((r[0] + r[1]) * 2250); + reg = DIV_ROUND_CLOSEST(volt * r[1] * 1024, + (r[0] + r[1]) * 2250); return clamp_val(reg, 0, 1023) & (0xff << 2); }