@@ -249,15 +249,14 @@ static int wolfkmod_load(void)
249249
250250 error = wolfkmod_init ();
251251 if (error != 0 ) {
252- return ( ECANCELED ) ;
252+ goto wolfkmod_load_out ;
253253 }
254254
255255 #ifndef NO_CRYPT_TEST
256256 error = wolfcrypt_test (NULL );
257257 if (error != 0 ) {
258258 printf ("error: wolfcrypt test failed: %d\n" , error );
259- (void )wolfkmod_cleanup ();
260- return (ECANCELED );
259+ goto wolfkmod_load_out ;
261260 }
262261 printf ("info: wolfCrypt self-test passed.\n" );
263262 #endif /* NO_CRYPT_TEST */
@@ -266,15 +265,19 @@ static int wolfkmod_load(void)
266265 error = benchmark_test (NULL );
267266 if (error != 0 ) {
268267 printf ("error: wolfcrypt benchmark failed: %d\n" , error );
269- (void )wolfkmod_cleanup ();
270- return (ECANCELED );
268+ goto wolfkmod_load_out ;
271269 }
272270 printf ("info: wolfCrypt benchmark passed.\n" );
273271 #endif /* WOLFSSL_KERNEL_BENCHMARKS */
274-
275272 printf ("info: libwolfssl loaded\n" );
276273
277- return (0 );
274+ wolfkmod_load_out :
275+ if (error != 0 ) {
276+ (void )wolfkmod_cleanup ();
277+ error = ECANCELED ;
278+ }
279+
280+ return (error );
278281}
279282
280283static int wolfkmod_unload (void )
@@ -435,7 +438,8 @@ static int wolfkdriv_attach(device_t dev)
435438
436439 ret = wolfkmod_init ();
437440 if (ret != 0 ) {
438- return (ECANCELED );
441+ error = ECANCELED ;
442+ goto attach_out ;
439443 }
440444
441445 /**
@@ -452,7 +456,8 @@ static int wolfkdriv_attach(device_t dev)
452456 if (softc -> crid < 0 ) {
453457 device_printf (dev , "error: crypto_get_driverid failed: %d\n" ,
454458 softc -> crid );
455- return (ENXIO );
459+ error = ENXIO ;
460+ goto attach_out ;
456461 }
457462
458463 /*
@@ -487,7 +492,7 @@ static int wolfkdriv_attach(device_t dev)
487492attach_out :
488493 if (error ) {
489494 wolfkdriv_unregister (softc );
490- error = ENXIO ;
495+ ( void ) wolfkmod_cleanup () ;
491496 }
492497
493498 return (error );
0 commit comments