linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] power: supply: cpcap-battery: use device_get_match_data() to simplify code
@ 2021-09-28  2:06 Tang Bin
  2021-10-02 16:03 ` Sebastian Reichel
  0 siblings, 1 reply; 2+ messages in thread
From: Tang Bin @ 2021-09-28  2:06 UTC (permalink / raw)
  To: sre; +Cc: linux-pm, linux-kernel, Tang Bin

In the function cpcap_battery_probe(), the driver only needs the
data object, so use device_get_match_data() instead, to make the
code cleaner.

Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
---
Changes from v1
 - change the title and commit message.
 - change the code to use other api to make code simple.
---
 drivers/power/supply/cpcap-battery.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
index 8d62d4241..18e3ff0e1 100644
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -1026,20 +1026,13 @@ static const struct power_supply_desc cpcap_charger_battery_desc = {
 static int cpcap_battery_probe(struct platform_device *pdev)
 {
 	struct cpcap_battery_ddata *ddata;
-	const struct of_device_id *match;
 	struct power_supply_config psy_cfg = {};
 	int error;
+	const struct cpcap_battery_config *cfg;
 
-	match = of_match_device(of_match_ptr(cpcap_battery_id_table),
-				&pdev->dev);
-	if (!match)
-		return -EINVAL;
-
-	if (!match->data) {
-		dev_err(&pdev->dev, "no configuration data found\n");
-
+	cfg = device_get_match_data(&pdev->dev);
+	if (!cfg)
 		return -ENODEV;
-	}
 
 	ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
 	if (!ddata)
@@ -1047,7 +1040,7 @@ static int cpcap_battery_probe(struct platform_device *pdev)
 
 	INIT_LIST_HEAD(&ddata->irq_list);
 	ddata->dev = &pdev->dev;
-	memcpy(&ddata->config, match->data, sizeof(ddata->config));
+	memcpy(&ddata->config, cfg, sizeof(ddata->config));
 
 	ddata->reg = dev_get_regmap(ddata->dev->parent, NULL);
 	if (!ddata->reg)
-- 
2.20.1.windows.1




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

* Re: [PATCH v2] power: supply: cpcap-battery: use device_get_match_data() to simplify code
  2021-09-28  2:06 [PATCH v2] power: supply: cpcap-battery: use device_get_match_data() to simplify code Tang Bin
@ 2021-10-02 16:03 ` Sebastian Reichel
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2021-10-02 16:03 UTC (permalink / raw)
  To: Tang Bin; +Cc: linux-pm, linux-kernel

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

Hi,

On Tue, Sep 28, 2021 at 10:06:23AM +0800, Tang Bin wrote:
> In the function cpcap_battery_probe(), the driver only needs the
> data object, so use device_get_match_data() instead, to make the
> code cleaner.
> 
> Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
> ---

Thanks, queued.

-- Sebastian

> Changes from v1
>  - change the title and commit message.
>  - change the code to use other api to make code simple.
> ---
>  drivers/power/supply/cpcap-battery.c | 15 ++++-----------
>  1 file changed, 4 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
> index 8d62d4241..18e3ff0e1 100644
> --- a/drivers/power/supply/cpcap-battery.c
> +++ b/drivers/power/supply/cpcap-battery.c
> @@ -1026,20 +1026,13 @@ static const struct power_supply_desc cpcap_charger_battery_desc = {
>  static int cpcap_battery_probe(struct platform_device *pdev)
>  {
>  	struct cpcap_battery_ddata *ddata;
> -	const struct of_device_id *match;
>  	struct power_supply_config psy_cfg = {};
>  	int error;
> +	const struct cpcap_battery_config *cfg;
>  
> -	match = of_match_device(of_match_ptr(cpcap_battery_id_table),
> -				&pdev->dev);
> -	if (!match)
> -		return -EINVAL;
> -
> -	if (!match->data) {
> -		dev_err(&pdev->dev, "no configuration data found\n");
> -
> +	cfg = device_get_match_data(&pdev->dev);
> +	if (!cfg)
>  		return -ENODEV;
> -	}
>  
>  	ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
>  	if (!ddata)
> @@ -1047,7 +1040,7 @@ static int cpcap_battery_probe(struct platform_device *pdev)
>  
>  	INIT_LIST_HEAD(&ddata->irq_list);
>  	ddata->dev = &pdev->dev;
> -	memcpy(&ddata->config, match->data, sizeof(ddata->config));
> +	memcpy(&ddata->config, cfg, sizeof(ddata->config));
>  
>  	ddata->reg = dev_get_regmap(ddata->dev->parent, NULL);
>  	if (!ddata->reg)
> -- 
> 2.20.1.windows.1
> 
> 
> 

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

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

end of thread, other threads:[~2021-10-02 16:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28  2:06 [PATCH v2] power: supply: cpcap-battery: use device_get_match_data() to simplify code Tang Bin
2021-10-02 16:03 ` Sebastian Reichel

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