Skip to content

Commit ef41627

Browse files
ubiedanashif
authored andcommitted
i3c: stm32: Prevent mutex deadlock on DAA failure
Make sure this function always unlocks bus_mutex. Signed-off-by: Luis Ubieda <[email protected]>
1 parent 4044e0e commit ef41627

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/i3c/i3c_stm32.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,7 @@ static int i3c_stm32_do_daa(const struct device *dev)
10471047
const struct i3c_stm32_config *config = dev->config;
10481048
struct i3c_stm32_data *data = dev->data;
10491049
I3C_TypeDef *i3c = config->i3c;
1050+
int ret = 0;
10501051

10511052
k_mutex_lock(&data->bus_mutex, K_FOREVER);
10521053

@@ -1068,20 +1069,23 @@ static int i3c_stm32_do_daa(const struct device *dev)
10681069

10691070
/* Wait for DAA to finish */
10701071
if (k_sem_take(&data->device_sync_sem, STM32_I3C_TRANSFER_TIMEOUT) != 0) {
1071-
return -ETIMEDOUT;
1072+
ret = -ETIMEDOUT;
1073+
goto i3c_stm32_do_daa_ending;
10721074
}
10731075

10741076
if (data->msg_state == STM32_I3C_MSG_ERR) {
10751077
i3c_stm32_clear_err(dev, false);
10761078
/* Enable TXFNF interrupt in case an error occurred before it was enabled by RXFNE
10771079
*/
10781080
LL_I3C_EnableIT_TXFNF(i3c);
1079-
return -EIO;
1081+
ret = -EIO;
1082+
goto i3c_stm32_do_daa_ending;
10801083
}
10811084

1085+
i3c_stm32_do_daa_ending:
10821086
k_mutex_unlock(&data->bus_mutex);
10831087

1084-
return 0;
1088+
return ret;
10851089
}
10861090

10871091
#ifdef CONFIG_I3C_STM32_DMA

0 commit comments

Comments
 (0)