-
Notifications
You must be signed in to change notification settings - Fork 2k
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
drivers/periph_i2c: let i2c_acquire return void #17275
drivers/periph_i2c: let i2c_acquire return void #17275
Conversation
0c466ca
to
47d4383
Compare
drivers/lis2dh12/lis2dh12.c
Outdated
@@ -184,9 +184,13 @@ int lis2dh12_init(lis2dh12_t *dev, const lis2dh12_params_t *params) | |||
/* enable all axes, set sampling rate and scale */ | |||
LIS2DH12_CTRL_REG1_t reg1 = {0}; | |||
|
|||
/* cppcheck-suppress unreadVariable; (reason: union type is used for read) */ |
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.
@maribu Here we have no volatile variable definitions, but cppcheck
complains anyway. So it looks like cppcheck
does not recognize the type unit
after all. Missing header files are probably not the problem in this case.
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.
@maribu I played a bit with cppcheck
and the single file that made the problems using command:
cppcheck --std=c99 --enable=style --force --error-exitcode=2 --quiet -j 1 --inline-suppr \
--suppress=unusedStructMember --template '{file}:{line}: {severity} ({id}): {message}' \
drivers/lis2dh12/lis2dh12.c
cppcheck
version 1.82 (local Ubuntu 18.04 LTS version) doesn't show any warnings.
cppcheck
version 1.90 in RIOT docker shows these 32 warnings as in CI.
cppcheck
version 2.6 (newest version from sourgeforge.net
) shows only 5 warnings.
Adding the required include pathes
-I drivers/include -I drivers/lis2dh12/include/
doesn't help with cppcheck
version 1.90 but solves all warnings with cppcheck
version 2.6.
So it seems that we need correct include pathes as well as a newer cppcheck
version in CI.
drivers/lis2dh12/lis2dh12.c
Outdated
fifo_reg.bit.FM = LIS2DH12_FIFO_MODE_BYPASS; | ||
|
||
/* switch to Bypass mode */ | ||
_write(dev, REG_FIFO_CTRL_REG, fifo_reg.reg); | ||
|
||
/* cppcheck-suppress redundantAssignment; (reason: union type is used for read) */ |
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.
@maribu Here I don't know how to solve the cppcheck
error.
If I use cppcheck-suppress redundantAssignment
, cppcheck
is complaining about unread variable. If I replace cppcheck-suppress redundantAssignment
by cppcheck-suppress unreadVariable
, it is complaining about redundant assignment.
How can this be solved?
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.
Solved. I just have to use multiple cppcheck-suppress
lines for all different warning that are given here.
Failed run tests are not related to this PR. Therefore, I remove the |
47d4383
to
3f6024c
Compare
Since all implementations simply return 0 and most drivers do not check the return value, it is better to return void and use an assert to ensure that the given device identifier and given device parameters are correct.
Make all `spi_acquire` implementations return `void` and add assertions to check for valid device identifier where missing.
3f6024c
to
b7dda22
Compare
Thanks |
See [1]. [1] RIOT-OS/RIOT#17275 Signed-off-by: Gilles DOFFE <g.doffe@gmail.com>
See [1]. [1] RIOT-OS/RIOT#17275 Signed-off-by: Gilles DOFFE <g.doffe@gmail.com>
See [1]. [1] RIOT-OS/RIOT#17275 Signed-off-by: Gilles DOFFE <g.doffe@gmail.com>
See [1]. [1] RIOT-OS/RIOT#17275 Signed-off-by: Gilles DOFFE <g.doffe@gmail.com>
Contribution description
As follow-up of PR #15902 and based on the discussion in issue #10673 this PR
int i2c_acquire(...)
tovoid i2c_acquire(...)
becauseassert()
where it is missing to ensure that a correct I2C device identifier is used<driver>_init()
.Testing procedure
Compilation and tests in Murdock should work.
Issues/PRs references
Follow-up of #15902
Fixes #10673