Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: hwmon: prepare for power supply extensions

The upcoming extension API will add properties which are not part of the
the power_supply_desc.
Use power_supply_has_property() so the properties from extensions are
also checked.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Reviewed-by: Armin Wolf <W_Armin@gmx.de>
Link: https://lore.kernel.org/r/20241111-power-supply-extensions-v4-4-7240144daa8e@weissschuh.net
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Thomas Weißschuh and committed by
Sebastian Reichel
39bb32f0 aa40f37d

+23 -25
+23 -25
drivers/power/supply/power_supply_hwmon.c
··· 349 349 .info = power_supply_hwmon_info, 350 350 }; 351 351 352 + static const enum power_supply_property power_supply_hwmon_props[] = { 353 + POWER_SUPPLY_PROP_CURRENT_AVG, 354 + POWER_SUPPLY_PROP_CURRENT_MAX, 355 + POWER_SUPPLY_PROP_CURRENT_NOW, 356 + POWER_SUPPLY_PROP_POWER_AVG, 357 + POWER_SUPPLY_PROP_POWER_NOW, 358 + POWER_SUPPLY_PROP_TEMP, 359 + POWER_SUPPLY_PROP_TEMP_MAX, 360 + POWER_SUPPLY_PROP_TEMP_MIN, 361 + POWER_SUPPLY_PROP_TEMP_ALERT_MIN, 362 + POWER_SUPPLY_PROP_TEMP_ALERT_MAX, 363 + POWER_SUPPLY_PROP_TEMP_AMBIENT, 364 + POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN, 365 + POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX, 366 + POWER_SUPPLY_PROP_VOLTAGE_AVG, 367 + POWER_SUPPLY_PROP_VOLTAGE_MIN, 368 + POWER_SUPPLY_PROP_VOLTAGE_MAX, 369 + POWER_SUPPLY_PROP_VOLTAGE_NOW, 370 + }; 371 + 352 372 int power_supply_add_hwmon_sysfs(struct power_supply *psy) 353 373 { 354 - const struct power_supply_desc *desc = psy->desc; 355 374 struct power_supply_hwmon *psyhw; 356 375 struct device *dev = &psy->dev; 357 376 struct device *hwmon; ··· 396 377 goto error; 397 378 } 398 379 399 - for (i = 0; i < desc->num_properties; i++) { 400 - const enum power_supply_property prop = desc->properties[i]; 380 + for (i = 0; i < ARRAY_SIZE(power_supply_hwmon_props); i++) { 381 + const enum power_supply_property prop = power_supply_hwmon_props[i]; 401 382 402 - switch (prop) { 403 - case POWER_SUPPLY_PROP_CURRENT_AVG: 404 - case POWER_SUPPLY_PROP_CURRENT_MAX: 405 - case POWER_SUPPLY_PROP_CURRENT_NOW: 406 - case POWER_SUPPLY_PROP_POWER_AVG: 407 - case POWER_SUPPLY_PROP_POWER_NOW: 408 - case POWER_SUPPLY_PROP_TEMP: 409 - case POWER_SUPPLY_PROP_TEMP_MAX: 410 - case POWER_SUPPLY_PROP_TEMP_MIN: 411 - case POWER_SUPPLY_PROP_TEMP_ALERT_MIN: 412 - case POWER_SUPPLY_PROP_TEMP_ALERT_MAX: 413 - case POWER_SUPPLY_PROP_TEMP_AMBIENT: 414 - case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN: 415 - case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX: 416 - case POWER_SUPPLY_PROP_VOLTAGE_AVG: 417 - case POWER_SUPPLY_PROP_VOLTAGE_MIN: 418 - case POWER_SUPPLY_PROP_VOLTAGE_MAX: 419 - case POWER_SUPPLY_PROP_VOLTAGE_NOW: 383 + if (power_supply_has_property(psy, prop)) 420 384 set_bit(prop, psyhw->props); 421 - break; 422 - default: 423 - break; 424 - } 425 385 } 426 386 427 387 name = psy->desc->name;