From: Gabriele Gorla <gorlik@penguintown.net>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH] adm1026: fix setting fan_div (2nd try)
Date: Thu, 02 Dec 2010 02:02:31 +0000 [thread overview]
Message-ID: <20101202020230.GA22774@penguintown.net> (raw)
In-Reply-To: <20101201005717.GE30973@penguintown.net>
On Wed, Dec 01, 2010 at 02:59:06PM +0100, Jean Delvare wrote:
> Your patch is correct. However, in order to get the fix in stable
> kernel series, I would prefer an even more minimalist fix, only
> addressing the actual bug. The two minor optimizations (skipping the
> register write if the value is the same and skipping the call to
> fixup_fan_min if the value is different but resulted in the same
> register encoding) would rather be left out at this time.
>
> This would result in the following patch:
>
> ---
> drivers/hwmon/adm1026.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> --- linux-2.6.37-rc4.orig/drivers/hwmon/adm1026.c 2010-12-01 13:48:13.000000000 +0100
> +++ linux-2.6.37-rc4/drivers/hwmon/adm1026.c 2010-12-01 14:20:14.000000000 +0100
> @@ -916,7 +916,7 @@ static ssize_t set_fan_div(struct device
> 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);
> @@ -928,15 +928,17 @@ static ssize_t set_fan_div(struct device
> 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)));
> + (DIV_TO_REG(data->fan_div[0]) << 0) |
> + (DIV_TO_REG(data->fan_div[1]) << 2) |
> + (DIV_TO_REG(data->fan_div[2]) << 4) |
> + (DIV_TO_REG(data->fan_div[3]) << 6));
> } 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)));
> + (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));
> }
>
> if (data->fan_div[nr] != orig_div) {
>
> As you can see, it's more compact and immediately obviously correct. So
> backporting it to kernels 2.6.36, 2.6.32, 2.6.27 and maybe even
> 2.6.16 will be trivial. Is this OK with you? You retain patch
> authorship, of course.
Sounds good to me. Do I need to submit it again, or you will take care
of the re-submission?
> Regarding the optimizations, I'm not even sure if we need them.
We could debate this issues for weeks but I am sure we all have better
things to do than trying to overoptimize a non critical code path. :-)
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-12-02 2:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-01 0:57 [lm-sensors] [PATCH] adm1026: fix setting fan_div (2nd try) Gabriele Gorla
2010-12-01 2:50 ` Phil Pokorny
2010-12-01 13:59 ` Jean Delvare
2010-12-02 2:02 ` Gabriele Gorla [this message]
2010-12-02 8:13 ` 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=20101202020230.GA22774@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.