diff options
author | Geert Uytterhoeven <geert+renesas@glider.be> | 2014-08-28 05:03:14 -0400 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2014-08-29 04:18:19 -0400 |
commit | 70145f87139fbc43b726f873813cd91dce371899 (patch) | |
tree | ad2aea1d515738ba8af8755afbe33e0b88a7060c /drivers/pwm | |
parent | 7264354c0cb8c04bd4a85d24e5d57a0e2417c2fb (diff) |
pwm: Fix uninitialized warnings in pwm_get()
With some versions of gcc (e.g. 4.1.2):
drivers/pwm/core.c: In function ‘pwm_get’:
drivers/pwm/core.c:610: warning: ‘polarity’ may be used uninitialized in this function
drivers/pwm/core.c:609: warning: ‘period’ may be used uninitialized in this function
While these are false positives, we can get rid of them by refactoring
the code to store a pointer to the best match, as suggested before by
Thierry Reding. This does require moving the mutex_unlock() down.
Fixes: d717ea73e36dd565 ("pwm: Fix period and polarity in pwm_get() for non-perfect matches")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm')
-rw-r--r-- | drivers/pwm/core.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 8c748b17f416..966497d10c6e 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c | |||
@@ -602,12 +602,9 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id) | |||
602 | struct pwm_device *pwm = ERR_PTR(-EPROBE_DEFER); | 602 | struct pwm_device *pwm = ERR_PTR(-EPROBE_DEFER); |
603 | const char *dev_id = dev ? dev_name(dev) : NULL; | 603 | const char *dev_id = dev ? dev_name(dev) : NULL; |
604 | struct pwm_chip *chip = NULL; | 604 | struct pwm_chip *chip = NULL; |
605 | unsigned int index = 0; | ||
606 | unsigned int best = 0; | 605 | unsigned int best = 0; |
607 | struct pwm_lookup *p; | 606 | struct pwm_lookup *p, *chosen = NULL; |
608 | unsigned int match; | 607 | unsigned int match; |
609 | unsigned int period; | ||
610 | enum pwm_polarity polarity; | ||
611 | 608 | ||
612 | /* look up via DT first */ | 609 | /* look up via DT first */ |
613 | if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) | 610 | if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) |
@@ -653,10 +650,7 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id) | |||
653 | } | 650 | } |
654 | 651 | ||
655 | if (match > best) { | 652 | if (match > best) { |
656 | chip = pwmchip_find_by_name(p->provider); | 653 | chosen = p; |
657 | index = p->index; | ||
658 | period = p->period; | ||
659 | polarity = p->polarity; | ||
660 | 654 | ||
661 | if (match != 3) | 655 | if (match != 3) |
662 | best = match; | 656 | best = match; |
@@ -665,17 +659,22 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id) | |||
665 | } | 659 | } |
666 | } | 660 | } |
667 | 661 | ||
668 | mutex_unlock(&pwm_lookup_lock); | 662 | if (!chosen) |
663 | goto out; | ||
669 | 664 | ||
670 | if (chip) | 665 | chip = pwmchip_find_by_name(chosen->provider); |
671 | pwm = pwm_request_from_chip(chip, index, con_id ?: dev_id); | 666 | if (!chip) |
672 | if (IS_ERR(pwm)) | 667 | goto out; |
673 | return pwm; | ||
674 | 668 | ||
675 | pwm_set_period(pwm, period); | 669 | pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id); |
676 | pwm_set_polarity(pwm, polarity); | 670 | if (IS_ERR(pwm)) |
671 | goto out; | ||
677 | 672 | ||
673 | pwm_set_period(pwm, chosen->period); | ||
674 | pwm_set_polarity(pwm, chosen->polarity); | ||
678 | 675 | ||
676 | out: | ||
677 | mutex_unlock(&pwm_lookup_lock); | ||
679 | return pwm; | 678 | return pwm; |
680 | } | 679 | } |
681 | EXPORT_SYMBOL_GPL(pwm_get); | 680 | EXPORT_SYMBOL_GPL(pwm_get); |