Skip to content

Commit 7c4821a

Browse files
erwangoMaureenHelm
authored andcommitted
drivers/gpio: stm32: Rework configure function exit for dual core
With dual core handling introduction, we now need to take care to always release lock before exiting function. Rework gpio_stm32_config to take this into account. Additionally, since ENOSYS usage is resevred to system calls handling, replace with EIO. Signed-off-by: Erwan Gouriou <[email protected]>
1 parent f3bc116 commit 7c4821a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

drivers/gpio/gpio_stm32.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ static int gpio_stm32_config(struct device *dev, int access_op,
259259
u32_t pin, int flags)
260260
{
261261
const struct gpio_stm32_config *cfg = dev->config->config_info;
262+
int err = 0;
262263
int pincfg;
263264
int map_res;
264265

@@ -281,18 +282,21 @@ static int gpio_stm32_config(struct device *dev, int access_op,
281282
*/
282283
map_res = gpio_stm32_flags_to_conf(flags, &pincfg);
283284
if (map_res != 0) {
284-
return map_res;
285+
err = map_res;
286+
goto release_lock;
285287
}
286288

287289
if (gpio_stm32_configure(cfg->base, pin, pincfg, 0) != 0) {
288-
return -EIO;
290+
err = -EIO;
291+
goto release_lock;
289292
}
290293

291294
if (IS_ENABLED(CONFIG_EXTI_STM32) && (flags & GPIO_INT) != 0) {
292295

293296
if (stm32_exti_set_callback(pin, cfg->port,
294297
gpio_stm32_isr, dev) != 0) {
295-
return -EBUSY;
298+
err = -EBUSY;
299+
goto release_lock;
296300
}
297301

298302
gpio_stm32_enable_int(cfg->port, pin);
@@ -312,20 +316,23 @@ static int gpio_stm32_config(struct device *dev, int access_op,
312316
stm32_exti_trigger(pin, edge);
313317
} else {
314318
/* Level trigger interrupts not supported */
315-
return -ENOTSUP;
319+
err = -ENOTSUP;
320+
goto release_lock;
316321
}
317322

318323
if (stm32_exti_enable(pin) != 0) {
319-
return -ENOSYS;
324+
err = -EIO;
325+
goto release_lock;
320326
}
321327

322328
}
323329

330+
release_lock:
324331
#if defined(CONFIG_STM32H7_DUAL_CORE)
325332
LL_HSEM_ReleaseLock(HSEM, LL_HSEM_ID_1, 0);
326333
#endif /* CONFIG_STM32H7_DUAL_CORE */
327334

328-
return 0;
335+
return err;
329336
}
330337

331338
/**

0 commit comments

Comments
 (0)