Skip to content

Conversation

@Flole998
Copy link
Contributor

@Flole998 Flole998 commented Jan 24, 2023

Contribution description

In syscalls_init() there is a call to malloc(), which will return NULL if the heap is not initialized before, causing the entire board to fail booting if MODULE_ESP_IDF_HEAP is used.

API of vTaskDelete() says, that if NULL is passed to vTaskDelete the calling task should be deleted.

This PR needs a backport to 2023.01.

Testing procedure

Just compiling on the ESP32S2 and running it with WiFi caused it to not start anymore, no output, nothing. When Null is written to that null-pointer it hangs.

The second commit fixed an issue/assertion fail that happens when the WiFi connection drops/disconnects.

Issues/PRs references

Issue was introduced with PR #19146

In syscalls_init() there is a call to malloc(), which will return NULL if the heap is not initialized before, causing the entire board to fail booting if MODULE_ESP_IDF_HEAP is used.
@Flole998 Flole998 requested a review from gschorcht as a code owner January 24, 2023 16:52
@github-actions github-actions bot added Area: cpu Area: CPU/MCU ports Platform: ESP Platform: This PR/issue effects ESP-based platforms labels Jan 24, 2023
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jan 24, 2023
@riot-ci
Copy link

riot-ci commented Jan 24, 2023

Murdock results

✔️ PASSED

56d2997 cpu/esp_common/freertos: Handle NULL being passed to vTaskDelete

Success Failures Total Runtime
6796 0 6796 11m:44s

Artifacts

@gschorcht
Copy link
Contributor

Oops, thank you for figuring out that issue. It is is a side effect of the recent change d5a28ec in PR #19146 where syscalls_init moved to an earlier position in the startup procedure to solve another issue. Since we tested it without WiFi, the esp_idf_heap module wasn't used and I didn't realize this side effect.

I'm not sure whether calling esp_idf_heap_init might cause other problems, I have to check. I'm also wondering whether we really need that malloc in syscalls_init

environ = malloc(sizeof(char*));
environ[0] = NULL;
is needed at all or whether the environment variable could also be static variable initialized with a static initializer.

@gschorcht gschorcht changed the title Fixes for boot issues and crashes on ESP32 cpu/esp32: fixes for boot issues and crashes on ESP32 Jan 24, 2023
@Flole998
Copy link
Contributor Author

I went through the code to check for potential other issues but haven't seen anything that could potentially break.

I guess environ is realloc()ed if it's resized, or at least that's what I would expect. So static would not work.

@gschorcht
Copy link
Contributor

I guess environ is realloc()ed if it's resized, or at least that's what I would expect. So static would not work.

Ok, then it has to be dynamic.

@gschorcht
Copy link
Contributor

@Flole998 Could you add some hints or just a make command how the issue can be reproduced and tested in your description?

@Flole998
Copy link
Contributor Author

I guess environ is realloc()ed if it's resized, or at least that's what I would expect. So static would not work.

Ok, then it has to be dynamic.

That's just a wild guess, I haven't checked but allocating a single char buffer indicates that.

@Flole998
Copy link
Contributor Author

@Flole998 Could you add some hints or just a make command how the issue can be reproduced and tested in your description?

Just compiling on the ESP32S2 and running it with WiFi caused it to not start anymore, no output, nothing. When Null is written to that null-pointer it hangs.

The second commit fixed an issue that happens when the WiFi connection drops/disconnects.

@gschorcht
Copy link
Contributor

The second commit fixed an issue/assertion fail that happens when the WiFi connection drops/disconnects.

Are you sure, I haven't seen that? Anyway, it seems to be a bug.

@Flole998
Copy link
Contributor Author

The second commit fixed an issue/assertion fail that happens when the WiFi connection drops/disconnects.

Are you sure, I haven't seen that? Anyway, it seems to be a bug.

Yes, absolutely sure. It might only happen on WPA Enterprise connections though.

Copy link
Contributor

@gschorcht gschorcht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, works as expected.

@Flole998
Copy link
Contributor Author

@gschorcht It looks like you accidentally added a wrong "Fixes:" entry right at the beginning of the description, could you double check that? The issue seems unrelated

@gschorcht
Copy link
Contributor

bors merge

bors bot added a commit that referenced this pull request Jan 24, 2023
19192: cpu/esp32: fixes for boot issues and crashes on ESP32 r=gschorcht a=Flole998

### Contribution description

In syscalls_init() there is a call to malloc(), which will return NULL if the heap is not initialized before, causing the entire board to fail booting if MODULE_ESP_IDF_HEAP is used.

API of [vTaskDelete()](https://www.freertos.org/a00126.html) says, that if NULL is passed to vTaskDelete the calling task should be deleted.

This PR needs a backport to 2023.01.

### Testing procedure

Just compiling on the ESP32S2 and running it with WiFi caused it to not start anymore, no output, nothing. When Null is written to that null-pointer it hangs.

The second commit fixed an issue/assertion fail that happens when the WiFi connection drops/disconnects.

### Issues/PRs references

Issue was introduced with PR #19146 

Co-authored-by: Flole998 <[email protected]>
@kaspar030
Copy link
Contributor

bors cancel
bors merge

@bors
Copy link
Contributor

bors bot commented Jan 24, 2023

Canceled.

@bors
Copy link
Contributor

bors bot commented Jan 24, 2023

Build succeeded:

@gschorcht
Copy link
Contributor

@Flole998 Thanks for providing the bug fix.

@gschorcht gschorcht added the Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) label Jan 25, 2023
bors bot added a commit that referenced this pull request Jan 25, 2023
19196: cpu/esp32: fixes for boot issues and crashes on ESP32 [backport 2023.1] r=benpicco a=gschorcht

# Backport of PR #19192

### Contribution description

In `syscalls_init()` there is a call to `malloc()`, which will return `NULL` if the heap is not initialized before, causing the entire board to fail booting if module `esp_idf_heap` is used, for example if the WiFi network interface is used.

API of [vTaskDelete()](https://www.freertos.org/a00126.html) says, that if NULL is passed to vTaskDelete the calling task should be deleted.

This PR needs a backport to 2023.01.

### Testing procedure

```
USEMODULE=esp_idf_heap BOARD=esp32-wroom-32 make -C tests/malloc
````
should work now but hangs in startup without the PR.

### Issues/PRs references

Issue was introduced with PR #19146 

Co-authored-by: Flole998 <[email protected]>
@MrKevinWeiss MrKevinWeiss added this to the Release 2023.04 milestone Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ESP Platform: This PR/issue effects ESP-based platforms Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants