hwmon: (applesmc) Cache fan positions during register initialization

To support the read_string callback for fan labels in the modern HWMON
API, load and cache the fan position names in smcreg.fan_positions
during register initialization.

Pre-pad fallback labels with four spaces to match the "+ 4" pointer
arithmetic offset used by all fan labels in the read_string callback.

Signed-off-by: Shih-Yuan Lee <fourdollars@debian.org>
Link: https://lore.kernel.org/r/20260711093323.14529-2-fourdollars@debian.org
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
Shih-Yuan Lee
2026-07-11 17:33:21 +08:00
committed by Guenter Roeck
parent 26db273640
commit d33baed3fe

View File

@@ -133,6 +133,7 @@ static struct applesmc_registers {
bool init_complete; /* true when fully initialized */
struct applesmc_entry *cache; /* cached key entries */
const char **index; /* temperature key index */
char fan_positions[10][17]; /* cached fan position labels */
} smcreg = {
.mutex = __MUTEX_INITIALIZER(smcreg.mutex),
};
@@ -566,7 +567,7 @@ static int applesmc_init_smcreg_try(void)
{
struct applesmc_registers *s = &smcreg;
bool left_light_sensor = false, right_light_sensor = false;
unsigned int count;
unsigned int count, i;
u8 tmp[1];
int ret;
@@ -597,6 +598,16 @@ static int applesmc_init_smcreg_try(void)
if (s->fan_count > 10)
s->fan_count = 10;
for (i = 0; i < s->fan_count; i++) {
char newkey[5];
scnprintf(newkey, sizeof(newkey), FAN_ID_FMT, i);
ret = applesmc_read_key(newkey, s->fan_positions[i], 16);
s->fan_positions[i][16] = 0;
if (ret)
scnprintf(s->fan_positions[i], 17, " Fan %d", i);
}
ret = applesmc_get_lower_bound(&s->temp_begin, "T");
if (ret)
return ret;