mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ralph Hempel <rhempel@hempeldesigngroup.com>
To: s.hauer@pengutronix.de
Cc: linux-kernel@vger.kernel.org
Subject: pwm_get() in core.c does not save best match before setting period and polarity
Date: Tue, 09 Sep 2014 08:15:30 -0400	[thread overview]
Message-ID: <540EEF62.7000307@hempeldesigngroup.com> (raw)

The PWM core does not appear to respect the settings in the pwm_lookup 
table in the ev3dev projects implementation of a board file. Root cause 
is that pwm_get() does not save the pwm_lookup entry for the  best 
matching device, and therefore ends up using period and polarity from a 
pointer that's past the end of the table.

These values are often 0, which translates to PWM_POLARITY_NORMAL, but 
it can be anything really...

First patch ever submitted - fun times finding this one - the bug was in 
the last place I looked
-----------------------------------------------------------------------

Make the match loop save the best match so that period and polarity can 
be set correctly

-----------------------------------------------------------------------


diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 4b66bf0..f244e2c 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -605,6 +605,7 @@ struct pwm_device *pwm_get(struct device *dev, const 
char *con_id)
         unsigned int index = 0;
         unsigned int best = 0;
         struct pwm_lookup *p;
+       struct pwm_lookup *pl = NULL;
         unsigned int match;

         /* look up via DT first */
@@ -651,6 +652,7 @@ struct pwm_device *pwm_get(struct device *dev, const 
char *con_id)
                 }

                 if (match > best) {
+                       pl = p;
                         chip = pwmchip_find_by_name(p->provider);
                         index = p->index;

@@ -668,8 +670,8 @@ struct pwm_device *pwm_get(struct device *dev, const 
char *con_id)
         if (IS_ERR(pwm))
                 return pwm;

-       pwm_set_period(pwm, p->period);
-       pwm_set_polarity(pwm, p->polarity);
+       pwm_set_period(pwm, pl->period);
+       pwm_set_polarity(pwm, pl->polarity);


         return pwm;

Ralph Hempel (rhempel@hempeldesigngroup.com)

                 reply	other threads:[~2014-09-09 12:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=540EEF62.7000307@hempeldesigngroup.com \
    --to=rhempel@hempeldesigngroup.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome