* Re: [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable
2012-02-22 22:18 [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable Nikolaus Schulz
@ 2012-02-23 1:32 ` Guenter Roeck
2012-02-23 2:26 ` Guenter Roeck
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Guenter Roeck @ 2012-02-23 1:32 UTC (permalink / raw)
To: lm-sensors
On Wed, Feb 22, 2012 at 05:18:48PM -0500, Nikolaus Schulz wrote:
> From: Nikolaus Schulz <schulz@macnetix.de>
>
> The F75387 supports automatic fan control using either PWM duty cycle or
> RPM speed values. Make the driver detect the latter mode, and expose the
> different modes in sysfs as per pwm_enable, so that the user can switch
> between them.
>
> The interpretation of the pwm_enable attribute for the F75387 is adjusted
> to be a superset of those values used for similar Fintek chips which do
> not support automatic duty mode, with 2 mapping to automatic speed mode,
> and moving automatic duty mode to the new value 4.
>
> Toggling the duty mode via pwm_enable is currently denied for the F75387,
> as the chip then simply reinterprets the fan configuration register values
> according to the new mode, switching between RPM and PWM units, which
> makes this a dangerous operation.
>
> Signed-off-by: Nikolaus Schulz <mail@microschulz.de>
> ---
[ ... ]
> @@ -363,12 +382,14 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
> fanmode |= (1 << F75387_FAN_MANU_MODE(nr));
> fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
> break;
> - case 2: /* AUTOMATIC*/
> - fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
> + case 2: /* Automatic, speed mode */
> break;
> case 3: /* fan speed */
> fanmode |= (1 << F75387_FAN_MANU_MODE(nr));
> break;
> + case 4: /* Automatic, pwm */
> + fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
Might be time to get rid of those extra spaces.
> + break;
> }
> } else {
> /* clear each fanX_mode bit before setting them properly */
> @@ -386,6 +407,8 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
> break;
> case 3: /* fan speed */
> break;
> + case 4: /* Automatic pwm */
> + return -EOPNOTSUPP;
Should be -EINVAL.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable
2012-02-22 22:18 [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable Nikolaus Schulz
2012-02-23 1:32 ` Guenter Roeck
@ 2012-02-23 2:26 ` Guenter Roeck
2012-02-23 19:12 ` Nikolaus Schulz
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Guenter Roeck @ 2012-02-23 2:26 UTC (permalink / raw)
To: lm-sensors
On Wed, Feb 22, 2012 at 05:18:48PM -0500, Nikolaus Schulz wrote:
> From: Nikolaus Schulz <schulz@macnetix.de>
>
> The F75387 supports automatic fan control using either PWM duty cycle or
> RPM speed values. Make the driver detect the latter mode, and expose the
> different modes in sysfs as per pwm_enable, so that the user can switch
> between them.
>
> The interpretation of the pwm_enable attribute for the F75387 is adjusted
> to be a superset of those values used for similar Fintek chips which do
> not support automatic duty mode, with 2 mapping to automatic speed mode,
> and moving automatic duty mode to the new value 4.
>
> Toggling the duty mode via pwm_enable is currently denied for the F75387,
> as the chip then simply reinterprets the fan configuration register values
> according to the new mode, switching between RPM and PWM units, which
> makes this a dangerous operation.
>
> Signed-off-by: Nikolaus Schulz <mail@microschulz.de>
> ---
> drivers/hwmon/f75375s.c | 42 ++++++++++++++++++++++++++++++++++--------
> 1 files changed, 34 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c
> index 3b06abf..29b11c6 100644
> --- a/drivers/hwmon/f75375s.c
> +++ b/drivers/hwmon/f75375s.c
> @@ -266,6 +266,21 @@ static inline u16 rpm_to_reg(int rpm)
> return 1500000 / rpm;
> }
>
> +static bool duty_mode_enabled(u8 pwm_enable)
> +{
> + switch (pwm_enable) {
> + case 0: /* Manual, duty mode (full speed) */
> + case 1: /* Manual, duty mode */
> + case 4: /* Auto, duty mode */
> + return true;
> + case 2: /* Auto, speed mode */
> + case 3: /* Manual, speed mode */
> + return false;
> + default:
> + BUG();
> + }
> +}
This keeps bugging me ... I think it would make sense to simplify it to
return pwm_enable != 2 && pwm_enable != 3;
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable
2012-02-22 22:18 [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable Nikolaus Schulz
2012-02-23 1:32 ` Guenter Roeck
2012-02-23 2:26 ` Guenter Roeck
@ 2012-02-23 19:12 ` Nikolaus Schulz
2012-02-23 19:21 ` Guenter Roeck
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Nikolaus Schulz @ 2012-02-23 19:12 UTC (permalink / raw)
To: lm-sensors
On Wed, Feb 22, 2012 at 05:32:34PM -0800, Guenter Roeck wrote:
> On Wed, Feb 22, 2012 at 05:18:48PM -0500, Nikolaus Schulz wrote:
> > From: Nikolaus Schulz <schulz@macnetix.de>
> >
> > The F75387 supports automatic fan control using either PWM duty cycle or
> > RPM speed values. Make the driver detect the latter mode, and expose the
> > different modes in sysfs as per pwm_enable, so that the user can switch
> > between them.
> >
> > The interpretation of the pwm_enable attribute for the F75387 is adjusted
> > to be a superset of those values used for similar Fintek chips which do
> > not support automatic duty mode, with 2 mapping to automatic speed mode,
> > and moving automatic duty mode to the new value 4.
> >
> > Toggling the duty mode via pwm_enable is currently denied for the F75387,
> > as the chip then simply reinterprets the fan configuration register values
> > according to the new mode, switching between RPM and PWM units, which
> > makes this a dangerous operation.
> >
> > Signed-off-by: Nikolaus Schulz <mail@microschulz.de>
> > ---
> [ ... ]
>
> > @@ -363,12 +382,14 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
> > fanmode |= (1 << F75387_FAN_MANU_MODE(nr));
> > fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
> > break;
> > - case 2: /* AUTOMATIC*/
> > - fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
> > + case 2: /* Automatic, speed mode */
> > break;
> > case 3: /* fan speed */
> > fanmode |= (1 << F75387_FAN_MANU_MODE(nr));
> > break;
> > + case 4: /* Automatic, pwm */
> > + fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
>
> Might be time to get rid of those extra spaces.
I see no extra spaces. You mean the extra parentheses? I can update
the patch to drop them.
> > + break;
> > }
> > } else {
> > /* clear each fanX_mode bit before setting them properly */
> > @@ -386,6 +407,8 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
> > break;
> > case 3: /* fan speed */
> > break;
> > + case 4: /* Automatic pwm */
> > + return -EOPNOTSUPP;
>
> Should be -EINVAL.
The value 4 is valid as it encodes an existing mode, it's just that this
code path handles hardware that does not support that mode. Why should
the code return EINVAL?
Thanks for your review,
Nikolaus
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable
2012-02-22 22:18 [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable Nikolaus Schulz
` (2 preceding siblings ...)
2012-02-23 19:12 ` Nikolaus Schulz
@ 2012-02-23 19:21 ` Guenter Roeck
2012-02-23 19:50 ` Nikolaus Schulz
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Guenter Roeck @ 2012-02-23 19:21 UTC (permalink / raw)
To: lm-sensors
On Thu, 2012-02-23 at 14:12 -0500, Nikolaus Schulz wrote:
> On Wed, Feb 22, 2012 at 05:32:34PM -0800, Guenter Roeck wrote:
> > On Wed, Feb 22, 2012 at 05:18:48PM -0500, Nikolaus Schulz wrote:
> > > From: Nikolaus Schulz <schulz@macnetix.de>
> > >
> > > The F75387 supports automatic fan control using either PWM duty cycle or
> > > RPM speed values. Make the driver detect the latter mode, and expose the
> > > different modes in sysfs as per pwm_enable, so that the user can switch
> > > between them.
> > >
> > > The interpretation of the pwm_enable attribute for the F75387 is adjusted
> > > to be a superset of those values used for similar Fintek chips which do
> > > not support automatic duty mode, with 2 mapping to automatic speed mode,
> > > and moving automatic duty mode to the new value 4.
> > >
> > > Toggling the duty mode via pwm_enable is currently denied for the F75387,
> > > as the chip then simply reinterprets the fan configuration register values
> > > according to the new mode, switching between RPM and PWM units, which
> > > makes this a dangerous operation.
> > >
> > > Signed-off-by: Nikolaus Schulz <mail@microschulz.de>
> > > ---
> > [ ... ]
> >
> > > @@ -363,12 +382,14 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
> > > fanmode |= (1 << F75387_FAN_MANU_MODE(nr));
> > > fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
> > > break;
> > > - case 2: /* AUTOMATIC*/
> > > - fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
> > > + case 2: /* Automatic, speed mode */
> > > break;
> > > case 3: /* fan speed */
> > > fanmode |= (1 << F75387_FAN_MANU_MODE(nr));
> > > break;
> > > + case 4: /* Automatic, pwm */
> > > + fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
> >
> > Might be time to get rid of those extra spaces.
>
> I see no extra spaces. You mean the extra parentheses? I can update
> the patch to drop them.
>
There seem to be two spaces before and after |=.
> > > + break;
> > > }
> > > } else {
> > > /* clear each fanX_mode bit before setting them properly */
> > > @@ -386,6 +407,8 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
> > > break;
> > > case 3: /* fan speed */
> > > break;
> > > + case 4: /* Automatic pwm */
> > > + return -EOPNOTSUPP;
> >
> > Should be -EINVAL.
>
> The value 4 is valid as it encodes an existing mode, it's just that this
> code path handles hardware that does not support that mode. Why should
> the code return EINVAL?
>
val is invalid for this hardware. Also it returned -EINVAL before you
made your changes.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable
2012-02-22 22:18 [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable Nikolaus Schulz
` (3 preceding siblings ...)
2012-02-23 19:21 ` Guenter Roeck
@ 2012-02-23 19:50 ` Nikolaus Schulz
2012-02-23 19:58 ` Nikolaus Schulz
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Nikolaus Schulz @ 2012-02-23 19:50 UTC (permalink / raw)
To: lm-sensors
On Wed, Feb 22, 2012 at 06:26:00PM -0800, Guenter Roeck wrote:
> On Wed, Feb 22, 2012 at 05:18:48PM -0500, Nikolaus Schulz wrote:
> > +static bool duty_mode_enabled(u8 pwm_enable)
> > +{
> > + switch (pwm_enable) {
> > + case 0: /* Manual, duty mode (full speed) */
> > + case 1: /* Manual, duty mode */
> > + case 4: /* Auto, duty mode */
> > + return true;
> > + case 2: /* Auto, speed mode */
> > + case 3: /* Manual, speed mode */
> > + return false;
> > + default:
> > + BUG();
> > + }
> > +}
>
> This keeps bugging me ... I think it would make sense to simplify it to
>
> return pwm_enable != 2 && pwm_enable != 3;
Well, I used that verbose switch statement because
a) I feel uncomfortable using these magic numbers instead of a
well-defined enum - by the way, is there a reason for not using an enum for
that? - and
b) a simple logical expression like you suggested may lead to hidden
bugs once the range of valid values changes.
But if you insist, I can change that.
Nikolaus
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable
2012-02-22 22:18 [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable Nikolaus Schulz
` (4 preceding siblings ...)
2012-02-23 19:50 ` Nikolaus Schulz
@ 2012-02-23 19:58 ` Nikolaus Schulz
2012-02-23 20:00 ` Guenter Roeck
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Nikolaus Schulz @ 2012-02-23 19:58 UTC (permalink / raw)
To: lm-sensors
On Thu, Feb 23, 2012 at 11:21:09AM -0800, Guenter Roeck wrote:
> On Thu, 2012-02-23 at 14:12 -0500, Nikolaus Schulz wrote:
> > On Wed, Feb 22, 2012 at 05:32:34PM -0800, Guenter Roeck wrote:
> > > On Wed, Feb 22, 2012 at 05:18:48PM -0500, Nikolaus Schulz wrote:
> > > > From: Nikolaus Schulz <schulz@macnetix.de>
[...]
> > > > @@ -363,12 +382,14 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
> > > > fanmode |= (1 << F75387_FAN_MANU_MODE(nr));
> > > > fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
> > > > break;
> > > > - case 2: /* AUTOMATIC*/
> > > > - fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
> > > > + case 2: /* Automatic, speed mode */
> > > > break;
> > > > case 3: /* fan speed */
> > > > fanmode |= (1 << F75387_FAN_MANU_MODE(nr));
> > > > break;
> > > > + case 4: /* Automatic, pwm */
> > > > + fanmode |= (1 << F75387_FAN_DUTY_MODE(nr));
> > >
> > > Might be time to get rid of those extra spaces.
> >
> > I see no extra spaces. You mean the extra parentheses? I can update
> > the patch to drop them.
> >
> There seem to be two spaces before and after |=.
Ah, got it :)
> > > > + break;
> > > > }
> > > > } else {
> > > > /* clear each fanX_mode bit before setting them properly */
> > > > @@ -386,6 +407,8 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
> > > > break;
> > > > case 3: /* fan speed */
> > > > break;
> > > > + case 4: /* Automatic pwm */
> > > > + return -EOPNOTSUPP;
> > >
> > > Should be -EINVAL.
> >
> > The value 4 is valid as it encodes an existing mode, it's just that this
> > code path handles hardware that does not support that mode. Why should
> > the code return EINVAL?
> >
> val is invalid for this hardware.
Ok, I consider that a valid argument :)
> Also it returned -EINVAL before you
> made your changes.
That one less so, since before, the value 4 was never valid for any
hardware, but it is now for the F75387.
But I'm okay making it return EINVAL.
Thanks for your review,
Nikolaus
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable
2012-02-22 22:18 [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable Nikolaus Schulz
` (5 preceding siblings ...)
2012-02-23 19:58 ` Nikolaus Schulz
@ 2012-02-23 20:00 ` Guenter Roeck
2012-02-23 20:16 ` Nikolaus Schulz
2012-02-23 21:26 ` Guenter Roeck
8 siblings, 0 replies; 10+ messages in thread
From: Guenter Roeck @ 2012-02-23 20:00 UTC (permalink / raw)
To: lm-sensors
On Thu, 2012-02-23 at 14:50 -0500, Nikolaus Schulz wrote:
> On Wed, Feb 22, 2012 at 06:26:00PM -0800, Guenter Roeck wrote:
> > On Wed, Feb 22, 2012 at 05:18:48PM -0500, Nikolaus Schulz wrote:
> > > +static bool duty_mode_enabled(u8 pwm_enable)
> > > +{
> > > + switch (pwm_enable) {
> > > + case 0: /* Manual, duty mode (full speed) */
> > > + case 1: /* Manual, duty mode */
> > > + case 4: /* Auto, duty mode */
> > > + return true;
> > > + case 2: /* Auto, speed mode */
> > > + case 3: /* Manual, speed mode */
> > > + return false;
> > > + default:
> > > + BUG();
> > > + }
> > > +}
> >
> > This keeps bugging me ... I think it would make sense to simplify it to
> >
> > return pwm_enable != 2 && pwm_enable != 3;
>
> Well, I used that verbose switch statement because
>
> a) I feel uncomfortable using these magic numbers instead of a
> well-defined enum - by the way, is there a reason for not using an enum for
> that? - and
>
I don't think there is a reason other than being lazy.
> b) a simple logical expression like you suggested may lead to hidden
> bugs once the range of valid values changes.
>
Good point. Maybe start using an enum ?
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable
2012-02-22 22:18 [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable Nikolaus Schulz
` (6 preceding siblings ...)
2012-02-23 20:00 ` Guenter Roeck
@ 2012-02-23 20:16 ` Nikolaus Schulz
2012-02-23 21:26 ` Guenter Roeck
8 siblings, 0 replies; 10+ messages in thread
From: Nikolaus Schulz @ 2012-02-23 20:16 UTC (permalink / raw)
To: lm-sensors
On Thu, Feb 23, 2012 at 12:00:52PM -0800, Guenter Roeck wrote:
> On Thu, 2012-02-23 at 14:50 -0500, Nikolaus Schulz wrote:
> > On Wed, Feb 22, 2012 at 06:26:00PM -0800, Guenter Roeck wrote:
> > > On Wed, Feb 22, 2012 at 05:18:48PM -0500, Nikolaus Schulz wrote:
> > > > +static bool duty_mode_enabled(u8 pwm_enable)
> > > > +{
> > > > + switch (pwm_enable) {
> > > > + case 0: /* Manual, duty mode (full speed) */
> > > > + case 1: /* Manual, duty mode */
> > > > + case 4: /* Auto, duty mode */
> > > > + return true;
> > > > + case 2: /* Auto, speed mode */
> > > > + case 3: /* Manual, speed mode */
> > > > + return false;
> > > > + default:
> > > > + BUG();
> > > > + }
> > > > +}
> > >
> > > This keeps bugging me ... I think it would make sense to simplify it to
> > >
> > > return pwm_enable != 2 && pwm_enable != 3;
> >
> > Well, I used that verbose switch statement because
> >
> > a) I feel uncomfortable using these magic numbers instead of a
> > well-defined enum - by the way, is there a reason for not using an enum for
> > that? - and
> >
> I don't think there is a reason other than being lazy.
If I recall correctly, early versions of this driver posted to this list
did in fact have an enum here, but for some reason that was dropped.
> > b) a simple logical expression like you suggested may lead to hidden
> > bugs once the range of valid values changes.
> >
> Good point. Maybe start using an enum ?
I can prepare another patch for that.
But using an enum does not address b), so I still tend to keep the
switch statement(s). Are you okay with that?
Nikolaus
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable
2012-02-22 22:18 [lm-sensors] [PATCH 5/6] hwmon: (f75375s) Properly map the F75387 automatic modes to pwm_enable Nikolaus Schulz
` (7 preceding siblings ...)
2012-02-23 20:16 ` Nikolaus Schulz
@ 2012-02-23 21:26 ` Guenter Roeck
8 siblings, 0 replies; 10+ messages in thread
From: Guenter Roeck @ 2012-02-23 21:26 UTC (permalink / raw)
To: lm-sensors
On Thu, 2012-02-23 at 15:16 -0500, Nikolaus Schulz wrote:
> On Thu, Feb 23, 2012 at 12:00:52PM -0800, Guenter Roeck wrote:
> > On Thu, 2012-02-23 at 14:50 -0500, Nikolaus Schulz wrote:
> > > On Wed, Feb 22, 2012 at 06:26:00PM -0800, Guenter Roeck wrote:
> > > > On Wed, Feb 22, 2012 at 05:18:48PM -0500, Nikolaus Schulz wrote:
> > > > > +static bool duty_mode_enabled(u8 pwm_enable)
> > > > > +{
> > > > > + switch (pwm_enable) {
> > > > > + case 0: /* Manual, duty mode (full speed) */
> > > > > + case 1: /* Manual, duty mode */
> > > > > + case 4: /* Auto, duty mode */
> > > > > + return true;
> > > > > + case 2: /* Auto, speed mode */
> > > > > + case 3: /* Manual, speed mode */
> > > > > + return false;
> > > > > + default:
> > > > > + BUG();
> > > > > + }
> > > > > +}
> > > >
> > > > This keeps bugging me ... I think it would make sense to simplify it to
> > > >
> > > > return pwm_enable != 2 && pwm_enable != 3;
> > >
> > > Well, I used that verbose switch statement because
> > >
> > > a) I feel uncomfortable using these magic numbers instead of a
> > > well-defined enum - by the way, is there a reason for not using an enum for
> > > that? - and
> > >
> > I don't think there is a reason other than being lazy.
>
> If I recall correctly, early versions of this driver posted to this list
> did in fact have an enum here, but for some reason that was dropped.
>
> > > b) a simple logical expression like you suggested may lead to hidden
> > > bugs once the range of valid values changes.
> > >
> > Good point. Maybe start using an enum ?
>
> I can prepare another patch for that.
>
> But using an enum does not address b), so I still tend to keep the
> switch statement(s). Are you okay with that?
>
Just keep the switch statement. Not worth the argument, and if someone
objected to the enum earlier I'd rather not revive that discussion.
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 10+ messages in thread