-
Notifications
You must be signed in to change notification settings - Fork 8k
Implement i2c_master_multi_buffer_transmit_receive() (IDFGH-16889) #17956
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
base: master
Are you sure you want to change the base?
Implement i2c_master_multi_buffer_transmit_receive() (IDFGH-16889) #17956
Conversation
👋 Hello 0xFEEDC0DE64, 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 ...
Review and merge process you can expect ...
|
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.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| { | ||
| ESP_RETURN_ON_FALSE(i2c_dev != NULL, ESP_ERR_INVALID_ARG, TAG, "i2c handle not initialized"); | ||
| ESP_RETURN_ON_FALSE(array_size <= (SOC_I2C_CMD_REG_NUM - 2 - 3), ESP_ERR_INVALID_ARG, TAG, "i2c command list cannot contain so many commands"); | ||
| ESP_RETURN_ON_FALSE(buffer_info_array != NULL, ESP_ERR_INVALID_ARG, TAG, "buffer info array is empty"); |
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.
Bug: Missing validation causes integer underflow when read_size is zero
The new function i2c_master_multi_buffer_transmit_receive() lacks validation for read_buffer and read_size, unlike the similar functions i2c_master_transmit_receive() and i2c_master_receive() which check (read_buffer != NULL) && (read_size > 0). When read_size is zero, the expression read_size - 1 causes unsigned integer underflow to SIZE_MAX, and read_buffer + read_size - 1 creates an out-of-bounds pointer.
Additional Locations (1)
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.
Dear AI, I copied the function basically from the one above. I have no interest in fixing this issue when it was already present (and accepted?) previously.
This PR adds a new method to the new i2c driver to first send multiple buffers, and then read a single buffer.
Note
Adds
i2c_master_multi_buffer_transmit_receive()to perform multiple writes followed by a read, with sync/async support and public header docs.i2c_master_multi_buffer_transmit_receive()incomponents/esp_driver_i2c/i2c_master.cto build an I2C op sequence:RESTART→ multipleWRITEbuffers →RESTART→READ(ACK then NACK last byte) →STOP, with argument checks and sync/async dispatch.i2c_master_multi_buffer_transmit_receive()incomponents/esp_driver_i2c/include/driver/i2c_master.h.Written by Cursor Bugbot for commit 81900f4. This will update automatically on new commits. Configure here.