Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jasperjonker
Copy link
Contributor

Fix the compiler warning "return value may be uninitialized" on the RTC DS3231

Copy link
Member

@jilaypandya jilaypandya left a 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>
Copy link

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);
Copy link
Contributor

@bjarki-andreasen bjarki-andreasen Jun 27, 2025

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: RTC Real Time Clock
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants