The upcoming Rust abstraction layer for the PWM subsystem uses a custom
`dev->release` handler to safely manage the lifetime of its driver
data.
To prevent leaking the memory of the `struct pwm_chip` (allocated by
`pwmchip_alloc`), this custom handler must also call the original
`pwmchip_release` function to complete the cleanup.
Make `pwmchip_release` a global, exported function so that it can be
called from the Rust FFI bridge. This involves removing the `static`
keyword, adding a prototype to the public header, and exporting the
symbol.
Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com>
---
drivers/pwm/core.c | 3 ++-
include/linux/pwm.h | 5 +++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 0d66376a83ec350e0c3718959f4d794efd71595a..a33da3dff608fdff91251e5fd07b0dbd295be022 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -1600,12 +1600,13 @@ void pwmchip_put(struct pwm_chip *chip)
}
EXPORT_SYMBOL_GPL(pwmchip_put);
-static void pwmchip_release(struct device *pwmchip_dev)
+void pwmchip_release(struct device *pwmchip_dev)
{
struct pwm_chip *chip = pwmchip_from_dev(pwmchip_dev);
kfree(chip);
}
+EXPORT_SYMBOL_GPL(pwmchip_release);
struct pwm_chip *pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv)
{
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 8cafc483db53addf95591d1ac74287532c0fa0ee..8f0698c09e62b893d63fc258da3c34781183056f 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -478,6 +478,7 @@ static inline bool pwm_might_sleep(struct pwm_device *pwm)
/* PWM provider APIs */
void pwmchip_put(struct pwm_chip *chip);
+void pwmchip_release(struct device *dev);
struct pwm_chip *pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv);
struct pwm_chip *devm_pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv);
@@ -551,6 +552,10 @@ static inline void pwmchip_put(struct pwm_chip *chip)
{
}
+static inline void pwmchip_release(struct device *dev)
+{
+}
+
static inline struct pwm_chip *pwmchip_alloc(struct device *parent,
unsigned int npwm,
size_t sizeof_priv)
--
2.34.1
Hello Michal, On Thu, Jul 10, 2025 at 08:54:28PM +0200, Michal Wilczynski wrote: > diff --git a/include/linux/pwm.h b/include/linux/pwm.h > index 8cafc483db53addf95591d1ac74287532c0fa0ee..8f0698c09e62b893d63fc258da3c34781183056f 100644 > --- a/include/linux/pwm.h > +++ b/include/linux/pwm.h > @@ -478,6 +478,7 @@ static inline bool pwm_might_sleep(struct pwm_device *pwm) > > /* PWM provider APIs */ > void pwmchip_put(struct pwm_chip *chip); > +void pwmchip_release(struct device *dev); I want this in a separate section because "normal" provider don't need that. Please add a comment that this is only public for technical reasons for the Rust wrappers. I understand you are eager to get this merged, but still I'd ask you to slow down your patch sending frequency. Currently I tend to not apply it for v6.17-rc1 as I'd like to have that in next for some time. With you waiting a bit longer before v11 I would have written that in reply to the explanation in the v10 thread and we might have saved one iteration ... > struct pwm_chip *pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv); > struct pwm_chip *devm_pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv); > > @@ -551,6 +552,10 @@ static inline void pwmchip_put(struct pwm_chip *chip) > { > } > > +static inline void pwmchip_release(struct device *dev) > +{ > +} > + Is this needed? There is no user of this function that doesn't depend on CONFIG_PWM?! > static inline struct pwm_chip *pwmchip_alloc(struct device *parent, > unsigned int npwm, > size_t sizeof_priv) > Best regards Uwe
On 7/10/25 22:52, Uwe Kleine-König wrote: > Hello Michal, > > On Thu, Jul 10, 2025 at 08:54:28PM +0200, Michal Wilczynski wrote: >> diff --git a/include/linux/pwm.h b/include/linux/pwm.h >> index 8cafc483db53addf95591d1ac74287532c0fa0ee..8f0698c09e62b893d63fc258da3c34781183056f 100644 >> --- a/include/linux/pwm.h >> +++ b/include/linux/pwm.h >> @@ -478,6 +478,7 @@ static inline bool pwm_might_sleep(struct pwm_device *pwm) >> >> /* PWM provider APIs */ >> void pwmchip_put(struct pwm_chip *chip); >> +void pwmchip_release(struct device *dev); > > I want this in a separate section because "normal" provider don't need > that. Please add a comment that this is only public for technical > reasons for the Rust wrappers. OK, thanks ! > > I understand you are eager to get this merged, but still I'd ask you to > slow down your patch sending frequency. Currently I tend to not apply it > for v6.17-rc1 as I'd like to have that in next for some time. Thank you for the feedback. All of your points make perfect sense. My apologies for the rapid pace of submissions; I will follow your suggestion and be sure to allow more time for discussion between future versions. > > With you waiting a bit longer before v11 I would have written that in > reply to the explanation in the v10 thread and we might have saved > one iteration ... > >> struct pwm_chip *pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv); >> struct pwm_chip *devm_pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv); >> >> @@ -551,6 +552,10 @@ static inline void pwmchip_put(struct pwm_chip *chip) >> { >> } >> >> +static inline void pwmchip_release(struct device *dev) >> +{ >> +} >> + > > Is this needed? There is no user of this function that doesn't depend > on CONFIG_PWM?! Since only Rust is using this it's not needed. Thanks ! > >> static inline struct pwm_chip *pwmchip_alloc(struct device *parent, >> unsigned int npwm, >> size_t sizeof_priv) >> > > Best regards > Uwe Best regards, -- Michal Wilczynski <m.wilczynski@samsung.com>
© 2016 - 2025 Red Hat, Inc.