Skip to content

Conversation

etienne-lms
Copy link
Contributor

Correct eeprom_stm32_write() to return a valid errno instead of mixing HAL return values and errno return values.

Clarify HAL return value is of type HAL_StatusTypeDef and not an int in eeprom_stm32_read().

Comment on lines 73 to 75
if (HAL_FLASHEx_DATAEEPROM_Unlock() != HAL_OK) {
return -EIO;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: there should be consistency about whether driver uses

if (xxx() != HAL_OK) {
   ...fail
}

or

ret = xxx();
if (ret != HAL_OK) {
   ...fail
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think when the return value is needed only to be tested straight, it's not really needed to be stored then tested, as here. Is this function, below, the return value is used not only with an if() instruction.
That said, I'm fine using the latter way (among the 2 you mentioned above).

if (ret != HAL_OK) {
LOG_ERR("failed to write to EEPROM (err %d)", ret);
HAL_FLASHEx_DATAEEPROM_Lock();
k_mutex_unlock(&lock);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seomthing's wrong in the 1st commit. EEPROM should be locked back. I'll fix.

Comment on lines 73 to 75
if (HAL_FLASHEx_DATAEEPROM_Unlock() != HAL_OK) {
return -EIO;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think when the return value is needed only to be tested straight, it's not really needed to be stored then tested, as here. Is this function, below, the return value is used not only with an if() instruction.
That said, I'm fine using the latter way (among the 2 you mentioned above).

Correct eeprom_stm32_write() to return a valid errno instead
of mixing HAL return values and errno return values.

Clarify HAL return value is of type HAL_StatusTypeDef and not an
int in eeprom_stm32_read().

Signed-off-by: Etienne Carriere <[email protected]>
Add missing test of HAL_FLASHEx_DATAEEPROM_Unlock() return value

Signed-off-by: Etienne Carriere <[email protected]>
@etienne-lms etienne-lms force-pushed the stm32-hal-ret-eeprom branch from bfde38d to bc8ef62 Compare October 9, 2025 15:32
Copy link

sonarqubecloud bot commented Oct 9, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants