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  linux-cve-announce  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]
Message-ID: <bd2b256b-5149-491a-a482-6e4488467fa5@roeck-us.net>
Date: Thu, 11 Jul 2024 21:37:29 -0700
From: Guenter Roeck <linux@...ck-us.net>
To: Chris Packham <chris.packham@...iedtelesis.co.nz>, jdelvare@...e.com,
 robh@...nel.org, krzk+dt@...nel.org, conor+dt@...nel.org, ukleinek@...nel.org
Cc: linux-hwmon@...r.kernel.org, devicetree@...r.kernel.org,
 linux-kernel@...r.kernel.org, linux-pwm@...r.kernel.org
Subject: Re: [PATCH v5 3/3] hwmon: (adt7475) Add support for configuring
 initial PWM state

On 7/11/24 16:46, Chris Packham wrote:
> By default the PWM duty cycle in hardware is 100%. On some systems this
> can cause unwanted fan noise. Add the ability to specify the fan
> connections and initial state of the PWMs via device properties.
> 
> Signed-off-by: Chris Packham <chris.packham@...iedtelesis.co.nz>
> ---
...
> +static int adt7475_pwm_properties_parse_reference_args(struct fwnode_handle *fwnode,
> +						       struct adt7475_pwm_config *cfg)
> +{
> +	int ret;
> +	struct fwnode_reference_args args = {};
> +	int freq_hz;
> +	int duty;
> +
> +	ret = fwnode_property_get_reference_args(fwnode, "pwms", "#pwm-cells", 0, 0, &args);
> +	if (ret)
> +		return ret;
> +
> +	if (args.nargs != 4) {
> +		fwnode_handle_put(args.fwnode);
> +		return -EINVAL;
> +	}
> +
> +	freq_hz = 1000000000UL / args.args[1];
> +	duty = 255 / (args.args[1] / args.args[3]);
> +
You'll need to validate args.args[1] and args.args[3] to ensure that there are no
divide by 0 errors.

On a side note,
	a = b / (c / d) == b / c * d (at least for d != 0)
Since the result is defined for d == 0, you'd only have to make sure
that args.args[1] > 0 and that the result for the duty cycle is <= 255.

> +	cfg->index = args.args[0];
> +	cfg->freq = find_closest(freq_hz, pwmfreq_table, ARRAY_SIZE(pwmfreq_table));
> +	cfg->flags = args.args[2];
> +	cfg->duty = clamp_val(duty, 0, 0xFF);
> +
> +	fwnode_handle_put(args.fwnode);
> +
> +	return 0;
> +}
> +
> +static int adt7475_pwm_properties_parse_args(struct fwnode_handle *fwnode,
> +					     struct adt7475_pwm_config *cfg)
> +{
> +	int ret;
> +	u32 args[4] = {};
> +	int freq_hz;
> +	int duty;
> +
> +	ret = fwnode_property_read_u32_array(fwnode, "pwms", args, ARRAY_SIZE(args));
> +	if (ret)
> +		return ret;
> +
> +	freq_hz = 1000000000UL / args[1];
> +	duty = 255 / (args[1] / args[3]);
> +
> +	cfg->index = args[0];
> +	cfg->freq = find_closest(freq_hz, pwmfreq_table, ARRAY_SIZE(pwmfreq_table));
> +	cfg->flags = args[2];
> +	cfg->duty = clamp_val(duty, 0, 0xFF);
> +

The code above is duplicate; please combine into a single function
(I don't mind if it has four parameters).

Thanks,
Guenter


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ