Skip to content

Commit f81b1e8

Browse files
etienne-lmsjhedberg
authored andcommitted
drivers: eeprom: stm32: test HAL return value
Add missing test of HAL_FLASHEx_DATAEEPROM_Unlock() return value. By the way, add a error trace message when failing to relock the EEPROM after we failed to program it. Signed-off-by: Etienne Carriere <[email protected]>
1 parent e943878 commit f81b1e8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

drivers/eeprom/eeprom_stm32.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,21 @@ static int eeprom_stm32_write(const struct device *dev, off_t offset,
7070

7171
k_mutex_lock(&lock, K_FOREVER);
7272

73-
HAL_FLASHEx_DATAEEPROM_Unlock();
73+
hal_ret = HAL_FLASHEx_DATAEEPROM_Unlock();
74+
if (hal_ret != HAL_OK) {
75+
LOG_ERR("failed to unlock to EEPROM");
76+
goto out;
77+
}
7478

7579
while (len) {
7680
hal_ret = HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE,
7781
config->addr + offset, *pbuf);
7882
if (hal_ret != HAL_OK) {
7983
LOG_ERR("failed to write to EEPROM (err %d)", hal_ret);
80-
HAL_FLASHEx_DATAEEPROM_Lock();
81-
k_mutex_unlock(&lock);
82-
return -EIO;
84+
if (HAL_FLASHEx_DATAEEPROM_Lock() != HAL_OK) {
85+
LOG_ERR("failed to lock to EEPROM");
86+
}
87+
goto out;
8388
}
8489

8590
pbuf++;
@@ -88,11 +93,14 @@ static int eeprom_stm32_write(const struct device *dev, off_t offset,
8893
}
8994

9095
hal_ret = HAL_FLASHEx_DATAEEPROM_Lock();
96+
if (hal_ret != HAL_OK) {
97+
LOG_ERR("failed to lock EEPROM");
98+
}
9199

100+
out:
92101
k_mutex_unlock(&lock);
93102

94103
if (hal_ret != HAL_OK) {
95-
LOG_ERR("failed to lock EEPROM");
96104
return -EIO;
97105
}
98106

0 commit comments

Comments
 (0)