All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] pwm: clear chip_data in pwm_put
@ 2019-03-25  9:49 Uwe Kleine-König
  2019-03-25  9:49 ` [PATCH 2/2] pwm: samsung: don't uses devm-functions in .request Uwe Kleine-König
  2019-05-09 15:21 ` [PATCH 1/2] pwm: clear chip_data in pwm_put Thierry Reding
  0 siblings, 2 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2019-03-25  9:49 UTC (permalink / raw)
  To: Thierry Reding; +Cc: linux-pwm, kernel

After a PWM is disposed by its user the per chip data becomes invalid.
Clear the data in common code instead of the device drivers to get
consistent behaviour. Before this patch only three of nine drivers cleaned
up here.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/pwm/core.c        | 1 +
 drivers/pwm/pwm-berlin.c  | 1 -
 drivers/pwm/pwm-pca9685.c | 1 -
 drivers/pwm/pwm-samsung.c | 1 -
 4 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 1a871cf8f7ee..8b247554bf50 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -881,6 +881,7 @@ void pwm_put(struct pwm_device *pwm)
 	if (pwm->chip->ops->free)
 		pwm->chip->ops->free(pwm->chip, pwm);
 
+	pwm_set_chip_data(pwm, NULL);
 	pwm->label = NULL;
 
 	module_put(pwm->chip->ops->owner);
diff --git a/drivers/pwm/pwm-berlin.c b/drivers/pwm/pwm-berlin.c
index 7c8d6a168ceb..b91c477cc84b 100644
--- a/drivers/pwm/pwm-berlin.c
+++ b/drivers/pwm/pwm-berlin.c
@@ -84,7 +84,6 @@ static void berlin_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
 {
 	struct berlin_pwm_channel *channel = pwm_get_chip_data(pwm);
 
-	pwm_set_chip_data(pwm, NULL);
 	kfree(channel);
 }
 
diff --git a/drivers/pwm/pwm-pca9685.c b/drivers/pwm/pwm-pca9685.c
index a7eaf962a95b..567f5e2771c4 100644
--- a/drivers/pwm/pwm-pca9685.c
+++ b/drivers/pwm/pwm-pca9685.c
@@ -176,7 +176,6 @@ static void pca9685_pwm_gpio_free(struct gpio_chip *gpio, unsigned int offset)
 	pm_runtime_put(pca->chip.dev);
 	mutex_lock(&pca->lock);
 	pwm = &pca->chip.pwms[offset];
-	pwm_set_chip_data(pwm, NULL);
 	mutex_unlock(&pca->lock);
 }
 
diff --git a/drivers/pwm/pwm-samsung.c b/drivers/pwm/pwm-samsung.c
index 062f2cfc45ec..3762432dd6a7 100644
--- a/drivers/pwm/pwm-samsung.c
+++ b/drivers/pwm/pwm-samsung.c
@@ -238,7 +238,6 @@ static int pwm_samsung_request(struct pwm_chip *chip, struct pwm_device *pwm)
 static void pwm_samsung_free(struct pwm_chip *chip, struct pwm_device *pwm)
 {
 	devm_kfree(chip->dev, pwm_get_chip_data(pwm));
-	pwm_set_chip_data(pwm, NULL);
 }
 
 static int pwm_samsung_enable(struct pwm_chip *chip, struct pwm_device *pwm)
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] pwm: samsung: don't uses devm-functions in .request
  2019-03-25  9:49 [PATCH 1/2] pwm: clear chip_data in pwm_put Uwe Kleine-König
@ 2019-03-25  9:49 ` Uwe Kleine-König
  2019-05-09 15:22   ` Thierry Reding
  2019-05-09 15:21 ` [PATCH 1/2] pwm: clear chip_data in pwm_put Thierry Reding
  1 sibling, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2019-03-25  9:49 UTC (permalink / raw)
  To: Thierry Reding; +Cc: linux-pwm, kernel

A call to .request() is always paired by a call to .free() before a given
device is disposed. So the simplification that usually is possible when
using devm-functions cannot be used here. So use plain kzalloc() and
kfree() for improved runtime behaviour and reduced memory footprint.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/pwm/pwm-samsung.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pwm/pwm-samsung.c b/drivers/pwm/pwm-samsung.c
index 3762432dd6a7..145a1c1ecf11 100644
--- a/drivers/pwm/pwm-samsung.c
+++ b/drivers/pwm/pwm-samsung.c
@@ -226,7 +226,7 @@ static int pwm_samsung_request(struct pwm_chip *chip, struct pwm_device *pwm)
 		return -EINVAL;
 	}
 
-	our_chan = devm_kzalloc(chip->dev, sizeof(*our_chan), GFP_KERNEL);
+	our_chan = kzalloc(chip->dev, sizeof(*our_chan), GFP_KERNEL);
 	if (!our_chan)
 		return -ENOMEM;
 
@@ -237,7 +237,7 @@ static int pwm_samsung_request(struct pwm_chip *chip, struct pwm_device *pwm)
 
 static void pwm_samsung_free(struct pwm_chip *chip, struct pwm_device *pwm)
 {
-	devm_kfree(chip->dev, pwm_get_chip_data(pwm));
+	kfree(chip->dev, pwm_get_chip_data(pwm));
 }
 
 static int pwm_samsung_enable(struct pwm_chip *chip, struct pwm_device *pwm)
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] pwm: clear chip_data in pwm_put
  2019-03-25  9:49 [PATCH 1/2] pwm: clear chip_data in pwm_put Uwe Kleine-König
  2019-03-25  9:49 ` [PATCH 2/2] pwm: samsung: don't uses devm-functions in .request Uwe Kleine-König
@ 2019-05-09 15:21 ` Thierry Reding
  1 sibling, 0 replies; 5+ messages in thread
From: Thierry Reding @ 2019-05-09 15:21 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: linux-pwm, kernel

[-- Attachment #1: Type: text/plain, Size: 609 bytes --]

On Mon, Mar 25, 2019 at 10:49:33AM +0100, Uwe Kleine-König wrote:
> After a PWM is disposed by its user the per chip data becomes invalid.
> Clear the data in common code instead of the device drivers to get
> consistent behaviour. Before this patch only three of nine drivers cleaned
> up here.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/pwm/core.c        | 1 +
>  drivers/pwm/pwm-berlin.c  | 1 -
>  drivers/pwm/pwm-pca9685.c | 1 -
>  drivers/pwm/pwm-samsung.c | 1 -
>  4 files changed, 1 insertion(+), 3 deletions(-)

Applied, thanks.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] pwm: samsung: don't uses devm-functions in .request
  2019-03-25  9:49 ` [PATCH 2/2] pwm: samsung: don't uses devm-functions in .request Uwe Kleine-König
@ 2019-05-09 15:22   ` Thierry Reding
  2019-05-09 19:02     ` Uwe Kleine-König
  0 siblings, 1 reply; 5+ messages in thread
From: Thierry Reding @ 2019-05-09 15:22 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: linux-pwm, kernel

[-- Attachment #1: Type: text/plain, Size: 645 bytes --]

On Mon, Mar 25, 2019 at 10:49:34AM +0100, Uwe Kleine-König wrote:
> A call to .request() is always paired by a call to .free() before a given
> device is disposed. So the simplification that usually is possible when
> using devm-functions cannot be used here. So use plain kzalloc() and
> kfree() for improved runtime behaviour and reduced memory footprint.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/pwm/pwm-samsung.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, and dropped the chip->dev parameter while at it to make this
actually build.

Thanks,
Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] pwm: samsung: don't uses devm-functions in .request
  2019-05-09 15:22   ` Thierry Reding
@ 2019-05-09 19:02     ` Uwe Kleine-König
  0 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2019-05-09 19:02 UTC (permalink / raw)
  To: Thierry Reding; +Cc: linux-pwm, kernel

On Thu, May 09, 2019 at 05:22:14PM +0200, Thierry Reding wrote:
> On Mon, Mar 25, 2019 at 10:49:34AM +0100, Uwe Kleine-König wrote:
> > A call to .request() is always paired by a call to .free() before a given
> > device is disposed. So the simplification that usually is possible when
> > using devm-functions cannot be used here. So use plain kzalloc() and
> > kfree() for improved runtime behaviour and reduced memory footprint.
> > 
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > ---
> >  drivers/pwm/pwm-samsung.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> Applied, and dropped the chip->dev parameter while at it to make this
> actually build.

Huh, thanks for that. I'm surprised I didn't notice that myself.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-05-09 19:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-25  9:49 [PATCH 1/2] pwm: clear chip_data in pwm_put Uwe Kleine-König
2019-03-25  9:49 ` [PATCH 2/2] pwm: samsung: don't uses devm-functions in .request Uwe Kleine-König
2019-05-09 15:22   ` Thierry Reding
2019-05-09 19:02     ` Uwe Kleine-König
2019-05-09 15:21 ` [PATCH 1/2] pwm: clear chip_data in pwm_put Thierry Reding

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.