mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
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: d717ea73e3
("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>
This commit is contained in:
parent
7264354c0c
commit
70145f8713
1 changed files with 14 additions and 15 deletions
|
@ -602,12 +602,9 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
|
||||||
struct pwm_device *pwm = ERR_PTR(-EPROBE_DEFER);
|
struct pwm_device *pwm = ERR_PTR(-EPROBE_DEFER);
|
||||||
const char *dev_id = dev ? dev_name(dev) : NULL;
|
const char *dev_id = dev ? dev_name(dev) : NULL;
|
||||||
struct pwm_chip *chip = NULL;
|
struct pwm_chip *chip = NULL;
|
||||||
unsigned int index = 0;
|
|
||||||
unsigned int best = 0;
|
unsigned int best = 0;
|
||||||
struct pwm_lookup *p;
|
struct pwm_lookup *p, *chosen = NULL;
|
||||||
unsigned int match;
|
unsigned int match;
|
||||||
unsigned int period;
|
|
||||||
enum pwm_polarity polarity;
|
|
||||||
|
|
||||||
/* look up via DT first */
|
/* look up via DT first */
|
||||||
if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node)
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match > best) {
|
if (match > best) {
|
||||||
chip = pwmchip_find_by_name(p->provider);
|
chosen = p;
|
||||||
index = p->index;
|
|
||||||
period = p->period;
|
|
||||||
polarity = p->polarity;
|
|
||||||
|
|
||||||
if (match != 3)
|
if (match != 3)
|
||||||
best = match;
|
best = match;
|
||||||
|
@ -665,17 +659,22 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&pwm_lookup_lock);
|
if (!chosen)
|
||||||
|
goto out;
|
||||||
|
|
||||||
if (chip)
|
chip = pwmchip_find_by_name(chosen->provider);
|
||||||
pwm = pwm_request_from_chip(chip, index, con_id ?: dev_id);
|
if (!chip)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id);
|
||||||
if (IS_ERR(pwm))
|
if (IS_ERR(pwm))
|
||||||
return pwm;
|
goto out;
|
||||||
|
|
||||||
pwm_set_period(pwm, period);
|
|
||||||
pwm_set_polarity(pwm, polarity);
|
|
||||||
|
|
||||||
|
pwm_set_period(pwm, chosen->period);
|
||||||
|
pwm_set_polarity(pwm, chosen->polarity);
|
||||||
|
|
||||||
|
out:
|
||||||
|
mutex_unlock(&pwm_lookup_lock);
|
||||||
return pwm;
|
return pwm;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(pwm_get);
|
EXPORT_SYMBOL_GPL(pwm_get);
|
||||||
|
|
Loading…
Add table
Reference in a new issue