]> git.itanic.dy.fi Git - linux-stable/commitdiff
pwm: Narrow scope of struct pwm_device pointer
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Thu, 23 Nov 2023 09:56:20 +0000 (10:56 +0100)
committerThierry Reding <thierry.reding@gmail.com>
Wed, 20 Dec 2023 15:04:13 +0000 (16:04 +0100)
In the expression determining the size of the allocation for chip->pwms
it's more natural to use sizeof(*chip->pwms) than sizeof(*pwm). With
that changed, the variable pwm is only used in a for loop and its scope
can be reduced accordingly.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/core.c

index fb36b3d559a729d93d5575c4c2a87861439325d7..b0e50ca9398a70a743259075ef15adfbdfd6c8dc 100644 (file)
@@ -208,7 +208,6 @@ static bool pwm_ops_check(const struct pwm_chip *chip)
  */
 int __pwmchip_add(struct pwm_chip *chip, struct module *owner)
 {
-       struct pwm_device *pwm;
        unsigned int i;
        int ret;
 
@@ -220,7 +219,7 @@ int __pwmchip_add(struct pwm_chip *chip, struct module *owner)
 
        chip->owner = owner;
 
-       chip->pwms = kcalloc(chip->npwm, sizeof(*pwm), GFP_KERNEL);
+       chip->pwms = kcalloc(chip->npwm, sizeof(*chip->pwms), GFP_KERNEL);
        if (!chip->pwms)
                return -ENOMEM;
 
@@ -236,7 +235,7 @@ int __pwmchip_add(struct pwm_chip *chip, struct module *owner)
        chip->id = ret;
 
        for (i = 0; i < chip->npwm; i++) {
-               pwm = &chip->pwms[i];
+               struct pwm_device *pwm = &chip->pwms[i];
 
                pwm->chip = chip;
                pwm->hwpwm = i;