@@ -146,25 +146,58 @@ CellularError_t Cellular_CommonInit( CellularHandle_t * pCellularHandle,
146146 CellularError_t cellularStatus = CELLULAR_SUCCESS ;
147147 CellularContext_t * pContext = NULL ;
148148
149- /* Init the common library. */
150- cellularStatus = _Cellular_LibInit ( pCellularHandle , pCommInterface , pTokenTable );
151-
152- /* Init the module. */
153- if ( cellularStatus == CELLULAR_SUCCESS )
149+ if ( pCellularHandle == NULL )
154150 {
155- pContext = * pCellularHandle ;
156- cellularStatus = Cellular_ModuleInit ( pContext , & pContext -> pModuleContext ) ;
151+ LogError ( ( "Cellular_CommonInit pCellularHandle is NULL." ) ) ;
152+ cellularStatus = CELLULAR_INVALID_HANDLE ;
157153 }
158-
159- /* Setup UE, URC and query register status. */
160- if ( cellularStatus == CELLULAR_SUCCESS )
154+ else if ( pCommInterface == NULL )
161155 {
162- cellularStatus = Cellular_ModuleEnableUE ( pContext );
156+ LogError ( ( "Cellular_CommonInit pCommInterface is NULL." ) );
157+ cellularStatus = CELLULAR_BAD_PARAMETER ;
163158 }
164-
165- if ( cellularStatus == CELLULAR_SUCCESS )
159+ else if ( pTokenTable == NULL )
160+ {
161+ LogError ( ( "Cellular_CommonInit pTokenTable is NULL." ) );
162+ cellularStatus = CELLULAR_BAD_PARAMETER ;
163+ }
164+ else
166165 {
167- cellularStatus = Cellular_ModuleEnableUrc ( pContext );
166+ /* Init the common library. */
167+ cellularStatus = _Cellular_LibInit ( pCellularHandle , pCommInterface , pTokenTable );
168+
169+ if ( cellularStatus == CELLULAR_SUCCESS )
170+ {
171+ pContext = ( CellularContext_t * ) ( * pCellularHandle );
172+
173+ cellularStatus = Cellular_ModuleInit ( pContext , & pContext -> pModuleContext );
174+
175+ if ( cellularStatus == CELLULAR_SUCCESS )
176+ {
177+ cellularStatus = Cellular_ModuleEnableUE ( pContext );
178+
179+ if ( cellularStatus == CELLULAR_SUCCESS )
180+ {
181+ cellularStatus = Cellular_ModuleEnableUrc ( pContext );
182+ }
183+
184+ if ( cellularStatus != CELLULAR_SUCCESS )
185+ {
186+ /* Clean up the resource allocated by cellular module here if
187+ * Cellular_ModuleEnableUE or Cellular_ModuleEnableUrc returns
188+ * error. */
189+ ( void ) Cellular_ModuleCleanUp ( pContext );
190+ }
191+ }
192+
193+ if ( cellularStatus != CELLULAR_SUCCESS )
194+ {
195+ /* Clean up the resource in cellular common library if any of the
196+ * module port function returns error. Error returned by _Cellular_LibInit
197+ * is already handled in the implementation. */
198+ ( void ) _Cellular_LibCleanup ( pContext );
199+ }
200+ }
168201 }
169202
170203 return cellularStatus ;
0 commit comments