Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp467543ybl; Tue, 28 Jan 2020 06:25:51 -0800 (PST) X-Google-Smtp-Source: APXvYqyfGBJjjx7gF1MUOuoZ0dFJLAIkap+tVjGouVzFgc0KM7B9rB/zzbD4Xx0riJUhrxbG8f3K X-Received: by 2002:a05:6830:1042:: with SMTP id b2mr16473419otp.306.1580221551029; Tue, 28 Jan 2020 06:25:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580221551; cv=none; d=google.com; s=arc-20160816; b=Flx6H7YuWnLoazkHezVHvp+ld8J3YT42wzQY9PV//QcZRsPBl1zM29ixJVcrYX2Ne/ NrF4KoZQuVakKzcGFQkJJ0zmASQmLm8XTYjiimxUEtNKdQeyKHljDuP+IjDnI3e4RjH0 rLnOHJd0exj5IosJJg6MsMPS+13yEkQKaU/qMSTJHja5UfyOD6NAbWJimYF6Dyy2XA67 CICY0V7p4JbNHVMqlrYcf9VIP3ER5KQIiRTF4FPyIXk8miwNORIOfd42w1AKJrBVNIZs Uqwbut4RBB4eBeVO1iypx7Az8HewCRue9g1Ogy0ldgcqd7Lx9giXf0VWU7BsH6gQItET FieQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=osEEpisUHd5BAepw/Qkoza83C1XxR4sSAZzSpKCNLFE=; b=AXMOYWx0dQgb/rmosLnJYVdU1wSKfUc6zAdzvVjQiNEq5TmF98unddW70PSpSkH130 bGkGSHdCCXIjSEH7aqyE9r2C7xBIa2khuSlEG02Y52/MWtcXLelvWQ1YhQguVcMzhEH+ CJsPUvnCyoyKmXarIKRXSyd91mFkvCio8P2M1qr+UA+Wnffhp8mUg03A4IGY+yt9j/H3 VO1tjpjQwKozwcEC5cNODtkgJMxv+Bk/0JdcMTdjZDznDc9HyKsbgMVe5/FTZJFwnqHJ fLaPYIVH6u4rCMG4G7rpcwtns3zlUBm3KT10zpWLc2dZaJJMTQL6/k2vwCI0bAa2oFH6 b+lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Tq9/JJHR"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f17si8434428oto.85.2020.01.28.06.25.39; Tue, 28 Jan 2020 06:25:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Tq9/JJHR"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732758AbgA1OYp (ORCPT + 99 others); Tue, 28 Jan 2020 09:24:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:51536 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732370AbgA1OYn (ORCPT ); Tue, 28 Jan 2020 09:24:43 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1526B24686; Tue, 28 Jan 2020 14:24:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221482; bh=rz9au/x2/LhW2l2P+rOP9AVynizyhC9avk5oBjR3xvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tq9/JJHRXKXfdRf8S2IO9gOU/4Mod38jzESjnLUkEQ8Xfs8u5xWW4+Q41ckhgDGc1 4CpukFcisw9iQC1vDJlvdEibMvM+kQOvOjk0C1CmzTVUhVfrm6AXLrGM6vBnt9G7ga N8CtmCWZZdfSYXXSpRYqYnqtJ9o2tJVeNwhkGtGE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luuk Paulussen , Guenter Roeck Subject: [PATCH 4.9 243/271] hwmon: (adt7475) Make volt2reg return same reg as reg2volt input Date: Tue, 28 Jan 2020 15:06:32 +0100 Message-Id: <20200128135910.618534426@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135852.449088278@linuxfoundation.org> References: <20200128135852.449088278@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 cc: stable@vger.kernel.org Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- 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); }