mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jean Delvare <khali@linux-fr.org>
To: Eric Miao <eric.y.miao@gmail.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	lm-sensors <lm-sensors@lm-sensors.org>
Subject: Re: [lm-sensors] [PATCH] hwmon: (max1111) change sysfs interface to in[0-3]_input in millivolts
Date: Wed, 9 Nov 2011 13:51:15 +0100	[thread overview]
Message-ID: <20111109135115.40195f65@endymion.delvare> (raw)
In-Reply-To: <CAMPhdO-LLzPLfTzwf721ut75KYcGtAsW3VeqYusAG+jw-=yVXg@mail.gmail.com>

On Wed, 9 Nov 2011 20:33:27 +0800, Eric Miao wrote:
> On Wed, Nov 9, 2011 at 8:22 PM, Jean Delvare <khali@linux-fr.org> wrote:
> > Hi Eric,
> >
> > On Wed,  9 Nov 2011 19:15:03 +0800, Eric Miao wrote:
> >> This patch fixed the inconsistent max1111 sysfs interface as pointed
> >> out by Jean Delvare:
> >>
> >>     It was pointed to me that the max1111 driver doesn't implement the
> >>     standard sysfs interface for hwmon drivers (as described in
> >>     Documentation/hwmon/sysfs-interface). It exports files adc[0-3]_in,
> >>     which
> >>     aren't part of the standard interface. Presumably these should be
> >>     renamed to in[0-3]_input. Renaming them is probably not sufficient
> >>     though, as I see no scaling done in the driver. As the MAX1111 chip has
> >>     a documented full scale of 2.048V, I take it that the LSB of the ADC
> >>     has a weight of 8 mV. Exporting raw register values to user-space is
> >>     not OK.
> >>
> >> Reported-by: Jean Delvare <khali@linux-fr.org>
> >> Signed-off-by: Eric Miao <eric.y.miao@gmail.com>
> >> ---
> >>  drivers/hwmon/max1111.c |   13 +++++++------
> >>  1 files changed, 7 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/drivers/hwmon/max1111.c b/drivers/hwmon/max1111.c
> >> index c97b78e..0e9fcfd 100644
> >> --- a/drivers/hwmon/max1111.c
> >> +++ b/drivers/hwmon/max1111.c
> >> @@ -106,11 +106,12 @@ static ssize_t show_adc(struct device *dev,
> >>       if (ret < 0)
> >>               return ret;
> >>
> >> -     return sprintf(buf, "%d\n", ret);
> >> +     /* assume the reference voltage to be 2.048V */
> >> +     return sprintf(buf, "%d\n", 2048 * 256 / ret);
> >
> > I bet you did not actually test your changes? ret == 0 would obviously
> > crash the driver. The formula looks wrong anyway, should be 2048 *
> > ret / 256. Or in short ret * 8, i.e. LSB weight of the ADC is 8 mV.
> >
> 
> Oops, shame to death.
> 
> How about simply '2048 * ret / 256' to make it clear and leave it to
> the compiler to optimize?

I find the concept of LSB weight clear enough, but ultimately that's up
to you, as long as the compiler actually optimizes it.

-- 
Jean Delvare

  reply	other threads:[~2011-11-09 12:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-09 11:15 Eric Miao
2011-11-09 12:22 ` [lm-sensors] " Jean Delvare
2011-11-09 12:33   ` Eric Miao
2011-11-09 12:51     ` Jean Delvare [this message]
2011-11-09 13:02       ` Eric Miao

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=20111109135115.40195f65@endymion.delvare \
    --to=khali@linux-fr.org \
    --cc=eric.y.miao@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lm-sensors@lm-sensors.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

all inboxes | Powered by JetHome®