lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 29 Dec 2014 04:50:23 -0800
From:	Guenter Roeck <linux@...ck-us.net>
To:	Lukasz Majewski <l.majewski@...sung.com>
Cc:	Eduardo Valentin <edubezval@...il.com>,
	Kamil Debski <k.debski@...sung.com>,
	Jean Delvare <jdelvare@...e.de>, lm-sensors@...sensors.org,
	Linux PM list <linux-pm@...r.kernel.org>,
	"linux-samsung-soc@...r.kernel.org" 
	<linux-samsung-soc@...r.kernel.org>, devicetree@...r.kernel.org,
	Lukasz Majewski <l.majewski@...ess.pl>,
	Kukjin Kim <kgene.kim@...sung.com>,
	linux-kernel@...r.kernel.org,
	Sylwester Nawrocki <s.nawrocki@...sung.com>,
	Abhilash Kesavan <kesavan.abhilash@...il.com>,
	Abhilash Kesavan <a.kesavan@...sung.com>
Subject: Re: [PATCH v2 7/8] hwmon: thermal: Read PWM FAN configuration from
 device tree

On Mon, Dec 22, 2014 at 05:27:47PM +0100, Lukasz Majewski wrote:
> Code for reading PWM FAN configuration data via device tree.
> 
> Signed-off-by: Lukasz Majewski <l.majewski@...sung.com>
> ---

The headline is quite misleading. Please provide the affected subsystem (hwmon)
and the affected driver (pwm-fan) in the hwmon-customary form
	hwmon: (pwm-fan) Description

The Description should explain what the patch is about.

> Changes for v2:
> - Rename pwm_fan_max_states to pwm_fan_cooling_levels
> - Moving pwm_fan_of_get_cooling_data() call after setting end enabling PWM FAN
> - pwm_fan_of_get_cooling_data() now can fail - preserving old behaviour
> - Remove unnecessary dev_err() call
> ---
>  drivers/hwmon/pwm-fan.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 47 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
> index 870e100..8e68308 100644
> --- a/drivers/hwmon/pwm-fan.c
> +++ b/drivers/hwmon/pwm-fan.c
> @@ -30,7 +30,10 @@
>  struct pwm_fan_ctx {
>  	struct mutex lock;
>  	struct pwm_device *pwm;
> -	unsigned char pwm_value;
> +	unsigned int pwm_value;
> +	unsigned int pwm_fan_state;
> +	unsigned int pwm_fan_max_state;
> +	unsigned int *pwm_fan_cooling_levels;
>  };
>  
>  static int  __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)
> @@ -100,6 +103,47 @@ static struct attribute *pwm_fan_attrs[] = {
>  
>  ATTRIBUTE_GROUPS(pwm_fan);
>  
> +int pwm_fan_of_get_cooling_data(struct device *dev, struct pwm_fan_ctx *ctx)
> +{
> +	struct device_node *np = dev->of_node;
> +	struct property *pp;
> +	int len, num, i;
> +
> +	pp = of_find_property(np, "cooling-levels", &len);
> +	if (!pp) {
> +		dev_err(dev, "Property: 'cooling-levels' not found\n");
> +		return -EINVAL;
> +	}
> +
> +	if (len == 0) {
> +		dev_err(dev, "Length wrong value!\n");

Semantics. "Wrong length" would be better.

> +		return -EINVAL;
> +	}
> +

of_property_count_elems_of_size() might be more appropriate here.

> +	ctx->pwm_fan_cooling_levels = devm_kzalloc(dev, len, GFP_KERNEL);
> +	if (!ctx->pwm_fan_cooling_levels)
> +		return -ENOMEM;
> +
> +	num = len / sizeof(u32);

What if 'num' is 0 ? Is that guaranteed to never happen ?

> +	if (of_property_read_u32_array(np, pp->name,
> +				       ctx->pwm_fan_cooling_levels, num)) {
> +		dev_err(dev, "Property: %s cannot be read!\n", pp->name);

The ':' after 'Property' in those error messages doesn't seem to make much sense
to me.

> +		return -EINVAL;

of_property_read_u32_array() returns an error code. Please use it.

> +	}
> +
> +	for (i = 0; i < num; i++) {
> +		if (ctx->pwm_fan_cooling_levels[i] > MAX_PWM) {
> +			dev_err(dev, "PWM fan state[%d]:%d > %d\n", i,
> +				ctx->pwm_fan_cooling_levels[i], MAX_PWM);
> +			return -EINVAL;
> +		}
> +	}
> +
> +	ctx->pwm_fan_max_state = num - 1;
> +
> +	return 0;
> +}
> +
>  static int pwm_fan_probe(struct platform_device *pdev)
>  {
>  	struct device *hwmon;
> @@ -145,6 +189,8 @@ static int pwm_fan_probe(struct platform_device *pdev)
>  		pwm_disable(ctx->pwm);
>  		return PTR_ERR(hwmon);
>  	}
> +
> +	pwm_fan_of_get_cooling_data(&pdev->dev, ctx);

Now this is odd. Adding a function to return an error code just to ignore it
doesn't make much sense. While it makes sense to ignore errors if there is no
cooling data in the devicetree, errors due to bad devicetree data should not be
ignored.

I am also a bit concerned that you make this call _after_ instantiating the
hwmon device; this may potentially result in a race condition. Please ensure
that this is not the case.

Thanks,
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists