From: khali@linux-fr.org (Jean Delvare)
To: lm-sensors@vger.kernel.org
Subject: [lm-sensors] [PATCH] Fix the set pwm value will change fan mode
Date: Tue, 30 May 2006 07:25:40 +0000 [thread overview]
Message-ID: <20060530092540.2205ea93.khali@linux-fr.org> (raw)
In-Reply-To: <444610F0.1070809@winbond.com.tw>
Hi Yuan,
> Here comes the patch, please can you check, i add the lock and allow fan
> pwm input range 0-255 here, the write also unconditional, please can you check :)
Thanks for the updated patch. There are a few new issues in
store_pwm_mode:
> @@ -736,29 +735,34 @@ store_pwm_mode(struct device *dev, struc
> const char *buf, size_t count)
> {
> struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> - int nr = sensor_attr->index - 1;
> + int nr = sensor_attr->index;
> struct i2c_client *client = to_i2c_client(dev);
> struct w83792d_data *data = i2c_get_clientdata(client);
> - u32 val;
> - u8 pwm_mode_mask = 0;
> + u32 val = simple_strtoul(buf, NULL, 10);
>
> - val = simple_strtoul(buf, NULL, 10);
> - data->pwm_mode[nr] = SENSORS_LIMIT(val, 0, 1);
> - pwm_mode_mask = w83792d_read_value(client,
> - W83792D_REG_PWM[nr]) & 0x7f;
> - w83792d_write_value(client, W83792D_REG_PWM[nr],
> - ((data->pwm_mode[nr]) << 7) | pwm_mode_mask);
> + mutex_lock(&data->update_lock);
> + data->pwm[nr] = w83792d_read_value(client, W83792D_REG_PWM[nr]);
> + if (0 = val) { /* DC mode */
> + data->pwm[nr] &= 0x7f;
> + } else if (1 = val) { /* PWM mode */
> + data->pwm[nr] = (data->pwm[nr] & 0x7f) | 0x80;
Equivalent to:
data->pwm[nr] |= 0x80;
> + } else {
> + return -EINVAL;
You return with the update lock held! It's easier to test the input
value for validity before taking the lock, this avoids that kind of
trap and is also more efficient.
> + }
> +
> + w83792d_write_value(client, W83792D_REG_PWM[nr], data->pwm[nr]);
> + mutex_unlock(&data->update_lock);
>
> return count;
> }
I've fixed both issues and applied your patch:
http://khali.linux-fr.org/devel/i2c/linux-2.6/hwmon-w83792d-pwm-set-fix.patch
Rudolf, parts of this patch should be ported back to the Linux 2.4
version of the driver. Please take care of this once our new Subversion
repository is usable.
Thanks,
--
Jean Delvare
next prev parent reply other threads:[~2006-05-30 7:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-19 10:29 [lm-sensors] [PATCH] Fix the set pwm value will change fan mode bug Yuan Mu
2006-05-27 19:28 ` [lm-sensors] [PATCH] Fix the set pwm value will change fan mode Rudolf Marek
2006-05-28 15:03 ` Jean Delvare
2006-05-28 15:55 ` Rudolf Marek
2006-05-30 2:12 ` Yuan Mu
2006-05-30 7:25 ` Jean Delvare [this message]
2006-05-30 7:34 ` Yuan Mu
2006-05-30 12:34 ` 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=20060530092540.2205ea93.khali@linux-fr.org \
--to=khali@linux-fr.org \
--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.