From 6359c8c008a4ecfa12c66dd94d145aa86fb14be5 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Mon, 25 Apr 2022 11:53:22 -0400 Subject: [PATCH] mavlink: shell expand locking (#19308) - on some H7 boards (cuav x7pro tested) there's an occasional hard fault when starting the mavlink shell that is no longer reproducible with the slightly expanded locking - this is likely just changing the timing (holding the sched lock for longer), but this should be harmless for now until we can identify the root cause --- src/modules/mavlink/mavlink_main.cpp | 14 ++++++++------ src/modules/mavlink/mavlink_shell.cpp | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/modules/mavlink/mavlink_main.cpp b/src/modules/mavlink/mavlink_main.cpp index d6ee7dd7a4..26b159829e 100644 --- a/src/modules/mavlink/mavlink_main.cpp +++ b/src/modules/mavlink/mavlink_main.cpp @@ -1334,18 +1334,20 @@ MavlinkShell * Mavlink::get_shell() { if (!_mavlink_shell) { - _mavlink_shell = new MavlinkShell(); + MavlinkShell *shell = new MavlinkShell(); - if (!_mavlink_shell) { + if (!shell) { PX4_ERR("Failed to allocate a shell"); } else { - int ret = _mavlink_shell->start(); + int ret = shell->start(); - if (ret != 0) { + if (ret == 0) { + _mavlink_shell = shell; + + } else { PX4_ERR("Failed to start shell (%i)", ret); - delete _mavlink_shell; - _mavlink_shell = nullptr; + delete shell; } } } diff --git a/src/modules/mavlink/mavlink_shell.cpp b/src/modules/mavlink/mavlink_shell.cpp index 6203e0f28e..f0feafa623 100644 --- a/src/modules/mavlink/mavlink_shell.cpp +++ b/src/modules/mavlink/mavlink_shell.cpp @@ -148,14 +148,14 @@ int MavlinkShell::start() close(fd_backups[i]); } -#ifdef __PX4_NUTTX - sched_unlock(); -#endif /* __PX4_NUTTX */ - //close unused pipe fd's close(_shell_fds[0]); close(_shell_fds[1]); +#ifdef __PX4_NUTTX + sched_unlock(); +#endif /* __PX4_NUTTX */ + return ret; }