2020-05-14 03:57:58

by 王文虎

[permalink] [raw]
Subject: [PATCH] drivers: ipa: use devm_kzalloc for simplicity

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

Signed-off-by: Wang Wenhu <[email protected]>
Cc: Alex Elder <[email protected]>
---
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


2020-05-14 17:19:25

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH] drivers: ipa: use devm_kzalloc for simplicity

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 <[email protected]>

The code is perfectly fine as is. What problem are you trying to solve?

2020-05-14 20:10:02

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] drivers: ipa: use devm_kzalloc for simplicity

From: Jakub Kicinski <[email protected]>
Date: Thu, 14 May 2020 10:15:16 -0700

> 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 <[email protected]>
>
> The code is perfectly fine as is. What problem are you trying to solve?

I agree, these kinds of transformations are kind of excessive.

2020-05-18 15:09:01

by Alex Elder

[permalink] [raw]
Subject: Re: [PATCH] drivers: ipa: use devm_kzalloc for simplicity

On 5/14/20 2:47 PM, David Miller wrote:
> From: Jakub Kicinski <[email protected]>
> Date: Thu, 14 May 2020 10:15:16 -0700
>
>> 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 <[email protected]>
>>
>> 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