All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pwm: samsung: Simplify using devm_pwmchip_add()
@ 2021-09-01  5:42 zhaoxiao
  2021-09-01  8:56   ` Krzysztof Kozlowski
  0 siblings, 1 reply; 6+ messages in thread
From: zhaoxiao @ 2021-09-01  5:42 UTC (permalink / raw)
  To: krzysztof.kozlowski, thierry.reding, lee.jones
  Cc: u.kleine-koenig, linux-arm-kernel, linux-samsung-soc, linux-pwm,
	linux-kernel, zhaoxiao

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);
-
-	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);
-
-	return 0;
-}
 
 #ifdef CONFIG_PM_SLEEP
 static int pwm_samsung_resume(struct device *dev)
@@ -635,7 +620,6 @@ static struct platform_driver pwm_samsung_driver = {
 		.of_match_table = of_match_ptr(samsung_pwm_matches),
 	},
 	.probe		= pwm_samsung_probe,
-	.remove		= pwm_samsung_remove,
 };
 module_platform_driver(pwm_samsung_driver);
 
-- 
2.20.1




_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] pwm: samsung: Simplify using devm_pwmchip_add()
  2021-09-01  5:42 [PATCH] pwm: samsung: Simplify using devm_pwmchip_add() zhaoxiao
@ 2021-09-01  8:56   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 6+ 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] 6+ messages in thread

* Re: [PATCH] pwm: samsung: Simplify using devm_pwmchip_add()
@ 2021-09-01  8:56   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 6+ 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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] pwm: samsung: Simplify using devm_pwmchip_add()
  2021-09-01  8:56   ` Krzysztof Kozlowski
  (?)
@ 2021-09-01  9:11   ` zhaoxiao
  -1 siblings, 0 replies; 6+ messages in thread
From: zhaoxiao @ 2021-09-01  9:11 UTC (permalink / raw)
  To: Krzysztof Kozlowski, thierry.reding, lee.jones
  Cc: u.kleine-koenig, linux-arm-kernel, linux-samsung-soc, linux-pwm,
	linux-kernel

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

在 2021/9/1 下午4:56, Krzysztof Kozlowski 写道:
> 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
>



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ 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; 6+ 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] 6+ messages in thread

* Re: [PATCH] pwm: samsung: Simplify using devm_pwmchip_add()
@ 2021-09-01  9:42       ` Krzysztof Kozlowski
  0 siblings, 0 replies; 6+ 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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

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

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

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.