LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] power: supply: cpcap-battery: remove redundant check
@ 2021-08-19 12:11 Tang Bin
  2021-09-27 15:46 ` Sebastian Reichel
  0 siblings, 1 reply; 3+ messages in thread
From: Tang Bin @ 2021-08-19 12:11 UTC (permalink / raw)
  To: sre; +Cc: linux-pm, linux-kernel, Tang Bin, Zhang Shengju

In the function cpcap_battery_probe(), the check of '!match->data'
can actually never happen for the driver. First, this probe function
will only be called if there is a match with an entry from the OF
device ID table, and then all entries have .data set to a valid point.
So remove the redundant check.

Co-developed-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
---
 drivers/power/supply/cpcap-battery.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
index 8d62d4241..a3866826b 100644
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -1035,12 +1035,6 @@ static int cpcap_battery_probe(struct platform_device *pdev)
 	if (!match)
 		return -EINVAL;
 
-	if (!match->data) {
-		dev_err(&pdev->dev, "no configuration data found\n");
-
-		return -ENODEV;
-	}
-
 	ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
 	if (!ddata)
 		return -ENOMEM;
-- 
2.20.1.windows.1




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

* Re: [PATCH] power: supply: cpcap-battery: remove redundant check
  2021-08-19 12:11 [PATCH] power: supply: cpcap-battery: remove redundant check Tang Bin
@ 2021-09-27 15:46 ` Sebastian Reichel
  2021-09-28  1:21   ` tangbin
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Reichel @ 2021-09-27 15:46 UTC (permalink / raw)
  To: Tang Bin; +Cc: linux-pm, linux-kernel, Zhang Shengju, Tony Lindgren

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

Hi,

On Thu, Aug 19, 2021 at 08:11:37PM +0800, Tang Bin wrote:
> In the function cpcap_battery_probe(), the check of '!match->data'
> can actually never happen for the driver. First, this probe function
> will only be called if there is a match with an entry from the OF
> device ID table, and then all entries have .data set to a valid point.
> So remove the redundant check.
> 
> Co-developed-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
> Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
> Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
> ---

NAK. Instead replace the complate of_match_device() part. The driver
only needs the data object and there is of_device_get_match_data()
for this. Also - even better - there is a non-DT specific variant
which is device_get_match_data(). Please use that:


const struct cpcap_battery_config *cfg = device_get_match_data(&pdev->dev);
if (!cfg)
    return -ENODEV;

memcpy(&ddata->config, cfg, sizeof(ddata->config));

Thanks,

-- Sebastian

>  drivers/power/supply/cpcap-battery.c | 6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
> index 8d62d4241..a3866826b 100644
> --- a/drivers/power/supply/cpcap-battery.c
> +++ b/drivers/power/supply/cpcap-battery.c
> @@ -1035,12 +1035,6 @@ static int cpcap_battery_probe(struct platform_device *pdev)
>  	if (!match)
>  		return -EINVAL;
>  
> -	if (!match->data) {
> -		dev_err(&pdev->dev, "no configuration data found\n");
> -
> -		return -ENODEV;
> -	}
> -
>  	ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
>  	if (!ddata)
>  		return -ENOMEM;
> -- 
> 2.20.1.windows.1
> 
> 
> 

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

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

* Re: [PATCH] power: supply: cpcap-battery: remove redundant check
  2021-09-27 15:46 ` Sebastian Reichel
@ 2021-09-28  1:21   ` tangbin
  0 siblings, 0 replies; 3+ messages in thread
From: tangbin @ 2021-09-28  1:21 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-pm, linux-kernel, Tony Lindgren

Hi, Reichel

On 2021/9/27 23:46, Sebastian Reichel wrote:
> NAK. Instead replace the complate of_match_device() part. The driver
> only needs the data object and there is of_device_get_match_data()
> for this. Also - even better - there is a non-DT specific variant
> which is device_get_match_data(). Please use that:
>
>
> const struct cpcap_battery_config *cfg = device_get_match_data(&pdev->dev);
> if (!cfg)
>      return -ENODEV;
>
> memcpy(&ddata->config, cfg, sizeof(ddata->config));
>
Got it. Before this patch, I thought it would be better to use 
of_device_get_match_data()

to simplify for this place, but your email made me learn it again. I 
will send patch v2 for

you.

Thanks

Tang Bin

>
>>   drivers/power/supply/cpcap-battery.c | 6 ------
>>   1 file changed, 6 deletions(-)
>>
>> diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
>> index 8d62d4241..a3866826b 100644
>> --- a/drivers/power/supply/cpcap-battery.c
>> +++ b/drivers/power/supply/cpcap-battery.c
>> @@ -1035,12 +1035,6 @@ static int cpcap_battery_probe(struct platform_device *pdev)
>>   	if (!match)
>>   		return -EINVAL;
>>   
>> -	if (!match->data) {
>> -		dev_err(&pdev->dev, "no configuration data found\n");
>> -
>> -		return -ENODEV;
>> -	}
>> -
>>   	ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
>>   	if (!ddata)
>>   		return -ENOMEM;
>> -- 
>> 2.20.1.windows.1
>>
>>
>>



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

end of thread, other threads:[~2021-09-28  1:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-19 12:11 [PATCH] power: supply: cpcap-battery: remove redundant check Tang Bin
2021-09-27 15:46 ` Sebastian Reichel
2021-09-28  1:21   ` tangbin

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