Skip to contentSkip to conversation

dmaengine: acpi: Free resource list at appropriate time

PATCH In review Andy Shevchenko 2 participants 4 messages Jun 17 – Oct 16 dmaengine

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: acpi: Free resource list at appropriate time

In one case we don't free resources when formally should, and in the other we do unneeded "double free" (emptying an empty list).

Both are not critical issues at all, they just make code robust against any possible future changes in the flow.

---
 drivers/dma/acpi-dma.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/dma/acpi-dma.c +3 -2
index be73021ecbd6..b053a7f96f85 100644
@@ -55,7 +55,7 @@ static int acpi_dma_parse_resource_group(const struct acpi_csrt_group *grp,
 
 	INIT_LIST_HEAD(&resource_list);
 	ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
-	if (ret <= 0)
+	if (ret < 0)
 		return 0;
 
 	list_for_each_entry(rentry, &resource_list, node) {
@@ -370,10 +370,11 @@ struct dma_chan *acpi_dma_request_slave_chan_by_index(struct device *dev,
 	INIT_LIST_HEAD(&resource_list);
 	ret = acpi_dev_get_resources(adev, &resource_list,
 				     acpi_dma_parse_fixed_dma, &pdata);
-	acpi_dev_free_resource_list(&resource_list);
 	if (ret < 0)
 		return ERR_PTR(ret);
 
+	acpi_dev_free_resource_list(&resource_list);
+
 	if (dma_spec->slave_id < 0 || dma_spec->chan_id < 0)
 		return ERR_PTR(-ENODEV);
 
Signature · 1 line
2.50.1
#1 lore raw
Quoted 6 lines · Andy Shevchenko

In one case we don't free resources when formally should, and in the other we do unneeded "double free" (emptying an empty list).

Both are not critical issues at all, they just make code robust against any possible future changes in the flow.

what are you talking about, can use straight forward words.

You just move acpi_dev_free_resource_list() after check return value of acpi_dev_get_resources().

Quoted 11 lines
---
 drivers/dma/acpi-dma.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/dma/acpi-dma.c +0 -0
index be73021ecbd6..b053a7f96f85 100644

drivers/dma/acpi-dma.c static int acpi_dma_parse_resource_group(const struct acpi_csrt_group *grp, · line 59

Quoted 6 lines
drivers/dma/acpi-dma.c +1 -1
@@ -55,7 +55,7 @@ static int acpi_dma_parse_resource_group(const struct acpi_csrt_group *grp,
 
 	INIT_LIST_HEAD(&resource_list);
 	ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
-	if (ret <= 0)
+	if (ret < 0)
 		return 0;

Dose this change related with this patch?

Frank

Quoted 18 lines
drivers/dma/acpi-dma.c +2 -2
 	list_for_each_entry(rentry, &resource_list, node) {
@@ -370,10 +370,11 @@ struct dma_chan *acpi_dma_request_slave_chan_by_index(struct device *dev,
 	INIT_LIST_HEAD(&resource_list);
 	ret = acpi_dev_get_resources(adev, &resource_list,
 				     acpi_dma_parse_fixed_dma, &pdata);
-	acpi_dev_free_resource_list(&resource_list);
 	if (ret < 0)
 		return ERR_PTR(ret);
 
+	acpi_dev_free_resource_list(&resource_list);
+
 	if (dma_spec->slave_id < 0 || dma_spec->chan_id < 0)
 		return ERR_PTR(-ENODEV);
 
--

2.50.1

#2 lore raw
Quoted 5 lines · Frank Li
Quoted 4 lines · Andy Shevchenko

In one case we don't free resources when formally should, and in the other we do unneeded "double free" (emptying an empty list).

Quoted 7 lines
Quoted 2 lines

Both are not critical issues at all, they just make code robust against any possible future changes in the flow.

what are you talking about, can use straight forward words.

You just move acpi_dev_free_resource_list() after check return value of acpi_dev_get_resources().

Not really. There are _two_ cases. And while they are slightly different, the solution is to make them behave in the same ways.

...

Quoted 7 lines

drivers/dma/acpi-dma.c static int acpi_dma_parse_resource_group(const struct acpi_csrt_group *grp, · line 59

Quoted 5 lines
drivers/dma/acpi-dma.c +1 -1
 	INIT_LIST_HEAD(&resource_list);
 	ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
-	if (ret <= 0)
+	if (ret < 0)
 		return 0;

Dose this change related with this patch?

Yes. It's mentioned in the very first part of the first sentence in the commit message.

Quoted 18 lines
Quoted 18 lines
drivers/dma/acpi-dma.c +2 -2
 	list_for_each_entry(rentry, &resource_list, node) {
@@ -370,10 +370,11 @@ struct dma_chan *acpi_dma_request_slave_chan_by_index(struct device *dev,
 	INIT_LIST_HEAD(&resource_list);
 	ret = acpi_dev_get_resources(adev, &resource_list,
 				     acpi_dma_parse_fixed_dma, &pdata);
-	acpi_dev_free_resource_list(&resource_list);
 	if (ret < 0)
 		return ERR_PTR(ret);
 
+	acpi_dev_free_resource_list(&resource_list);
+
 	if (dma_spec->slave_id < 0 || dma_spec->chan_id < 0)
 		return ERR_PTR(-ENODEV);
 
--

2.50.1

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

In one case we don't free resources when formally should, and in the other we do unneeded "double free" (emptying an empty list).

Both are not critical issues at all, they just make code robust against any possible future changes in the flow.

Can you rephrase commit message

In acpi_dma_parse_resource_group(), change the return condition from "ret <= 0" to "ret < 0" so that when acpi_dev_get_resources() returns 0 (no resources), acpi_dev_free_resource_list() is still called to free the empty list instead of returning early.

In acpi_dma_request_slave_chan_by_index(), move acpi_dev_free_resource_list() to after the error check so that on the error return path the resource list is properly freed.

Frank

Quoted 35 lines
---
 drivers/dma/acpi-dma.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/dma/acpi-dma.c +3 -3
index be73021ecbd6..b053a7f96f85 100644
@@ -55,7 +55,7 @@ static int acpi_dma_parse_resource_group(const struct acpi_csrt_group *grp,
 
 	INIT_LIST_HEAD(&resource_list);
 	ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
-	if (ret <= 0)
+	if (ret < 0)
 		return 0;
 
 	list_for_each_entry(rentry, &resource_list, node) {
@@ -370,10 +370,11 @@ struct dma_chan *acpi_dma_request_slave_chan_by_index(struct device *dev,
 	INIT_LIST_HEAD(&resource_list);
 	ret = acpi_dev_get_resources(adev, &resource_list,
 				     acpi_dma_parse_fixed_dma, &pdata);
-	acpi_dev_free_resource_list(&resource_list);
 	if (ret < 0)
 		return ERR_PTR(ret);
 
+	acpi_dev_free_resource_list(&resource_list);
+
 	if (dma_spec->slave_id < 0 || dma_spec->chan_id < 0)
 		return ERR_PTR(-ENODEV);
 
--

2.50.1