From: Gabriele Gorla <gorlik@penguintown.net>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH] adm1026: fix setting fan_div
Date: Tue, 30 Nov 2010 19:10:53 +0000 [thread overview]
Message-ID: <20101130191053.GA30973@penguintown.net> (raw)
In-Reply-To: <20101130014623.GA26439@penguintown.net>
On Tue, Nov 30, 2010 at 10:17:13AM +0100, Jean Delvare wrote:
> Thanks for the patch. It's hard to believe the code has been broken for
> so long and nobody complained...
>
> Please run your patch through scripts/checkpatch.pl, and fix all the
> style errors before you resubmit.
ok, I will.
> >
> > diff -r -U 5 linux-source-2.6.26_orig/drivers/hwmon/adm1026.c linux-source-2.6.26/drivers/hwmon/adm1026.c
> > --- linux-source-2.6.26_orig/drivers/hwmon/adm1026.c 2008-07-13 14:51:29.000000000 -0700
> > +++ linux-source-2.6.26/drivers/hwmon/adm1026.c 2010-11-29 17:21:06.000000000 -0800
> > @@ -918,37 +918,42 @@
> > {
> > struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> > int nr = sensor_attr->index;
> > struct i2c_client *client = to_i2c_client(dev);
> > struct adm1026_data *data = i2c_get_clientdata(client);
> > - int val, orig_div, new_div, shift;
> > + int val, orig_div, new_div;
> >
> > val = simple_strtol(buf, NULL, 10);
> > - new_div = DIV_TO_REG(val);
> > - if (new_div = 0) {
> > - return -EINVAL;
> > - }
> > - mutex_lock(&data->update_lock);
> > - orig_div = data->fan_div[nr];
> > - data->fan_div[nr] = DIV_FROM_REG(new_div);
> >
> > - if (nr < 4) { /* 0 <= nr < 4 */
> > - shift = 2 * nr;
> > - adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
> > - ((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
> > - (new_div << shift)));
> > - } else { /* 3 < nr < 8 */
> > - shift = 2 * (nr - 4);
> > - adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
> > - ((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
> > - (new_div << shift)));
> > + if(val<1 || val>8) {
> > + return -EINVAL;
>
> As underlined by Phil already, this is a little inconsistent. You
> should reject all invalid values, as documented at the end of
> Documentation/hwmon/sysfs-interface. But this should be done in a
> separate patch, as this isn't really a bug fix and changes the driver's
> behavior on invalid input.
Original code will reject 1 as input. I think this is a bug as div=1 is
valid for adm1026.
Anyway, if you think I should separate the patch and reject all invalid
values it's ok for me.
> > + adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
> > + (DIV_TO_REG(data->fan_div[4]) << 0) |
> > + (DIV_TO_REG(data->fan_div[5]) << 2) |
> > + (DIV_TO_REG(data->fan_div[6]) << 4) |
> > + (DIV_TO_REG(data->fan_div[7]) << 6) );
> > + }
>
> Note: this is horribly inefficient. In my opinion, data->fan_div should
> hold split but un-decoded register values. Calling DIV_FROM_REG() is
> cheap, calling DIV_TO_REG() is expensive. In fact DIV_TO_REG()
> shouldn't exist in the first place, as the conversion should happen in
> a single place. Again, this is material for a separate patch.
agree.
thanks,
GG
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
next prev parent reply other threads:[~2010-11-30 19:10 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-30 1:49 [lm-sensors] [PATCH] adm1026: fix setting fan_div Gabriele Gorla
2010-11-30 2:29 ` Phil Pokorny
2010-11-30 8:04 ` Gabriele Gorla
2010-11-30 9:17 ` Jean Delvare
2010-11-30 15:50 ` Guenter Roeck
2010-11-30 19:05 ` Phil Pokorny
2010-11-30 19:10 ` Gabriele Gorla [this message]
2010-11-30 19:19 ` Phil Pokorny
2010-11-30 19:44 ` Jean Delvare
2010-11-30 20:30 ` Jean Delvare
2010-12-01 1:05 ` Gabriele Gorla
2010-12-01 2:46 ` Phil Pokorny
2010-12-01 8:18 ` Jean Delvare
2010-12-01 8:55 ` Jean Delvare
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=20101130191053.GA30973@penguintown.net \
--to=gorlik@penguintown.net \
--cc=lm-sensors@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.