Message ID | 20231121134901.208535-59-u.kleine-koenig@pengutronix.de |
---|---|
State | Superseded |
Headers | show |
Series | pwm: Fix lifetime issues for pwm_chips | expand |
Hi Uwe, On Di, 2023-11-21 at 14:50 +0100, Uwe Kleine-König wrote: > This prepares the pwm-imx27 driver to further changes of the pwm core > outlined in the commit introducing devm_pwmchip_alloc(). There is no > intended semantical change and the driver should behave as before. > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> > --- > drivers/pwm/pwm-imx27.c | 20 +++++++++++--------- > 1 file changed, 11 insertions(+), 9 deletions(-) > > diff --git a/drivers/pwm/pwm-imx27.c b/drivers/pwm/pwm-imx27.c > index 5d796453519a..52ac65e40e35 100644 > --- a/drivers/pwm/pwm-imx27.c > +++ b/drivers/pwm/pwm-imx27.c [...] > @@ -93,7 +92,10 @@ struct pwm_imx27_chip { > unsigned int duty_cycle; > }; > > -#define to_pwm_imx27_chip(chip) container_of(chip, struct pwm_imx27_chip, chip) > +static inline struct pwm_imx27_chip *to_pwm_imx27_chip(struct pwm_chip *chip) > +{ > + return pwmchip_priv(chip); > +} > > static int pwm_imx27_clk_prepare_enable(struct pwm_imx27_chip *imx) > { > @@ -306,13 +308,15 @@ MODULE_DEVICE_TABLE(of, pwm_imx27_dt_ids); > > static int pwm_imx27_probe(struct platform_device *pdev) > { > + struct pwm_chip *chip; > struct pwm_imx27_chip *imx; > int ret; > u32 pwmcr; > > - imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL); > - if (imx == NULL) > - return -ENOMEM; > + chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*imx)); > + if (IS_ERR(chip)) > + return PTR_ERR(chip); > + imx = pwmchip_priv(chip); Please use to_pwm_imx27_chip() here. Otherwise, Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> regards Philipp
Hello Philipp, On Tue, Dec 05, 2023 at 12:49:19PM +0100, Philipp Zabel wrote: > On Di, 2023-11-21 at 14:50 +0100, Uwe Kleine-König wrote: > > @@ -306,13 +308,15 @@ MODULE_DEVICE_TABLE(of, pwm_imx27_dt_ids); > > > > static int pwm_imx27_probe(struct platform_device *pdev) > > { > > + struct pwm_chip *chip; > > struct pwm_imx27_chip *imx; > > int ret; > > u32 pwmcr; > > > > - imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL); > > - if (imx == NULL) > > - return -ENOMEM; > > + chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*imx)); > > + if (IS_ERR(chip)) > > + return PTR_ERR(chip); > > + imx = pwmchip_priv(chip); > > Please use to_pwm_imx27_chip() here. Otherwise, > > Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> Thanks. This is already fixed in my tree for this and a few other drivers. Currently the patch looks as follows: https://git.pengutronix.de/cgit/ukl/linux/commit/?h=pwm-lifetime-tracking&id=4fa8c8a8661fa6d91de0368693d4a92907fb5359 The only other changes since this v3 is the usage of pwmchip_get_drvdata() instead of pwmchip_priv(). Can I keep your Reviewed-by for this new variant? Best regards Uwe
On Di, 2023-12-05 at 13:14 +0100, Uwe Kleine-König wrote: > Hello Philipp, > > On Tue, Dec 05, 2023 at 12:49:19PM +0100, Philipp Zabel wrote: > > On Di, 2023-11-21 at 14:50 +0100, Uwe Kleine-König wrote: > > > @@ -306,13 +308,15 @@ MODULE_DEVICE_TABLE(of, pwm_imx27_dt_ids); > > > > > > static int pwm_imx27_probe(struct platform_device *pdev) > > > { > > > + struct pwm_chip *chip; > > > struct pwm_imx27_chip *imx; > > > int ret; > > > u32 pwmcr; > > > > > > - imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL); > > > - if (imx == NULL) > > > - return -ENOMEM; > > > + chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*imx)); > > > + if (IS_ERR(chip)) > > > + return PTR_ERR(chip); > > > + imx = pwmchip_priv(chip); > > > > Please use to_pwm_imx27_chip() here. Otherwise, > > > > Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> > > Thanks. This is already fixed in my tree for this and a few other > drivers. Currently the patch looks as follows: > > https://git.pengutronix.de/cgit/ukl/linux/commit/?h=pwm-lifetime-tracking&id=4fa8c8a8661fa6d91de0368693d4a92907fb5359 > > The only other changes since this v3 is the usage of > pwmchip_get_drvdata() instead of pwmchip_priv(). Can I keep your > Reviewed-by for this new variant? Yes. regards Philipp
diff --git a/drivers/pwm/pwm-imx27.c b/drivers/pwm/pwm-imx27.c index 5d796453519a..52ac65e40e35 100644 --- a/drivers/pwm/pwm-imx27.c +++ b/drivers/pwm/pwm-imx27.c @@ -83,7 +83,6 @@ struct pwm_imx27_chip { struct clk *clk_ipg; struct clk *clk_per; void __iomem *mmio_base; - struct pwm_chip chip; /* * The driver cannot read the current duty cycle from the hardware if @@ -93,7 +92,10 @@ struct pwm_imx27_chip { unsigned int duty_cycle; }; -#define to_pwm_imx27_chip(chip) container_of(chip, struct pwm_imx27_chip, chip) +static inline struct pwm_imx27_chip *to_pwm_imx27_chip(struct pwm_chip *chip) +{ + return pwmchip_priv(chip); +} static int pwm_imx27_clk_prepare_enable(struct pwm_imx27_chip *imx) { @@ -306,13 +308,15 @@ MODULE_DEVICE_TABLE(of, pwm_imx27_dt_ids); static int pwm_imx27_probe(struct platform_device *pdev) { + struct pwm_chip *chip; struct pwm_imx27_chip *imx; int ret; u32 pwmcr; - imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL); - if (imx == NULL) - return -ENOMEM; + chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*imx)); + if (IS_ERR(chip)) + return PTR_ERR(chip); + imx = pwmchip_priv(chip); imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); if (IS_ERR(imx->clk_ipg)) @@ -324,9 +328,7 @@ static int pwm_imx27_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(imx->clk_per), "failed to get peripheral clock\n"); - imx->chip.ops = &pwm_imx27_ops; - imx->chip.dev = &pdev->dev; - imx->chip.npwm = 1; + chip->ops = &pwm_imx27_ops; imx->mmio_base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(imx->mmio_base)) @@ -341,7 +343,7 @@ static int pwm_imx27_probe(struct platform_device *pdev) if (!(pwmcr & MX3_PWMCR_EN)) pwm_imx27_clk_disable_unprepare(imx); - return devm_pwmchip_add(&pdev->dev, &imx->chip); + return devm_pwmchip_add(&pdev->dev, chip); } static struct platform_driver imx_pwm_driver = {
This prepares the pwm-imx27 driver to further changes of the pwm core outlined in the commit introducing devm_pwmchip_alloc(). There is no intended semantical change and the driver should behave as before. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> --- drivers/pwm/pwm-imx27.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)