Skip to content

Conversation

@szerwi
Copy link

@szerwi szerwi commented Nov 4, 2025

Description of Change

Delete _mac and _phy to free the resources if initialization of ETH failed or when calling ETHClass::end() and ETH is not fully initialized.

I found a bug that leads to w5500_tsk running when begin() for W5500 ETH module fails. When begin() fails, it makes it impossible to free the resources allocated in _mac and _phy and calling begin() one more time makes those resources to allocate again leading to a memory leak.

This PR adds clearing the _mac and _phy handles when one of them or _eth_handle fails to initialize during begin().
The fix also changes end() function to free those handles even if _eth_handle is null.

Test Scenarios

Tested on arduino-esp32 v3.3.2, ESP32 Dev Board and W5500 Ethernet module.
Tested on both scenarios, with Ethernet module connected to ESP32 and disconnected from power.
When the module is not powered, ETHClass::begin() fails with:

E (17:34:56.299) w5500.mac: w5500_reset(308): reset timeout
E (17:34:56.300) w5500.mac: emac_w5500_init(893): reset w5500 failed
E (17:34:56.310) esp_eth: esp_eth_driver_install(250): init mac failed
E (17:34:56.311) ARDUINO: SPI Ethernet driver install failed: 263

and deletes _mac and _phy handles, which results in the removal of w5500_tsk.

Before the fix, the w5500_tsk kept running resulting in constant w5500.mac: w5500_get_rx_received_size(238): read RX RSR failed errors.

Related links

- Delete _mac and _phy resources when initialization of ETH fails
- Delete _mac and _phy resources when calling ETHClass::end() and ETH is not fully initialized
@szerwi szerwi requested a review from me-no-dev as a code owner November 4, 2025 18:02
@CLAassistant
Copy link

CLAassistant commented Nov 4, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "fx(pr): Remove call to _delMacAndPhy on MAC creation failure":
    • type/action should be one of [change, ci, docs, feat, fix, refactor, remove, revert, test]

Please fix these commit messages - here are some basic tips:

  • follow Conventional Commits style
  • correct format of commit message should be: <type/action>(<scope/component>): <summary>, for example fix(esp32): Fixed startup timeout issue
  • allowed types are: change,ci,docs,feat,fix,refactor,remove,revert,test
  • sufficiently descriptive message summary should be between 10 to 72 characters and start with upper case letter
  • avoid Jira references in commit messages (unavailable/irrelevant for our customers)

TIP: Install pre-commit hooks and run this check when committing (uses the Conventional Precommit Linter).

👋 Hello szerwi, we appreciate your contribution to this project!


📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more.

🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project.

Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 089061b

@TD-er
Copy link
Contributor

TD-er commented Nov 4, 2025

Purely based on your description, I think I may have ran into the issues you describe.
So that would be great if those are fixed by this PR.
Will try and test tomorrow.

_mac = esp_eth_mac_new_esp32(&mac_config, &eth_mac_config);
if (_mac == NULL) {
log_e("esp_eth_mac_new_esp32 failed");
_delMacAndPhy();
Copy link
Member

Choose a reason for hiding this comment

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

mac is null and phy has not been initialized yet. This is not needed here

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

Memory usage test (comparing PR against master branch)

The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.

MemoryFLASH [bytes]FLASH [%]RAM [bytes]RAM [%]
TargetDECINCDECINCDECINCDECINC
ESP32C50⚠️ +760.00⚠️ +0.01000.000.00
ESP32P40⚠️ +740.00⚠️ +0.01000.000.00
ESP32S30⚠️ +680.00⚠️ +0.01000.000.00
ESP32S20⚠️ +680.00⚠️ +0.01000.000.00
ESP32C30⚠️ +760.00⚠️ +0.01000.000.00
ESP32C60⚠️ +760.00⚠️ +0.01000.000.00
ESP32H20⚠️ +740.00⚠️ +0.01000.000.00
ESP320⚠️ +800.00⚠️ +0.01000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32C5ESP32P4ESP32S3ESP32S2ESP32C3ESP32C6ESP32H2ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
libraries/Ethernet/examples/ETH_W5500_Arduino_SPI⚠️ +740⚠️ +740⚠️ +600⚠️ +600⚠️ +740⚠️ +740⚠️ +740⚠️ +720
libraries/Ethernet/examples/ETH_W5500_IDF_SPI⚠️ +740⚠️ +740⚠️ +600⚠️ +600⚠️ +740⚠️ +740⚠️ +740⚠️ +720
libraries/Ethernet/examples/ETH_WIFI_BRIDGE⚠️ +760⚠️ +740⚠️ +680⚠️ +680⚠️ +760⚠️ +760--⚠️ +800
libraries/Ethernet/examples/ETH_TLK110--⚠️ +640----------⚠️ +560
libraries/Ethernet/examples/ETH_LAN8720--------------⚠️ +560

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

Test Results

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit cf3d316.

♻️ This comment has been updated with latest results.

@me-no-dev me-no-dev added the Status: Pending Merge Pull Request is ready to be merged label Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Pending Merge Pull Request is ready to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants