[PATCH] drivers: ipa: use devm_kzalloc for simplicity

Subsystems: networking drivers, qcom ipa driver, the rest

STALE2266d

4 messages, 4 authors, 2020-05-18 · open the first message on its own page

[PATCH] drivers: ipa: use devm_kzalloc for simplicity

From: Wang Wenhu <hidden>
Date: 2020-05-14 03:56:13

Make a substitution of kzalloc with devm_kzalloc to simplify the
ipa_probe() process.

Signed-off-by: Wang Wenhu <redacted>
Cc: Alex Elder <elder@kernel.org>
---
 drivers/net/ipa/ipa_clock.c | 7 ++-----
 drivers/net/ipa/ipa_main.c  | 7 ++-----
 2 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ipa/ipa_clock.c b/drivers/net/ipa/ipa_clock.c
index 374491ea11cf..ddbd687fe64b 100644
--- a/drivers/net/ipa/ipa_clock.c
+++ b/drivers/net/ipa/ipa_clock.c
@@ -276,7 +276,7 @@ struct ipa_clock *ipa_clock_init(struct device *dev)
 		goto err_clk_put;
 	}
 
-	clock = kzalloc(sizeof(*clock), GFP_KERNEL);
+	clock = devm_kzalloc(dev, sizeof(*clock), GFP_KERNEL);
 	if (!clock) {
 		ret = -ENOMEM;
 		goto err_clk_put;
@@ -285,15 +285,13 @@ struct ipa_clock *ipa_clock_init(struct device *dev)
 
 	ret = ipa_interconnect_init(clock, dev);
 	if (ret)
-		goto err_kfree;
+		goto err_clk_put;
 
 	mutex_init(&clock->mutex);
 	atomic_set(&clock->count, 0);
 
 	return clock;
 
-err_kfree:
-	kfree(clock);
 err_clk_put:
 	clk_put(clk);
 
@@ -308,6 +306,5 @@ void ipa_clock_exit(struct ipa_clock *clock)
 	WARN_ON(atomic_read(&clock->count) != 0);
 	mutex_destroy(&clock->mutex);
 	ipa_interconnect_exit(clock);
-	kfree(clock);
 	clk_put(clk);
 }
diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c
index 28998dcce3d2..b7b348b863f7 100644
--- a/drivers/net/ipa/ipa_main.c
+++ b/drivers/net/ipa/ipa_main.c
@@ -760,7 +760,7 @@ static int ipa_probe(struct platform_device *pdev)
 	}
 
 	/* Allocate and initialize the IPA structure */
-	ipa = kzalloc(sizeof(*ipa), GFP_KERNEL);
+	ipa = devm_kzalloc(dev, sizeof(*ipa), GFP_KERNEL);
 	if (!ipa) {
 		ret = -ENOMEM;
 		goto err_wakeup_source_unregister;
@@ -776,7 +776,7 @@ static int ipa_probe(struct platform_device *pdev)
 
 	ret = ipa_reg_init(ipa);
 	if (ret)
-		goto err_kfree_ipa;
+		goto err_wakeup_source_unregister;
 
 	ret = ipa_mem_init(ipa, data->mem_count, data->mem_data);
 	if (ret)
@@ -848,8 +848,6 @@ static int ipa_probe(struct platform_device *pdev)
 	ipa_mem_exit(ipa);
 err_reg_exit:
 	ipa_reg_exit(ipa);
-err_kfree_ipa:
-	kfree(ipa);
 err_wakeup_source_unregister:
 	wakeup_source_unregister(wakeup_source);
 err_clock_exit:
@@ -885,7 +883,6 @@ static int ipa_remove(struct platform_device *pdev)
 	gsi_exit(&ipa->gsi);
 	ipa_mem_exit(ipa);
 	ipa_reg_exit(ipa);
-	kfree(ipa);
 	wakeup_source_unregister(wakeup_source);
 	ipa_clock_exit(clock);
 	rproc_put(rproc);
-- 
2.17.1

Re: [PATCH] drivers: ipa: use devm_kzalloc for simplicity

From: Jakub Kicinski <kuba@kernel.org>
Date: 2020-05-14 17:15:19

On Wed, 13 May 2020 20:55:20 -0700 Wang Wenhu wrote:
Make a substitution of kzalloc with devm_kzalloc to simplify the
ipa_probe() process.

Signed-off-by: Wang Wenhu <redacted>
The code is perfectly fine as is. What problem are you trying to solve?

Re: [PATCH] drivers: ipa: use devm_kzalloc for simplicity

From: David Miller <davem@davemloft.net>
Date: 2020-05-14 19:47:07

From: Jakub Kicinski <kuba@kernel.org>
Date: Thu, 14 May 2020 10:15:16 -0700
On Wed, 13 May 2020 20:55:20 -0700 Wang Wenhu wrote:
quoted
Make a substitution of kzalloc with devm_kzalloc to simplify the
ipa_probe() process.

Signed-off-by: Wang Wenhu <redacted>
The code is perfectly fine as is. What problem are you trying to solve?
I agree, these kinds of transformations are kind of excessive.

Re: [PATCH] drivers: ipa: use devm_kzalloc for simplicity

From: Alex Elder <hidden>
Date: 2020-05-18 15:03:58

On 5/14/20 2:47 PM, David Miller wrote:
From: Jakub Kicinski <kuba@kernel.org>
Date: Thu, 14 May 2020 10:15:16 -0700
quoted
On Wed, 13 May 2020 20:55:20 -0700 Wang Wenhu wrote:
quoted
Make a substitution of kzalloc with devm_kzalloc to simplify the
ipa_probe() process.

Signed-off-by: Wang Wenhu <redacted>
The code is perfectly fine as is. What problem are you trying to solve?
I agree, these kinds of transformations are kind of excessive.
I have considered using the devm_*() functions, but if I were to
make such a switch it would be done comprehensively, throughout
the driver.  It is not something I plan to do in the near term
though.

					-Alex
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help