-
Notifications
You must be signed in to change notification settings - Fork 7.7k
drivers: rtc: fix warning return value may be uninitialized on DS3231 #91672
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: main
Are you sure you want to change the base?
drivers: rtc: fix warning return value may be uninitialized on DS3231 #91672
Conversation
45c6d8d
to
4086387
Compare
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.
wouldn't the following be a more appropriate solution?
static int rtc_ds3231_modify_register(const struct device *dev, uint8_t reg, uint8_t *buf,
const uint8_t bitmask)
{
const struct rtc_ds3231_conf *config = dev->config;
if (bitmask != 255) {
uint8_t og_buf = 0;
int err = mfd_ds3231_i2c_get_registers(config->mfd, reg, &og_buf, 1);
if (err != 0) {
return err;
}
og_buf &= ~bitmask;
*buf &= bitmask;
og_buf |= *buf;
*buf = og_buf;
}
return mfd_ds3231_i2c_set_registers(config->mfd, reg, buf, 1);
}
Fix the return value may be uninitialized on the RTC DS3231 Signed-off-by: Jasper Jonker <jjasper.jonker@gmail.com>
4086387
to
21a0a80
Compare
|
const struct rtc_ds3231_conf *config = dev->config; | ||
|
||
if (bitmask != 255) { | ||
uint8_t og_buf = 0; | ||
|
||
err = mfd_ds3231_i2c_get_registers(config->mfd, reg, &og_buf, 1); | ||
int err = mfd_ds3231_i2c_get_registers(config->mfd, reg, &og_buf, 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.
due to MISRA compliance the err variable (and other variables put onto stack) has to be declared at the beginning of the function, otherwise changes look good :)
Fix the compiler warning "return value may be uninitialized" on the RTC DS3231