linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org,
	Thierry Reding <thierry.reding@gmail.com>,
	Lee Jones <lee.jones@linaro.org>,
	kernel@pengutronix.de, Michael Walle <michael@walle.cc>
Subject: [PATCH RESEND for 5.10] pwm: sl28cpld: fix getting driver data in pwm callbacks
Date: Thu,  3 Dec 2020 09:41:42 +0100	[thread overview]
Message-ID: <20201203084142.3810204-1-u.kleine-koenig@pengutronix.de> (raw)

Currently .get_state() and .apply() use dev_get_drvdata() on the struct
device related to the pwm chip. This only works after .probe() called
platform_set_drvdata() which in this driver happens only after
pwmchip_add() and so comes possibly too late.

Instead of setting the driver data earlier use the traditional
container_of approach as this way the driver data is conceptually and
computational nearer.

Fixes: 9db33d221efc ("pwm: Add support for sl28cpld PWM controller")
Tested-by: Michael Walle <michael@walle.cc>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello Linus,

Thierry (who usually sends PWM patches to you) didn't react to this
patch sent to the pwm Mailinglist last week
(https://lore.kernel.org/r/20201124212432.3117322-1-u.kleine-koenig@pengutronix.de)
yet.

Given v5.10 isn't far away any more and I don't know when Thierry will
take a look and act, I'm sending this directly to you. The affected
driver was new in 5.10-rc1 and at least once the unpatched driver
created an oops:

	https://lavalab.kontron.com/scheduler/job/108#L950

Michael Walle who tested this patch is the original author of the
driver. IMHO it would be good to have this fixed before 5.10.

If you prefer a pull request, I can setup something (but I don't have
access to Thierry's tree, so it will be for a repository that's new to
you).

Best regards
Uwe

 drivers/pwm/pwm-sl28cpld.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/pwm/pwm-sl28cpld.c b/drivers/pwm/pwm-sl28cpld.c
index 5046b6b7fd35..b4c651fc749c 100644
--- a/drivers/pwm/pwm-sl28cpld.c
+++ b/drivers/pwm/pwm-sl28cpld.c
@@ -84,12 +84,14 @@ struct sl28cpld_pwm {
 	struct regmap *regmap;
 	u32 offset;
 };
+#define sl28cpld_pwm_from_chip(_chip) \
+	container_of(_chip, struct sl28cpld_pwm, pwm_chip)
 
 static void sl28cpld_pwm_get_state(struct pwm_chip *chip,
 				   struct pwm_device *pwm,
 				   struct pwm_state *state)
 {
-	struct sl28cpld_pwm *priv = dev_get_drvdata(chip->dev);
+	struct sl28cpld_pwm *priv = sl28cpld_pwm_from_chip(chip);
 	unsigned int reg;
 	int prescaler;
 
@@ -118,7 +120,7 @@ static void sl28cpld_pwm_get_state(struct pwm_chip *chip,
 static int sl28cpld_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 			      const struct pwm_state *state)
 {
-	struct sl28cpld_pwm *priv = dev_get_drvdata(chip->dev);
+	struct sl28cpld_pwm *priv = sl28cpld_pwm_from_chip(chip);
 	unsigned int cycle, prescaler;
 	bool write_duty_cycle_first;
 	int ret;
-- 
2.29.2


             reply	other threads:[~2020-12-03  8:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03  8:41 Uwe Kleine-König [this message]
2020-12-04 12:41 ` Thierry Reding
2020-12-04 13:24   ` Lee Jones
2020-12-04 14:03     ` Uwe Kleine-König
2020-12-04 13:51   ` Uwe Kleine-König
2020-12-04 16:08     ` Thierry Reding
2020-12-04 20:06       ` Uwe Kleine-König

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=20201203084142.3810204-1-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=kernel@pengutronix.de \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=michael@walle.cc \
    --cc=thierry.reding@gmail.com \
    --cc=torvalds@linux-foundation.org \
    --subject='Re: [PATCH RESEND for 5.10] pwm: sl28cpld: fix getting driver data in pwm callbacks' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).