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] [day] [month] [year] [list]
Message-ID: <fe6d1df7-eefc-4e4e-9f3c-989f982b0daa@denx.de>
Date: Thu, 11 Jul 2024 03:29:28 +0200
From: Marek Vasut <marex@...x.de>
To: pieterjanca@...il.com, Pavel Machek <pavel@....cz>,
 Lee Jones <lee@...nel.org>, Rob Herring <robh@...nel.org>,
 Krzysztof Kozlowski <krzk+dt@...nel.org>, Conor Dooley
 <conor+dt@...nel.org>, Isai Gaspar <isaiezequiel.gaspar@....com>
Cc: linux-leds@...r.kernel.org, devicetree@...r.kernel.org,
 linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 2/2] leds: leds-pca995x: Add support for NXP PCA9956B

On 7/10/24 4:32 PM, Pieterjan Camerlynck via B4 Relay wrote:

[...]

> @@ -52,9 +68,9 @@ struct pca995x_led {
>   };
>   
>   struct pca995x_chip {
> +	const struct pca995x_chipdef *chipdef;
>   	struct regmap *regmap;
> -	struct pca995x_led leds[PCA995X_MAX_OUTPUTS];
> -	int btype;
> +	struct pca995x_led leds[];

Please increase PCA995X_MAX_OUTPUTS to 24 and avoid this variable length 
array at the end.

>   };
>   
>   static int pca995x_brightness_set(struct led_classdev *led_cdev,
> @@ -62,10 +78,11 @@ static int pca995x_brightness_set(struct led_classdev *led_cdev,
>   {
>   	struct pca995x_led *led = ldev_to_led(led_cdev);
>   	struct pca995x_chip *chip = led->chip;
> +	const struct pca995x_chipdef *chipdef = chip->chipdef;
>   	u8 ledout_addr, pwmout_addr;
>   	int shift, ret;
>   
> -	pwmout_addr = (chip->btype ? PCA9955B_PWM0 : PCA9952_PWM0) + led->led_no;
> +	pwmout_addr = (chipdef->pwm_base) + led->led_no;

Parenthesis around (chipdef->pwm_base) not needed.

>   	ledout_addr = PCA995X_LEDOUT0 + (led->led_no / PCA995X_OUTPUTS_PER_REG);
>   	shift = PCA995X_LDRX_BITS * (led->led_no % PCA995X_OUTPUTS_PER_REG);
>   
> @@ -101,24 +118,24 @@ static const struct regmap_config pca995x_regmap = {
>   
>   static int pca995x_probe(struct i2c_client *client)
>   {
> -	struct fwnode_handle *led_fwnodes[PCA995X_MAX_OUTPUTS] = { 0 };
>   	struct fwnode_handle *np, *child;
>   	struct device *dev = &client->dev;
> +	const struct pca995x_chipdef *chipdef;
>   	struct pca995x_chip *chip;
>   	struct pca995x_led *led;
> -	int i, btype, reg, ret;
> +	int reg, ret;
>   
> -	btype = (unsigned long)device_get_match_data(&client->dev);
> +	chipdef = device_get_match_data(&client->dev);
>   
>   	np = dev_fwnode(dev);
>   	if (!np)
>   		return -ENODEV;
>   
> -	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
> +	chip = devm_kzalloc(dev, struct_size(chip, leds, chipdef->num_leds), GFP_KERNEL);

This won't be needed once you fix up PCA995X_MAX_OUTPUTS above.

>   	if (!chip)
>   		return -ENOMEM;
>   
> -	chip->btype = btype;
> +	chip->chipdef = chipdef;
>   	chip->regmap = devm_regmap_init_i2c(client, &pca995x_regmap);
>   	if (IS_ERR(chip->regmap))
>   		return PTR_ERR(chip->regmap);

It is starting to look pretty good, thanks !

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ