-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Description
I have read very carefully all related issues #6577 and PRs #6575, #6576 to figure out the answer to the following question:
For which purpose do the i2c_acquire
and i2c_release
function still have a return value. In fact they simply lock and unlock a mutex on all platforms. Since i2c_acquire
blocks until the mutex can be locked, the function will not fail.
Some implementations check whether the device parameter is valid, but there is no reason to have a return parameter for it. The recommended way is to check the device parameter is using assert
. In all other cases, all implementations simply return 0.
Disadvantages of the Current API
Since the API claims that the return value might be -1 in case of error, the return value would have to be checked.
The reality looks completely different. The return value is checked in less than 10 % (19 of 227) of i2c_acquire
function calls and in 0% (0 of 380) i2c_release
function calls.
Proposal
It is quite tedious to use something like the following over and over again just because the API defines return values, although the function can not cause an error.
if (i2c_aquire(I2C_DEV(0)) != 0) {
...
}
The return values should be removed. Otherwise, all drivers would need a rework for the case that the function can fail.