Skip to contentSkip to conversation

firmware: tegra: bpmp: Fix freeing uninitialized pointers

PATCH In review Gax-c 3 participants 9 messages Oct 1, 2024 – Oct 5, 2024

Subsystems (2)
lore
Share & tools
lore

Gax-c

author
#0 lore raw

PATCH 1/1 firmware: tegra: bpmp: Fix freeing uninitialized pointers

Like commit 90ca6956d383 ("ice: Fix freeing uninitialized pointers"), automatically cleaned up pointers need to be initialized before exiting their scope. Additionally, device_node() should be replaced with a proper freeing free function of_node_put() in this case.
And the pointer need to be initialized to NULL before any return statement.

Fixes 8812b8689ee6 ("firmware: tegra: bpmp: Use scoped device node handling to simplify error paths")
---
 drivers/firmware/tegra/bpmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/tegra/bpmp.c +1 -1
index 2bee6e918f81..b365995364fb 100644
@@ -35,7 +35,7 @@ channel_to_ops(struct tegra_bpmp_channel *channel)
 
 struct tegra_bpmp *tegra_bpmp_get(struct device *dev)
 {
-	struct device_node *np __free(device_node);
+	struct device_node *np __free(of_node_put) = NULL;
 	struct platform_device *pdev;
 	struct tegra_bpmp *bpmp;
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines · Gax-c

Like commit 90ca6956d383 ("ice: Fix freeing uninitialized pointers"), automatically cleaned up pointers need to be initialized before exiting their scope.

So where is the early exit?

Quoted 3 lines

Additionally, device_node() should be replaced with a proper freeing free function of_node_put() in this case.
And the pointer need to be initialized to NULL before any return statement.

And it is already.

This looks really bogus.

Quoted 4 lines
Fixes 8812b8689ee6 ("firmware: tegra: bpmp: Use scoped device node handling to simplify error paths")

Hm? How is this possible? You are writing this patch, aren't you? This is bogus tag.

Quoted 2 lines

Where are the reports? Why three people are listed here?

This is an open source work and public collaboration. The "Reported-by" usually means that the issue was reported to us, in some way, usually in public. Can we see the report?
Otherwise adding non-public, non-verifiable reports is useless and clutters our report-credit-system.

Best regards,
Krzysztof

author
#2 lore raw

Thank you for your feedback!

You can see from commit 90ca6956d383 ("ice: Fix freeing uninitialized pointers") or any other usages of __free.
Initialization is a necessary and standard way to protect your memory.

Additionally, the proper freeing function should be of_node_put() rather than device_node().
In commit 8812b8689ee6 ("firmware: tegra: bpmp: Use scoped device node handling to simplify error paths"),
of_node_put() was originally set to free the memory.

And as for the tag mistakes. We are sorry and will correct that later.

Best,
Zichen

Quoted 40 lines · Krzysztof Kozlowski
Quoted 2 lines · Gax-c

Like commit 90ca6956d383 ("ice: Fix freeing uninitialized pointers"), automatically cleaned up pointers need to be initialized before exiting their scope.

So where is the early exit?

Quoted 3 lines

Additionally, device_node() should be replaced with a proper freeing free function of_node_put() in this case.
And the pointer need to be initialized to NULL before any return statement.

And it is already.

This looks really bogus.

Quoted 4 lines
Fixes 8812b8689ee6 ("firmware: tegra: bpmp: Use scoped device node handling to simplify error paths")

Hm? How is this possible? You are writing this patch, aren't you? This is bogus tag.

Quoted 2 lines

Where are the reports? Why three people are listed here?

This is an open source work and public collaboration. The "Reported-by" usually means that the issue was reported to us, in some way, usually in public. Can we see the report?
Otherwise adding non-public, non-verifiable reports is useless and clutters our report-credit-system.

Best regards,
Krzysztof

#3 lore raw
Quoted 5 lines · Zichen Xie

Thank you for your feedback!

You can see from commit 90ca6956d383 ("ice: Fix freeing uninitialized pointers") or any other usages of __free.
Initialization is a necessary and standard way to protect your memory.

You did not understand that commit.

Quoted 3 lines

Additionally, the proper freeing function should be of_node_put() rather than device_node().

What?

Quoted 3 lines

In commit 8812b8689ee6 ("firmware: tegra: bpmp: Use scoped device node handling to simplify error paths"),
of_node_put() was originally set to free the memory.

What?!?!

You don't understand this code, do you?

Quoted 4 lines

And as for the tag mistakes. We are sorry and will correct that later.

Best,

Best regards,
Krzysztof

#4 lore raw
Quoted 15 lines · Krzysztof Kozlowski
Quoted 5 lines · Zichen Xie

Thank you for your feedback!

You can see from commit 90ca6956d383 ("ice: Fix freeing uninitialized pointers") or any other usages of __free.
Initialization is a necessary and standard way to protect your memory.

You did not understand that commit.

Quoted 3 lines

Additionally, the proper freeing function should be of_node_put() rather than device_node().

What?

Quoted 7 lines
Quoted 3 lines

In commit 8812b8689ee6 ("firmware: tegra: bpmp: Use scoped device node handling to simplify error paths"),
of_node_put() was originally set to free the memory.

What?!?!

You don't understand this code, do you?

To be clear:
1. Neither your code nor explanation make any sense.
2. Patch is wrong - buggy.
3. Patch was never even compiled.

That's a NAK, before anyone tries to pick it up.

Best regards,
Krzysztof

author
#5 lore raw

I don't think device_node() is a correct freeing function here:
'struct device_node *np __free(device_node);'
even if I'm not an expert in Kernel.

And I think it could be more convincing to explain 'why', rather than simply highlighting the errors repeatedly.

Best,
Zichen

Quoted 35 lines · Krzysztof Kozlowski
Quoted 15 lines · Krzysztof Kozlowski
Quoted 5 lines · Zichen Xie

Thank you for your feedback!

You can see from commit 90ca6956d383 ("ice: Fix freeing uninitialized pointers") or any other usages of __free.
Initialization is a necessary and standard way to protect your memory.

You did not understand that commit.

Quoted 3 lines

Additionally, the proper freeing function should be of_node_put() rather than device_node().

What?

Quoted 7 lines
Quoted 3 lines

In commit 8812b8689ee6 ("firmware: tegra: bpmp: Use scoped device node handling to simplify error paths"),
of_node_put() was originally set to free the memory.

What?!?!

You don't understand this code, do you?

To be clear:
1. Neither your code nor explanation make any sense.
2. Patch is wrong - buggy.
3. Patch was never even compiled.

That's a NAK, before anyone tries to pick it up.

Best regards,
Krzysztof

#6 lore raw
Quoted 6 lines · Zichen Xie

I don't think device_node() is a correct freeing function here:
'struct device_node *np __free(device_node);'
even if I'm not an expert in Kernel.

And I think it could be more convincing to explain 'why', rather than simply highlighting the errors repeatedly.

If you ever bothered to compile your code, you would see why.

None of your arguments make any sense. Your code tries to perform initialization, just before assignment so it is completely unnecessary. I don't understand why you could not spot that obvious part of the code, because this is just C. For obvious reasons I won't be spending my time to explain why this:

some_ptr *ptr = NULL;
ptr = foo;
if () ...
return ...;

is wrong. You just did not read the code, not built it.

Best regards,
Krzysztof

author
#7 lore raw

Hi Krzysztof,

Thank you for the explanation and sorry for not realizing the correct deallocation function.

I found in another email thread that the NULL initialization following the __free() was mainly for readability but not safety. Sorry for the confusion.

We are working on a static analysis tool and wanted to report potential bugs. We directly sent a patch trying to reduce developer’s burden but didn’t not realize the correct use of Reported-by tag. We will be more careful in the future.

Best,
Zichen

Quoted 27 lines · Krzysztof Kozlowski
Quoted 6 lines · Zichen Xie

I don't think device_node() is a correct freeing function here:
'struct device_node *np __free(device_node);'
even if I'm not an expert in Kernel.

And I think it could be more convincing to explain 'why', rather than simply highlighting the errors repeatedly.

If you ever bothered to compile your code, you would see why.

None of your arguments make any sense. Your code tries to perform initialization, just before assignment so it is completely unnecessary. I don't understand why you could not spot that obvious part of the code, because this is just C. For obvious reasons I won't be spending my time to explain why this:

some_ptr *ptr = NULL;
ptr = foo;
if () ...
return ...;

is wrong. You just did not read the code, not built it.

Best regards,
Krzysztof

#8 lore raw
Quoted 11 lines

Thank you for the explanation and sorry for not realizing the correct deallocation function.

I found in another email thread that the NULL initialization following the __free() was mainly for readability but not safety. Sorry for the confusion.

We are working on a static analysis tool and wanted to report potential bugs. We directly sent a patch trying to reduce developer’s burden but didn’t not realize the correct use of Reported-by tag. We will be more careful in the future.

Please take another look at another corresponding public information source.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/researcher-guidelines.rst?h=v6.12-rc1#n5

Regards,
Markus