Re: [PATCH 1/2] leds: ktd20xx: Add the KTD20xx family of the RGB LEDs driver from Kinetic

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

 



Hi Florian,

url:    https://github.com/0day-ci/linux/commits/Florian-Eckert/leds-Add-KTD20xx-RGB-LEDs-driver-from-Kinetic/20211109-181728
base:   git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds.git for-next
config: i386-randconfig-m031-20211115 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

smatch warnings:
drivers/leds/leds-ktd20xx.c:304 ktd20xx_probe_dt() warn: missing error code 'ret'
drivers/leds/leds-ktd20xx.c:492 current_color0_store() warn: unsigned 'value[i]' is never less than zero.
drivers/leds/leds-ktd20xx.c:566 current_color1_store() warn: unsigned 'value[i]' is never less than zero.
drivers/leds/leds-ktd20xx.c:661 faderate_store() warn: unsigned 'faderate' is never less than zero.

vim +/ret +304 drivers/leds/leds-ktd20xx.c

004e74105bb360 Florian Eckert 2021-11-09  281  static int ktd20xx_probe_dt(struct ktd20xx *chip)
004e74105bb360 Florian Eckert 2021-11-09  282  {
004e74105bb360 Florian Eckert 2021-11-09  283  	struct fwnode_handle *child = NULL;
004e74105bb360 Florian Eckert 2021-11-09  284  	struct led_init_data init_data = {};
004e74105bb360 Florian Eckert 2021-11-09  285  	struct led_classdev *led_cdev;
004e74105bb360 Florian Eckert 2021-11-09  286  	struct ktd20xx_led *led;
004e74105bb360 Florian Eckert 2021-11-09  287  	struct device *dev = &chip->client->dev;
004e74105bb360 Florian Eckert 2021-11-09  288  	u8 value[3] = { 0, 0, 0 };
004e74105bb360 Florian Eckert 2021-11-09  289  	int i = 0;
004e74105bb360 Florian Eckert 2021-11-09  290  	int ret = -EINVAL;
004e74105bb360 Florian Eckert 2021-11-09  291  	int color;
004e74105bb360 Florian Eckert 2021-11-09  292  
004e74105bb360 Florian Eckert 2021-11-09  293  	device_for_each_child_node(chip->dev, child) {
004e74105bb360 Florian Eckert 2021-11-09  294  		led = &chip->leds[i];
004e74105bb360 Florian Eckert 2021-11-09  295  
004e74105bb360 Florian Eckert 2021-11-09  296  		ret = fwnode_property_read_u32(child, "reg", &led->index);
004e74105bb360 Florian Eckert 2021-11-09  297  		if (ret) {
004e74105bb360 Florian Eckert 2021-11-09  298  			dev_err(dev, "missing property: reg\n");
004e74105bb360 Florian Eckert 2021-11-09  299  			goto child_out;
004e74105bb360 Florian Eckert 2021-11-09  300  		}
004e74105bb360 Florian Eckert 2021-11-09  301  		if (led->index >= KTD20XX_MAX_LEDS) {
004e74105bb360 Florian Eckert 2021-11-09  302  			dev_warn(dev, "property 'reg' must contain value between '0' and '%i'\n",
004e74105bb360 Florian Eckert 2021-11-09  303  					KTD20XX_MAX_LEDS);

ret = -EINVAL;

004e74105bb360 Florian Eckert 2021-11-09 @304  			goto child_out;
004e74105bb360 Florian Eckert 2021-11-09  305  		}
004e74105bb360 Florian Eckert 2021-11-09  306  
004e74105bb360 Florian Eckert 2021-11-09  307  		ret = fwnode_property_read_u32(child, "color", &color);
004e74105bb360 Florian Eckert 2021-11-09  308  		if (ret) {
004e74105bb360 Florian Eckert 2021-11-09  309  			dev_err(dev, "missing property: color\n");
004e74105bb360 Florian Eckert 2021-11-09  310  			goto child_out;
004e74105bb360 Florian Eckert 2021-11-09  311  		}
004e74105bb360 Florian Eckert 2021-11-09  312  		if (color != LED_COLOR_ID_RGB) {
004e74105bb360 Florian Eckert 2021-11-09  313  			dev_warn(dev, "property 'color' must contain value 'LED_COLOR_ID_RGB'\n");

ret = -EINVAL;

004e74105bb360 Florian Eckert 2021-11-09  314  			goto child_out;
004e74105bb360 Florian Eckert 2021-11-09  315  		}
004e74105bb360 Florian Eckert 2021-11-09  316  
004e74105bb360 Florian Eckert 2021-11-09  317  		/* Get default color register selection */
004e74105bb360 Florian Eckert 2021-11-09  318  		if (fwnode_property_read_u8_array(child, "kinetic,color-selection", value, 3))
004e74105bb360 Florian Eckert 2021-11-09  319  			dev_warn(dev, "no kinetic,color-selection property found, use default rgbt color selection from register 0.\n");
004e74105bb360 Florian Eckert 2021-11-09  320  
004e74105bb360 Florian Eckert 2021-11-09  321  		led->subled_info[0].color_index = LED_COLOR_ID_RED;
004e74105bb360 Florian Eckert 2021-11-09  322  		led->subled_info[0].channel = 0;
004e74105bb360 Florian Eckert 2021-11-09  323  		led->subled_info[0].intensity = value[0];
004e74105bb360 Florian Eckert 2021-11-09  324  		led->subled_info[1].color_index = LED_COLOR_ID_GREEN;
004e74105bb360 Florian Eckert 2021-11-09  325  		led->subled_info[1].channel = 1;
004e74105bb360 Florian Eckert 2021-11-09  326  		led->subled_info[1].intensity = value[1];
004e74105bb360 Florian Eckert 2021-11-09  327  		led->subled_info[2].color_index = LED_COLOR_ID_BLUE;
004e74105bb360 Florian Eckert 2021-11-09  328  		led->subled_info[2].channel = 2;
004e74105bb360 Florian Eckert 2021-11-09  329  		led->subled_info[2].intensity = value[2];
004e74105bb360 Florian Eckert 2021-11-09  330  
004e74105bb360 Florian Eckert 2021-11-09  331  		led->mc_cdev.subled_info = led->subled_info;
004e74105bb360 Florian Eckert 2021-11-09  332  		led->mc_cdev.num_colors = KTD20XX_LED_CHANNELS;
004e74105bb360 Florian Eckert 2021-11-09  333  
004e74105bb360 Florian Eckert 2021-11-09  334  		init_data.fwnode = child;
004e74105bb360 Florian Eckert 2021-11-09  335  
004e74105bb360 Florian Eckert 2021-11-09  336  		led->chip = chip;
004e74105bb360 Florian Eckert 2021-11-09  337  		led_cdev = &led->mc_cdev.led_cdev;
004e74105bb360 Florian Eckert 2021-11-09  338  		led_cdev->brightness_set_blocking = ktd20xx_brightness_set;
004e74105bb360 Florian Eckert 2021-11-09  339  
004e74105bb360 Florian Eckert 2021-11-09  340  		switch (led->index) {
004e74105bb360 Florian Eckert 2021-11-09  341  		case RGB_A1:
004e74105bb360 Florian Eckert 2021-11-09  342  			led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  343  					chip->regmap, kt20xx_a1_select);
004e74105bb360 Florian Eckert 2021-11-09  344  			led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  345  					chip->regmap, kt20xx_a1_enable);
004e74105bb360 Florian Eckert 2021-11-09  346  			break;
004e74105bb360 Florian Eckert 2021-11-09  347  		case RGB_A2:
004e74105bb360 Florian Eckert 2021-11-09  348  			led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  349  					chip->regmap, kt20xx_a2_select);
004e74105bb360 Florian Eckert 2021-11-09  350  			led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  351  					chip->regmap, kt20xx_a2_enable);
004e74105bb360 Florian Eckert 2021-11-09  352  			break;
004e74105bb360 Florian Eckert 2021-11-09  353  		case RGB_A3:
004e74105bb360 Florian Eckert 2021-11-09  354  			led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  355  					chip->regmap, kt20xx_a3_select);
004e74105bb360 Florian Eckert 2021-11-09  356  			led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  357  					chip->regmap, kt20xx_a3_enable);
004e74105bb360 Florian Eckert 2021-11-09  358  			break;
004e74105bb360 Florian Eckert 2021-11-09  359  		case RGB_A4:
004e74105bb360 Florian Eckert 2021-11-09  360  			led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  361  					chip->regmap, kt20xx_a4_select);
004e74105bb360 Florian Eckert 2021-11-09  362  			led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  363  					chip->regmap, kt20xx_a4_enable);
004e74105bb360 Florian Eckert 2021-11-09  364  			break;
004e74105bb360 Florian Eckert 2021-11-09  365  		case RGB_B1:
004e74105bb360 Florian Eckert 2021-11-09  366  			led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  367  					chip->regmap, kt20xx_b1_select);
004e74105bb360 Florian Eckert 2021-11-09  368  			led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  369  					chip->regmap, kt20xx_b1_enable);
004e74105bb360 Florian Eckert 2021-11-09  370  			break;
004e74105bb360 Florian Eckert 2021-11-09  371  		case RGB_B2:
004e74105bb360 Florian Eckert 2021-11-09  372  			led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  373  					chip->regmap, kt20xx_b2_select);
004e74105bb360 Florian Eckert 2021-11-09  374  			led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  375  					chip->regmap, kt20xx_b2_enable);
004e74105bb360 Florian Eckert 2021-11-09  376  			break;
004e74105bb360 Florian Eckert 2021-11-09  377  		case RGB_B3:
004e74105bb360 Florian Eckert 2021-11-09  378  			led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  379  					chip->regmap, kt20xx_b3_select);
004e74105bb360 Florian Eckert 2021-11-09  380  			led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  381  					chip->regmap, kt20xx_b3_enable);
004e74105bb360 Florian Eckert 2021-11-09  382  			break;
004e74105bb360 Florian Eckert 2021-11-09  383  		case RGB_B4:
004e74105bb360 Florian Eckert 2021-11-09  384  			led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  385  					chip->regmap, kt20xx_b4_select);
004e74105bb360 Florian Eckert 2021-11-09  386  			led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  387  					chip->regmap, kt20xx_b4_enable);
004e74105bb360 Florian Eckert 2021-11-09  388  			break;
004e74105bb360 Florian Eckert 2021-11-09  389  		case RGB_C1:
004e74105bb360 Florian Eckert 2021-11-09  390  			led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  391  					chip->regmap, kt20xx_c1_select);
004e74105bb360 Florian Eckert 2021-11-09  392  			led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  393  					chip->regmap, kt20xx_c1_enable);
004e74105bb360 Florian Eckert 2021-11-09  394  			break;
004e74105bb360 Florian Eckert 2021-11-09  395  		case RGB_C2:
004e74105bb360 Florian Eckert 2021-11-09  396  			led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  397  					chip->regmap, kt20xx_c2_select);
004e74105bb360 Florian Eckert 2021-11-09  398  			led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  399  					chip->regmap, kt20xx_c2_enable);
004e74105bb360 Florian Eckert 2021-11-09  400  			break;
004e74105bb360 Florian Eckert 2021-11-09  401  		case RGB_C3:
004e74105bb360 Florian Eckert 2021-11-09  402  			led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  403  					chip->regmap, kt20xx_c3_select);
004e74105bb360 Florian Eckert 2021-11-09  404  			led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  405  					chip->regmap, kt20xx_c3_enable);
004e74105bb360 Florian Eckert 2021-11-09  406  			break;
004e74105bb360 Florian Eckert 2021-11-09  407  		case RGB_C4:
004e74105bb360 Florian Eckert 2021-11-09  408  			led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  409  					chip->regmap, kt20xx_c4_select);
004e74105bb360 Florian Eckert 2021-11-09  410  			led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09  411  					chip->regmap, kt20xx_c4_enable);
004e74105bb360 Florian Eckert 2021-11-09  412  			break;
004e74105bb360 Florian Eckert 2021-11-09  413  		}
004e74105bb360 Florian Eckert 2021-11-09  414  
004e74105bb360 Florian Eckert 2021-11-09  415  		ret = devm_led_classdev_multicolor_register_ext(&chip->client->dev,
004e74105bb360 Florian Eckert 2021-11-09  416  			&led->mc_cdev,
004e74105bb360 Florian Eckert 2021-11-09  417  			&init_data);
004e74105bb360 Florian Eckert 2021-11-09  418  
004e74105bb360 Florian Eckert 2021-11-09  419  		if (ret) {
004e74105bb360 Florian Eckert 2021-11-09  420  			dev_err(&chip->client->dev, "led register err: %d\n", ret);
004e74105bb360 Florian Eckert 2021-11-09  421  			goto child_out;
004e74105bb360 Florian Eckert 2021-11-09  422  		}
004e74105bb360 Florian Eckert 2021-11-09  423  
004e74105bb360 Florian Eckert 2021-11-09  424  		i++;
004e74105bb360 Florian Eckert 2021-11-09  425  		fwnode_handle_put(child);
004e74105bb360 Florian Eckert 2021-11-09  426  	}
004e74105bb360 Florian Eckert 2021-11-09  427  
004e74105bb360 Florian Eckert 2021-11-09  428  	return 0;
004e74105bb360 Florian Eckert 2021-11-09  429  
004e74105bb360 Florian Eckert 2021-11-09  430  child_out:
004e74105bb360 Florian Eckert 2021-11-09  431  	fwnode_handle_put(child);
004e74105bb360 Florian Eckert 2021-11-09  432  	return ret;
004e74105bb360 Florian Eckert 2021-11-09  433  }
004e74105bb360 Florian Eckert 2021-11-09  434  
004e74105bb360 Florian Eckert 2021-11-09  435  /* Device attribute for color0 register
004e74105bb360 Florian Eckert 2021-11-09  436   *
004e74105bb360 Florian Eckert 2021-11-09  437   * The device attribute colour1 is intended to adjust the colour space.
004e74105bb360 Florian Eckert 2021-11-09  438   * The colour strength can be controlled via the current in 125uA steps.
004e74105bb360 Florian Eckert 2021-11-09  439   * The maximum current for the individual channels is limited to 24mA.
004e74105bb360 Florian Eckert 2021-11-09  440   * To set a new RGB value, 3 values must be passed. This value may not be
004e74105bb360 Florian Eckert 2021-11-09  441   * less than 0 and also not greater than 194. The chip can only process the
004e74105bb360 Florian Eckert 2021-11-09  442   * maximum current of 24mA. This means that any value greater than 194
004e74105bb360 Florian Eckert 2021-11-09  443   * cannot be set.
004e74105bb360 Florian Eckert 2021-11-09  444   */
004e74105bb360 Florian Eckert 2021-11-09  445  static ssize_t current_color0_show(struct device *dev,
004e74105bb360 Florian Eckert 2021-11-09  446  		struct device_attribute *a,
004e74105bb360 Florian Eckert 2021-11-09  447  		char *buf)
004e74105bb360 Florian Eckert 2021-11-09  448  {
004e74105bb360 Florian Eckert 2021-11-09  449  	struct i2c_client *client = to_i2c_client(dev);
004e74105bb360 Florian Eckert 2021-11-09  450  	struct ktd20xx *chip = i2c_get_clientdata(client);
004e74105bb360 Florian Eckert 2021-11-09  451  	unsigned int value;
004e74105bb360 Florian Eckert 2021-11-09  452  	int len = 0;
004e74105bb360 Florian Eckert 2021-11-09  453  
004e74105bb360 Florian Eckert 2021-11-09  454  	mutex_lock(&chip->lock);
004e74105bb360 Florian Eckert 2021-11-09  455  	regmap_read(chip->regmap, KTD20XX_IRED0, &value);
004e74105bb360 Florian Eckert 2021-11-09  456  	len += sprintf(buf + len, "%d", value);
004e74105bb360 Florian Eckert 2021-11-09  457  	len += sprintf(buf + len, " ");
004e74105bb360 Florian Eckert 2021-11-09  458  
004e74105bb360 Florian Eckert 2021-11-09  459  	regmap_read(chip->regmap, KTD20XX_IGRN0, &value);
004e74105bb360 Florian Eckert 2021-11-09  460  	len += sprintf(buf + len, "%d", value);
004e74105bb360 Florian Eckert 2021-11-09  461  	len += sprintf(buf + len, " ");
004e74105bb360 Florian Eckert 2021-11-09  462  
004e74105bb360 Florian Eckert 2021-11-09  463  	regmap_read(chip->regmap, KTD20XX_IBLU0, &value);
004e74105bb360 Florian Eckert 2021-11-09  464  	len += sprintf(buf + len, "%d", value);
004e74105bb360 Florian Eckert 2021-11-09  465  	mutex_unlock(&chip->lock);
004e74105bb360 Florian Eckert 2021-11-09  466  
004e74105bb360 Florian Eckert 2021-11-09  467  	buf[len++] = '\n';
004e74105bb360 Florian Eckert 2021-11-09  468  	return len;
004e74105bb360 Florian Eckert 2021-11-09  469  }
004e74105bb360 Florian Eckert 2021-11-09  470  
004e74105bb360 Florian Eckert 2021-11-09  471  static ssize_t current_color0_store(struct device *dev,
004e74105bb360 Florian Eckert 2021-11-09  472  		struct device_attribute *a,
004e74105bb360 Florian Eckert 2021-11-09  473  		const char *buf, size_t size)
004e74105bb360 Florian Eckert 2021-11-09  474  {
004e74105bb360 Florian Eckert 2021-11-09  475  	struct i2c_client *client = to_i2c_client(dev);
004e74105bb360 Florian Eckert 2021-11-09  476  	struct ktd20xx *chip = i2c_get_clientdata(client);
004e74105bb360 Florian Eckert 2021-11-09  477  	unsigned int value[3];
004e74105bb360 Florian Eckert 2021-11-09  478  	int i;
004e74105bb360 Florian Eckert 2021-11-09  479  	ssize_t ret;
004e74105bb360 Florian Eckert 2021-11-09  480  
004e74105bb360 Florian Eckert 2021-11-09  481  	ret = sscanf(buf, "%u %u %u", &value[0], &value[1], &value[2]);
004e74105bb360 Florian Eckert 2021-11-09  482  	if (ret < 3) {
004e74105bb360 Florian Eckert 2021-11-09  483  		ret = -EINVAL;
004e74105bb360 Florian Eckert 2021-11-09  484  		goto err_out;
004e74105bb360 Florian Eckert 2021-11-09  485  	}
004e74105bb360 Florian Eckert 2021-11-09  486  
004e74105bb360 Florian Eckert 2021-11-09  487  	for (i = 0; i < 3; i++) {
004e74105bb360 Florian Eckert 2021-11-09  488  		if (value[i] > 194) {
004e74105bb360 Florian Eckert 2021-11-09  489  			ret = -EINVAL;
004e74105bb360 Florian Eckert 2021-11-09  490  			goto err_out;
004e74105bb360 Florian Eckert 2021-11-09  491  		}
004e74105bb360 Florian Eckert 2021-11-09 @492  		if (value[i] < 0) {
                                                            ^^^^^^^^^^^^
Impossible

004e74105bb360 Florian Eckert 2021-11-09  493  			ret = -EINVAL;
004e74105bb360 Florian Eckert 2021-11-09  494  			goto err_out;
004e74105bb360 Florian Eckert 2021-11-09  495  		}
004e74105bb360 Florian Eckert 2021-11-09  496  	}
004e74105bb360 Florian Eckert 2021-11-09  497  
004e74105bb360 Florian Eckert 2021-11-09  498  	mutex_lock(&chip->lock);
004e74105bb360 Florian Eckert 2021-11-09  499  	regmap_write(chip->regmap, KTD20XX_IRED0, value[0]);
004e74105bb360 Florian Eckert 2021-11-09  500  	regmap_write(chip->regmap, KTD20XX_IGRN0, value[1]);
004e74105bb360 Florian Eckert 2021-11-09  501  	regmap_write(chip->regmap, KTD20XX_IBLU0, value[2]);
004e74105bb360 Florian Eckert 2021-11-09  502  	mutex_unlock(&chip->lock);
004e74105bb360 Florian Eckert 2021-11-09  503  	return size;
004e74105bb360 Florian Eckert 2021-11-09  504  
004e74105bb360 Florian Eckert 2021-11-09  505  err_out:
004e74105bb360 Florian Eckert 2021-11-09  506  	return ret;
004e74105bb360 Florian Eckert 2021-11-09  507  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux