linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] pwm: samsung: Simplify using devm_pwmchip_add()
       [not found] <20210901054230.29678-1-zhaoxiao@uniontech.com>
@ 2021-09-01  8:56 ` Krzysztof Kozlowski
       [not found]   ` <612f43cc.1c69fb81.205fc.d94bSMTPIN_ADDED_BROKEN@mx.google.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Krzysztof Kozlowski @ 2021-09-01  8:56 UTC (permalink / raw)
  To: zhaoxiao, thierry.reding, lee.jones
  Cc: u.kleine-koenig, linux-arm-kernel, linux-samsung-soc, linux-pwm,
	linux-kernel

On 01/09/2021 07:42, zhaoxiao wrote:
> With devm_pwmchip_add() we can drop pwmchip_remove() from the device
> remove callback. The latter can then go away, too and as this is the
> only user of platform_get_drvdata(), the respective call to
> platform_set_drvdata() can go, too.
> 
> Signed-off-by: zhaoxiao <zhaoxiao@uniontech.com>
> ---
>  drivers/pwm/pwm-samsung.c | 18 +-----------------
>  1 file changed, 1 insertion(+), 17 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-samsung.c b/drivers/pwm/pwm-samsung.c
> index f6c528f02d43..b860a7b8bbdf 100644
> --- a/drivers/pwm/pwm-samsung.c
> +++ b/drivers/pwm/pwm-samsung.c
> @@ -560,9 +560,7 @@ static int pwm_samsung_probe(struct platform_device *pdev)
>  	chip->tclk0 = devm_clk_get(&pdev->dev, "pwm-tclk0");
>  	chip->tclk1 = devm_clk_get(&pdev->dev, "pwm-tclk1");
>  
> -	platform_set_drvdata(pdev, chip);

The test looks untested because this should cause bug during resume.
> -
> -	ret = pwmchip_add(&chip->chip);
> +	ret = devm_pwmchip_add(&pdev->dev, &chip->chip);
>  	if (ret < 0) {
>  		dev_err(dev, "failed to register PWM chip\n");
>  		clk_disable_unprepare(chip->base_clk);
> @@ -577,19 +575,6 @@ static int pwm_samsung_probe(struct platform_device *pdev)
>  	return 0;
>  }
>  
> -static int pwm_samsung_remove(struct platform_device *pdev)
> -{
> -	struct samsung_pwm_chip *chip = platform_get_drvdata(pdev);
> -	int ret;
> -
> -	ret = pwmchip_remove(&chip->chip);
> -	if (ret < 0)
> -		return ret;
> -
> -	clk_disable_unprepare(chip->base_clk);

NAK, the patch looks bad. You cannot remove some code from remove()
callback just "because".


Best regards,
Krzysztof

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

* Re: [PATCH] pwm: samsung: Simplify using devm_pwmchip_add()
       [not found]   ` <612f43cc.1c69fb81.205fc.d94bSMTPIN_ADDED_BROKEN@mx.google.com>
@ 2021-09-01  9:42     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 2+ messages in thread
From: Krzysztof Kozlowski @ 2021-09-01  9:42 UTC (permalink / raw)
  To: zhaoxiao, thierry.reding, lee.jones
  Cc: u.kleine-koenig, linux-arm-kernel, linux-samsung-soc, linux-pwm,
	linux-kernel

On 01/09/2021 11:11, zhaoxiao wrote:
> Thanks for your advices, This patch is modified with reference to the 
> patch that has been submitted,example:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git/commit/?h=staging-testing&id=66a03c4fd9e95e192c574811a1f4ea8f62992358
> 

The patch there looks correct, but you cannot apply one code pattern to
entirely different code and hope it works.

You reference a patch in a driver not using drvdata and having only
pwmchip_remove() in its remove() callback.

Now you apply it to other drivers and:
1. Remove drvdata even though it is used,
2. Delete additional code from remove() callback.

Especially the point (2) is a proof that you don't understand the
fundamental Linux driver model, so please do not convert code into
devm-like() before learning it.


Best regards,
Krzysztof

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

end of thread, other threads:[~2021-09-01  9:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20210901054230.29678-1-zhaoxiao@uniontech.com>
2021-09-01  8:56 ` [PATCH] pwm: samsung: Simplify using devm_pwmchip_add() Krzysztof Kozlowski
     [not found]   ` <612f43cc.1c69fb81.205fc.d94bSMTPIN_ADDED_BROKEN@mx.google.com>
2021-09-01  9:42     ` Krzysztof Kozlowski

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