Skip to content

Commit efb704a

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: Reduce number of pointer dereferences in pwm_device_request()
pwm->chip and pwm->chip->ops are used several times in this function. Introduce local variables for these. There is no semantical change, but with ARCH=arm, allmodconfig and gcc-13 bloat-o-meter reports a slight improvement: add/remove: 1/1 grow/shrink: 1/1 up/down: 8/-36 (-28) Function old new delta pwm_apply_state 476 480 +4 __initcall__kmod_core__307_1092_pwm_debugfs_init4 - 4 +4 __initcall__kmod_core__307_1090_pwm_debugfs_init4 4 - -4 pwm_request_from_chip 628 596 -32 Total: Before=15091, After=15063, chg -0.19% Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent d243221 commit efb704a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/pwm/core.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,24 @@ static struct pwm_chip *pwmchip_find_by_name(const char *name)
5959
static int pwm_device_request(struct pwm_device *pwm, const char *label)
6060
{
6161
int err;
62+
struct pwm_chip *chip = pwm->chip;
63+
const struct pwm_ops *ops = chip->ops;
6264

6365
if (test_bit(PWMF_REQUESTED, &pwm->flags))
6466
return -EBUSY;
6567

66-
if (!try_module_get(pwm->chip->owner))
68+
if (!try_module_get(chip->owner))
6769
return -ENODEV;
6870

69-
if (pwm->chip->ops->request) {
70-
err = pwm->chip->ops->request(pwm->chip, pwm);
71+
if (ops->request) {
72+
err = ops->request(chip, pwm);
7173
if (err) {
72-
module_put(pwm->chip->owner);
74+
module_put(chip->owner);
7375
return err;
7476
}
7577
}
7678

77-
if (pwm->chip->ops->get_state) {
79+
if (ops->get_state) {
7880
/*
7981
* Zero-initialize state because most drivers are unaware of
8082
* .usage_power. The other members of state are supposed to be
@@ -84,7 +86,7 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
8486
*/
8587
struct pwm_state state = { 0, };
8688

87-
err = pwm->chip->ops->get_state(pwm->chip, pwm, &state);
89+
err = ops->get_state(chip, pwm, &state);
8890
trace_pwm_get(pwm, &state, err);
8991

9092
if (!err)

0 commit comments

Comments
 (0)