mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-21 21:55:34 +08:00
Fixed up nullptr handling
This commit is contained in:
@@ -1176,8 +1176,11 @@ mk_start(unsigned motors, char *device_path)
|
||||
// try i2c3 first
|
||||
g_mk = new MK(3, device_path);
|
||||
|
||||
if (g_mk && OK == g_mk->init(motors)) {
|
||||
fprintf(stderr, "[mkblctrl] scanning i2c3...\n");
|
||||
if (!g_mk)
|
||||
return -ENOMEM;
|
||||
|
||||
if (OK == g_mk->init(motors)) {
|
||||
warnx("[mkblctrl] scanning i2c3...\n");
|
||||
ret = g_mk->mk_check_for_blctrl(8, false, true);
|
||||
if (ret > 0) {
|
||||
return OK;
|
||||
@@ -1190,8 +1193,11 @@ mk_start(unsigned motors, char *device_path)
|
||||
// fallback to bus 1
|
||||
g_mk = new MK(1, device_path);
|
||||
|
||||
if (g_mk && OK == g_mk->init(motors)) {
|
||||
fprintf(stderr, "[mkblctrl] scanning i2c1...\n");
|
||||
if (!g_mk)
|
||||
return -ENOMEM;
|
||||
|
||||
if (OK == g_mk->init(motors)) {
|
||||
warnx("[mkblctrl] scanning i2c1...\n");
|
||||
ret = g_mk->mk_check_for_blctrl(8, false, true);
|
||||
if (ret > 0) {
|
||||
return OK;
|
||||
@@ -1201,7 +1207,7 @@ mk_start(unsigned motors, char *device_path)
|
||||
delete g_mk;
|
||||
g_mk = nullptr;
|
||||
|
||||
return -ENOMEM;
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user