Skip to content

Commit

Permalink
pwm: Narrow scope of struct pwm_device pointer
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Uwe Kleine-König authored and Thierry Reding committed Dec 20, 2023
1 parent 1c9a2ad commit b0445a1
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/pwm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit b0445a1

Please sign in to comment.