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

power: supply: 88pm860x: make fsm_state array static const, simplify usage

Don't populate the read-only array fsm_state on the stack at run time,
instead make it static const, this reduces the object code size as
the data is placed on the data segment and this removes the need to
have code to set the array up on each call.

Note that making the size of the strings to a more optimal 11 bytes long
does not seem to reduce the overall size. Making the array an array of
pointers to the strings increases the code size due to the dereferencing
overhead.

Simplify the array access with &fsm_state[info->state][0] with the simpler
expression fsm_state[info->state] to clean up the code.

Original:
text data bss dec hex filename
22884 8272 64 31220 79f4 drivers/power/supply/88pm860x_charger.o

Patched:
text data bss dec hex filename
22695 8368 64 31127 7997 drivers/power/supply/88pm860x_charger.o

Difference:
text data bss dec
-189 +96 0 -93

Reduction of 93 bytes total.

gcc version 14.2.0 (x86-64)

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Colin Ian King and committed by
Sebastian Reichel
cb03556a 32f350d5

+4 -4
+4 -4
drivers/power/supply/88pm860x_charger.c
··· 284 284 { 285 285 struct power_supply *psy; 286 286 union power_supply_propval data; 287 - unsigned char fsm_state[][16] = { "init", "discharge", "precharge", 288 - "fastcharge", 287 + static const unsigned char fsm_state[][16] = { 288 + "init", "discharge", "precharge", "fastcharge", 289 289 }; 290 290 int ret; 291 291 int vbatt; ··· 313 313 314 314 dev_dbg(info->dev, "Entering FSM:%s, Charger:%s, Battery:%s, " 315 315 "Allowed:%d\n", 316 - &fsm_state[info->state][0], 316 + fsm_state[info->state], 317 317 (info->online) ? "online" : "N/A", 318 318 (info->present) ? "present" : "N/A", info->allowed); 319 319 dev_dbg(info->dev, "set_charging_fsm:vbatt:%d(mV)\n", vbatt); ··· 385 385 } 386 386 dev_dbg(info->dev, 387 387 "Out FSM:%s, Charger:%s, Battery:%s, Allowed:%d\n", 388 - &fsm_state[info->state][0], 388 + fsm_state[info->state], 389 389 (info->online) ? "online" : "N/A", 390 390 (info->present) ? "present" : "N/A", info->allowed); 391 391 mutex_unlock(&info->lock);