diff mbox series

[v4,001/115] pwm: Reduce number of pointer dereferences in pwm_device_request()

Message ID e0b5c32bca45e90d47f26f917574ccdce422b5dc.1701860672.git.u.kleine-koenig@pengutronix.de
State Accepted
Delegated to: Uwe Kleine-König
Headers show
Series pwm: Fix lifetime issues for pwm_chips | expand

Commit Message

Uwe Kleine-König Dec. 6, 2023, 11:43 a.m. UTC
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 <u.kleine-koenig@pengutronix.de>
---
Note this patch was already sent individually, find it at
https://lore.kernel.org/linux-pwm/20231130072105.966848-1-u.kleine-koenig@pengutronix.de

 drivers/pwm/core.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index f60b715abe62..eea93ed8a49b 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -59,22 +59,24 @@  static struct pwm_chip *pwmchip_find_by_name(const char *name)
 static int pwm_device_request(struct pwm_device *pwm, const char *label)
 {
 	int err;
+	struct pwm_chip *chip = pwm->chip;
+	const struct pwm_ops *ops = chip->ops;
 
 	if (test_bit(PWMF_REQUESTED, &pwm->flags))
 		return -EBUSY;
 
-	if (!try_module_get(pwm->chip->owner))
+	if (!try_module_get(chip->owner))
 		return -ENODEV;
 
-	if (pwm->chip->ops->request) {
-		err = pwm->chip->ops->request(pwm->chip, pwm);
+	if (ops->request) {
+		err = ops->request(chip, pwm);
 		if (err) {
-			module_put(pwm->chip->owner);
+			module_put(chip->owner);
 			return err;
 		}
 	}
 
-	if (pwm->chip->ops->get_state) {
+	if (ops->get_state) {
 		/*
 		 * Zero-initialize state because most drivers are unaware of
 		 * .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)
 		 */
 		struct pwm_state state = { 0, };
 
-		err = pwm->chip->ops->get_state(pwm->chip, pwm, &state);
+		err = ops->get_state(chip, pwm, &state);
 		trace_pwm_get(pwm, &state, err);
 
 		if (!err)