-
-
Notifications
You must be signed in to change notification settings - Fork 186
I2C dispose fix #3121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I2C dispose fix #3121
Conversation
Automated fixes for code style.
WalkthroughThe changes update the data type of the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (10)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
targets/ESP32/_nanoCLR/System.Device.I2c/sys_dev_i2c_native_System_Device_I2c_I2cDevice.cpp (1)
121-128
: Add bounds check in disposal logic.The disposal logic should validate that the counter is positive before decrementing to prevent potential underflow issues.
- Esp_I2C_Initialised_Flag[bus]--; + if (Esp_I2C_Initialised_Flag[bus] > 0) + { + Esp_I2C_Initialised_Flag[bus]--; + } if (Esp_I2C_Initialised_Flag[bus] <= 0) { i2c_driver_delete(bus); Esp_I2C_Initialised_Flag[bus] = 0; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
targets/ESP32/_include/targetPAL_I2c.h
(1 hunks)targets/ESP32/_nanoCLR/System.Device.I2c/sys_dev_i2c_native_System_Device_I2c_I2cDevice.cpp
(2 hunks)targets/ESP32/_nanoCLR/targetPAL_I2c.cpp
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: nf-interpreter (Check_Code_Style)
- GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
- GitHub Check: nf-interpreter (Check_Build_Options)
🔇 Additional comments (3)
targets/ESP32/_include/targetPAL_I2c.h (1)
13-13
: LGTM! The data type change improves robustness.The change from
uint8_t
toint16_t
forEsp_I2C_Initialised_Flag
provides a much wider range for tracking I2C device initialization counts, which helps prevent potential overflow issues and allows for better detection of mismatched init/dispose calls.targets/ESP32/_nanoCLR/targetPAL_I2c.cpp (1)
10-16
: LGTM! Implementation is consistent with the header.The data type change to
int16_t
is properly implemented while maintaining the same initialization logic and cleanup behavior.targets/ESP32/_nanoCLR/System.Device.I2c/sys_dev_i2c_native_System_Device_I2c_I2cDevice.cpp (1)
97-98
: LGTM! Fixed device initialization tracking.Moving the increment operation outside the initialization block ensures accurate tracking of I2C device instances, fixing the issue where devices weren't being properly counted.
…4-3f35-45df-9084-25272177a879' into I2C-fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Good finding :-)
Description
When creating and disposing a number of I2CDevice objects the driver was disposed wrongly due to error in code counting open devices.
This fixes the counter logic.
The scan example should be changed to dispose I2CDevice objects otherwise memory is filled with unused objects until GC runs.
Other code should do the same when I2CDevcie is no longer in use.
Motivation and Context
How Has This Been Tested?
Tested with I2C scan program
Types of changes
Checklist
Summary by CodeRabbit