Fix dspInit() error handling in ndspInit().

The early return after dspInit() failure obviously keeps the refcount increased and the component loaded. This change properly unwinds all state changes.
This commit is contained in:
Patrik Rak 2019-10-04 14:03:37 +02:00 committed by GitHub
parent 8acc1871bc
commit 90016af3fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -479,23 +479,24 @@ Result ndspInit(void)
} }
rc = dspInit(); rc = dspInit();
if (R_FAILED(rc)) return rc; if (R_FAILED(rc)) goto _fail1;
rc = ndspInitialize(false); rc = ndspInitialize(false);
if (R_FAILED(rc)) goto _fail1; if (R_FAILED(rc)) goto _fail2;
LightEvent_Init(&sleepEvent, RESET_ONESHOT); LightEvent_Init(&sleepEvent, RESET_ONESHOT);
ndspThread = threadCreate(ndspThreadMain, 0x0, NDSP_THREAD_STACK_SIZE, 0x18, -2, true); ndspThread = threadCreate(ndspThreadMain, 0x0, NDSP_THREAD_STACK_SIZE, 0x18, -2, true);
if (!ndspThread) goto _fail2; if (!ndspThread) goto _fail3;
aptHook(&aptCookie, ndspAptHook, NULL); aptHook(&aptCookie, ndspAptHook, NULL);
return 0; return 0;
_fail2: _fail3:
ndspFinalize(false); ndspFinalize(false);
_fail1: _fail2:
dspExit(); dspExit();
_fail1:
if (componentFree) if (componentFree)
{ {
free((void*)componentBin); free((void*)componentBin);