linux-samsung-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v1] Revert "pwm: Clear chip_data in pwm_put()"
@ 2023-03-07 21:00 George Stark
  2023-03-07 21:27 ` Uwe Kleine-König
  0 siblings, 1 reply; 4+ messages in thread
From: George Stark @ 2023-03-07 21:00 UTC (permalink / raw)
  To: thierry.reding, u.kleine-koenig, krzysztof.kozlowski, alim.akhtar
  Cc: linux-pwm, linux-kernel, linux-arm-kernel, linux-samsung-soc,
	kernel, gnstark, George Stark

From: George Stark <GNStark@sberdevices.ru>

This reverts commit e926b12c611c2095c7976e2ed31753ad6eb5ff1a.

There're several issues with the original change:

- it breaks generic semantics of set_driver_data-like routines that
only client code controls lifetime of it's own data.

- it breaks pwm-sti.c driver: pwm_set_chip_data is used only in probe stage
then pwm_get_chip_data used in capture callback

Change-Id: I5787c6b4c520d4a0997567c416b26fa4e0806b94
Signed-off-by: George Stark <GNStark@sberdevices.ru>
---
 drivers/pwm/core.c        | 1 -
 drivers/pwm/pwm-berlin.c  | 1 +
 drivers/pwm/pwm-samsung.c | 1 +
 3 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index e01147f66e15..3bc644cc16fe 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -1036,7 +1036,6 @@ 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 e157273fd2f7..953cc2bba314 100644
--- a/drivers/pwm/pwm-berlin.c
+++ b/drivers/pwm/pwm-berlin.c
@@ -84,6 +84,7 @@ 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-samsung.c b/drivers/pwm/pwm-samsung.c
index 9c5b4f515641..7e5dbdd6fc64 100644
--- a/drivers/pwm/pwm-samsung.c
+++ b/drivers/pwm/pwm-samsung.c
@@ -249,6 +249,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)
 {
 	kfree(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.38.4


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

* Re: [RFC PATCH v1] Revert "pwm: Clear chip_data in pwm_put()"
  2023-03-07 21:00 [RFC PATCH v1] Revert "pwm: Clear chip_data in pwm_put()" George Stark
@ 2023-03-07 21:27 ` Uwe Kleine-König
  2023-03-08 12:16   ` George Stark
  0 siblings, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2023-03-07 21:27 UTC (permalink / raw)
  To: George Stark
  Cc: thierry.reding, krzysztof.kozlowski, alim.akhtar, linux-pwm,
	linux-kernel, linux-arm-kernel, linux-samsung-soc, kernel

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

Hello George,

On Wed, Mar 08, 2023 at 12:00:14AM +0300, George Stark wrote:
> From: George Stark <GNStark@sberdevices.ru>
> 
> This reverts commit e926b12c611c2095c7976e2ed31753ad6eb5ff1a.
> 
> There're several issues with the original change:
> 
> - it breaks generic semantics of set_driver_data-like routines that
> only client code controls lifetime of it's own data.
> 
> - it breaks pwm-sti.c driver: pwm_set_chip_data is used only in probe stage
> then pwm_get_chip_data used in capture callback

pwm-sti is also broken in other regards. pwm_set_chip_data() is only
called after pwmchip_add(). But as soon as pwmchip_add() is called, the
callbacks (e.g. capture) might be called. Then the call to
pwm_set_chip_data() might be too late.

> Change-Id: I5787c6b4c520d4a0997567c416b26fa4e0806b94

Please don't add a Change-Id footer for Linux submissions.

If you ask me, better drop pwm_set_chip_data() completely. It adds no
useful value. It's just a variant of driver data and using both
complicates the driver and probably fragments memory allocations. Also
the sematic of driver data is better known as it's the same for all
subsystems.

Do you use the capture functionality? In my eyes the capture part of the
pwm subsystem is very alien. Only a small subset of the hardware
supports this and the counter framework should be better suited for such
tasks.

Best regards
Uwe

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

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

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

* Re: [RFC PATCH v1] Revert "pwm: Clear chip_data in pwm_put()"
  2023-03-07 21:27 ` Uwe Kleine-König
@ 2023-03-08 12:16   ` George Stark
  2023-03-08 16:52     ` Uwe Kleine-König
  0 siblings, 1 reply; 4+ messages in thread
From: George Stark @ 2023-03-08 12:16 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: thierry.reding, krzysztof.kozlowski, alim.akhtar, linux-pwm,
	linux-kernel, linux-arm-kernel, linux-samsung-soc, kernel

Hello Uwe

On 3/8/23 00:28, Uwe Kleine-König wrote:
> Hello George,
>
> On Wed, Mar 08, 2023 at 12:00:14AM +0300, George Stark wrote:
>> From: George Stark <GNStark@sberdevices.ru>
>>
>> This reverts commit e926b12c611c2095c7976e2ed31753ad6eb5ff1a.
>>
>> There're several issues with the original change:
>>
>> - it breaks generic semantics of set_driver_data-like routines that
>> only client code controls lifetime of it's own data.
>>
>> - it breaks pwm-sti.c driver: pwm_set_chip_data is used only in probe stage
>> then pwm_get_chip_data used in capture callback
> pwm-sti is also broken in other regards. pwm_set_chip_data() is only
> called after pwmchip_add(). But as soon as pwmchip_add() is called, the
> callbacks (e.g. capture) might be called. Then the call to
> pwm_set_chip_data() might be too late.
>
>> Change-Id: I5787c6b4c520d4a0997567c416b26fa4e0806b94
> Please don't add a Change-Id footer for Linux submissions.
missed it somehow. Sorry about that
>
> If you ask me, better drop pwm_set_chip_data() completely. It adds no
> useful value. It's just a variant of driver data and using both
> complicates the driver and probably fragments memory allocations. Also
> the sematic of driver data is better known as it's the same for all
> subsystems.
>
> Do you use the capture functionality? In my eyes the capture part of the
> pwm subsystem is very alien. Only a small subset of the hardware
> supports this and the counter framework should be better suited for such
> tasks.
I don't use pwm-sti driver. I update meson pwm driver for new chips
and when started using pwm_set_chip_data in probe I was very surprised that
my data is lost after sysfs export/unexport calls. Then I found the 
patch and
checked other drivers for similar usecases.
Probably you're right about dropping pwm_set_chip_data.
> Best regards
> Uwe
>
Best regards
George


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

* Re: [RFC PATCH v1] Revert "pwm: Clear chip_data in pwm_put()"
  2023-03-08 12:16   ` George Stark
@ 2023-03-08 16:52     ` Uwe Kleine-König
  0 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2023-03-08 16:52 UTC (permalink / raw)
  To: George Stark
  Cc: thierry.reding, krzysztof.kozlowski, alim.akhtar, linux-pwm,
	linux-kernel, linux-arm-kernel, linux-samsung-soc, kernel

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

Hello George,

On Wed, Mar 08, 2023 at 12:16:00PM +0000, George Stark wrote:
> On 3/8/23 00:28, Uwe Kleine-König wrote:
> > If you ask me, better drop pwm_set_chip_data() completely. It adds no
> > useful value. It's just a variant of driver data and using both
> > complicates the driver and probably fragments memory allocations. Also
> > the sematic of driver data is better known as it's the same for all
> > subsystems.
> >
> > Do you use the capture functionality? In my eyes the capture part of the
> > pwm subsystem is very alien. Only a small subset of the hardware
> > supports this and the counter framework should be better suited for such
> > tasks.
> I don't use pwm-sti driver. I update meson pwm driver for new chips
> and when started using pwm_set_chip_data in probe I was very surprised that
> my data is lost after sysfs export/unexport calls. Then I found the 
> patch and
> checked other drivers for similar usecases.

OK.

> Probably you're right about dropping pwm_set_chip_data.

If you want to tackle that, you might want to take

	https://lore.kernel.org/all/20210504132537.62072-2-u.kleine-koenig@pengutronix.de/

into account. (Both to reuse this patch to prepare pwm-berlin for
dropping pwm_set_chip_data and to be prepared that back then Thierry
opposed to the idea.)

Best regards
Uwe

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

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

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

end of thread, other threads:[~2023-03-08 16:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-07 21:00 [RFC PATCH v1] Revert "pwm: Clear chip_data in pwm_put()" George Stark
2023-03-07 21:27 ` Uwe Kleine-König
2023-03-08 12:16   ` George Stark
2023-03-08 16:52     ` Uwe Kleine-König

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).