Skip to content

Commit e943878

Browse files
etienne-lmsjhedberg
authored andcommitted
drivers: eeprom: stm32: don't mix HAL return value and errno
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(). Remove printing of HAL_FLASHEx_DATAEEPROM_Lock() error code since not very useful. Signed-off-by: Etienne Carriere <[email protected]>
1 parent 0e39d34 commit e943878

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

drivers/eeprom/eeprom_stm32.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static int eeprom_stm32_write(const struct device *dev, off_t offset,
5757
{
5858
const struct eeprom_stm32_config *config = dev->config;
5959
const uint8_t *pbuf = buf;
60-
HAL_StatusTypeDef ret = HAL_OK;
60+
HAL_StatusTypeDef hal_ret;
6161

6262
if (!len) {
6363
return 0;
@@ -73,29 +73,30 @@ static int eeprom_stm32_write(const struct device *dev, off_t offset,
7373
HAL_FLASHEx_DATAEEPROM_Unlock();
7474

7575
while (len) {
76-
ret = HAL_FLASHEx_DATAEEPROM_Program(
77-
FLASH_TYPEPROGRAMDATA_BYTE,
78-
config->addr + offset, *pbuf);
79-
if (ret) {
80-
LOG_ERR("failed to write to EEPROM (err %d)", ret);
76+
hal_ret = HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE,
77+
config->addr + offset, *pbuf);
78+
if (hal_ret != HAL_OK) {
79+
LOG_ERR("failed to write to EEPROM (err %d)", hal_ret);
8180
HAL_FLASHEx_DATAEEPROM_Lock();
8281
k_mutex_unlock(&lock);
83-
return ret;
82+
return -EIO;
8483
}
8584

8685
pbuf++;
8786
offset++;
8887
len--;
8988
}
9089

91-
ret = HAL_FLASHEx_DATAEEPROM_Lock();
92-
if (ret) {
93-
LOG_ERR("failed to lock EEPROM (err %d)", ret);
94-
}
90+
hal_ret = HAL_FLASHEx_DATAEEPROM_Lock();
9591

9692
k_mutex_unlock(&lock);
9793

98-
return ret;
94+
if (hal_ret != HAL_OK) {
95+
LOG_ERR("failed to lock EEPROM");
96+
return -EIO;
97+
}
98+
99+
return 0;
99100
}
100101

101102
static size_t eeprom_stm32_size(const struct device *dev)

0 commit comments

Comments
 (0)