* [PATCH][next] power: supply: 88pm860x: make fsm_state array static const, simplify usage
@ 2025-08-07 12:13 Colin Ian King
2025-09-06 21:45 ` Sebastian Reichel
0 siblings, 1 reply; 2+ messages in thread
From: Colin Ian King @ 2025-08-07 12:13 UTC (permalink / raw)
To: Sebastian Reichel, linux-pm; +Cc: kernel-janitors, linux-kernel
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>
---
drivers/power/supply/88pm860x_charger.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/power/supply/88pm860x_charger.c b/drivers/power/supply/88pm860x_charger.c
index 2b9fcb7e71d7..8d99c6ff72ed 100644
--- a/drivers/power/supply/88pm860x_charger.c
+++ b/drivers/power/supply/88pm860x_charger.c
@@ -284,8 +284,8 @@ static int set_charging_fsm(struct pm860x_charger_info *info)
{
struct power_supply *psy;
union power_supply_propval data;
- unsigned char fsm_state[][16] = { "init", "discharge", "precharge",
- "fastcharge",
+ static const unsigned char fsm_state[][16] = {
+ "init", "discharge", "precharge", "fastcharge",
};
int ret;
int vbatt;
@@ -313,7 +313,7 @@ static int set_charging_fsm(struct pm860x_charger_info *info)
dev_dbg(info->dev, "Entering FSM:%s, Charger:%s, Battery:%s, "
"Allowed:%d\n",
- &fsm_state[info->state][0],
+ fsm_state[info->state],
(info->online) ? "online" : "N/A",
(info->present) ? "present" : "N/A", info->allowed);
dev_dbg(info->dev, "set_charging_fsm:vbatt:%d(mV)\n", vbatt);
@@ -385,7 +385,7 @@ static int set_charging_fsm(struct pm860x_charger_info *info)
}
dev_dbg(info->dev,
"Out FSM:%s, Charger:%s, Battery:%s, Allowed:%d\n",
- &fsm_state[info->state][0],
+ fsm_state[info->state],
(info->online) ? "online" : "N/A",
(info->present) ? "present" : "N/A", info->allowed);
mutex_unlock(&info->lock);
--
2.50.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH][next] power: supply: 88pm860x: make fsm_state array static const, simplify usage
2025-08-07 12:13 [PATCH][next] power: supply: 88pm860x: make fsm_state array static const, simplify usage Colin Ian King
@ 2025-09-06 21:45 ` Sebastian Reichel
0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2025-09-06 21:45 UTC (permalink / raw)
To: Sebastian Reichel, linux-pm, Colin Ian King; +Cc: kernel-janitors, linux-kernel
On Thu, 07 Aug 2025 13:13:49 +0100, Colin Ian King wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] power: supply: 88pm860x: make fsm_state array static const, simplify usage
commit: cb03556acf83b235dfb2e9f86e14f5e5b8a5f1e7
Best regards,
--
Sebastian Reichel <sebastian.reichel@collabora.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-06 21:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-07 12:13 [PATCH][next] power: supply: 88pm860x: make fsm_state array static const, simplify usage Colin Ian King
2025-09-06 21:45 ` Sebastian Reichel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®