[PATCH] missing parentheses?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Roel,

On Thu, 14 May 2009 13:29:38 +0200, Roel Kluin wrote:
> Add missing parentheses.
> 
> Signed-off-by: Roel Kluin <roel.kluin at gmail.com>
> ---
> The original code looks odd, but I am not sure whether my patch is correct.
> So please review.

The original code looks good to me and your patch doesn't.

> 
> diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c
> index 3195a26..a5a511b 100644
> --- a/drivers/hwmon/lm63.c
> +++ b/drivers/hwmon/lm63.c
> @@ -219,9 +219,9 @@ static ssize_t show_pwm1(struct device *dev, struct device_attribute *dummy,
>  			 char *buf)
>  {
>  	struct lm63_data *data = lm63_update_device(dev);
> -	return sprintf(buf, "%d\n", data->pwm1_value >= 2 * data->pwm1_freq ?
> +	return sprintf(buf, "%d\n", data->pwm1_value >= 2 * (data->pwm1_freq ?
>  		       255 : (data->pwm1_value * 255 + data->pwm1_freq) /
> -		       (2 * data->pwm1_freq));
> +		       (2 * data->pwm1_freq)));

The correct parentheses would be:

	return sprintf(buf, "%d\n", (data->pwm1_value >= 2 * data->pwm1_freq) ?
		       255 : ((data->pwm1_value * 255 + data->pwm1_freq) /
		       (2 * data->pwm1_freq)));

Which I think is equivalent to what we already have, since the ?:
operator has low precedence.

>  }
>  
>  static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy,


-- 
Jean Delvare



[Index of Archives]     [Linux Kernel]     [Linux Hardware Monitoring]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux