2424#define CRYPT_LUKS NULL
2525#endif
2626#endif
27+
2728#include <sys/mount.h>
2829#include <sys/prctl.h>
2930#include <sys/wait.h>
3233#include "ask-password-api.h"
3334#include "blkid-util.h"
3435#include "copy.h"
36+ #include "crypt-util.h"
3537#include "def.h"
3638#include "device-nodes.h"
3739#include "dissect-image.h"
@@ -850,7 +852,7 @@ static int decrypt_partition(
850852 DecryptedImage * d ) {
851853
852854 _cleanup_free_ char * node = NULL , * name = NULL ;
853- struct crypt_device * cd ;
855+ _cleanup_ ( crypt_freep ) struct crypt_device * cd = NULL ;
854856 int r ;
855857
856858 assert (m );
@@ -877,37 +879,28 @@ static int decrypt_partition(
877879 return log_debug_errno (r , "Failed to initialize dm-crypt: %m" );
878880
879881 r = crypt_load (cd , CRYPT_LUKS , NULL );
880- if (r < 0 ) {
881- log_debug_errno (r , "Failed to load LUKS metadata: %m" );
882- goto fail ;
883- }
882+ if (r < 0 )
883+ return log_debug_errno (r , "Failed to load LUKS metadata: %m" );
884884
885885 r = crypt_activate_by_passphrase (cd , name , CRYPT_ANY_SLOT , passphrase , strlen (passphrase ),
886886 ((flags & DISSECT_IMAGE_READ_ONLY ) ? CRYPT_ACTIVATE_READONLY : 0 ) |
887887 ((flags & DISSECT_IMAGE_DISCARD_ON_CRYPTO ) ? CRYPT_ACTIVATE_ALLOW_DISCARDS : 0 ));
888- if (r < 0 )
888+ if (r < 0 ) {
889889 log_debug_errno (r , "Failed to activate LUKS device: %m" );
890- if (r == - EPERM ) {
891- r = - EKEYREJECTED ;
892- goto fail ;
890+ return r == - EPERM ? - EKEYREJECTED : r ;
893891 }
894- if (r < 0 )
895- goto fail ;
896892
897893 d -> decrypted [d -> n_decrypted ].name = name ;
898894 name = NULL ;
899895
900896 d -> decrypted [d -> n_decrypted ].device = cd ;
897+ cd = NULL ;
901898 d -> n_decrypted ++ ;
902899
903900 m -> decrypted_node = node ;
904901 node = NULL ;
905902
906903 return 0 ;
907-
908- fail :
909- crypt_free (cd );
910- return r ;
911904}
912905
913906static int verity_partition (
@@ -919,7 +912,7 @@ static int verity_partition(
919912 DecryptedImage * d ) {
920913
921914 _cleanup_free_ char * node = NULL , * name = NULL ;
922- struct crypt_device * cd ;
915+ _cleanup_ ( crypt_freep ) struct crypt_device * cd = NULL ;
923916 int r ;
924917
925918 assert (m );
@@ -949,30 +942,27 @@ static int verity_partition(
949942
950943 r = crypt_load (cd , CRYPT_VERITY , NULL );
951944 if (r < 0 )
952- goto fail ;
945+ return r ;
953946
954947 r = crypt_set_data_device (cd , m -> node );
955948 if (r < 0 )
956- goto fail ;
949+ return r ;
957950
958951 r = crypt_activate_by_volume_key (cd , name , root_hash , root_hash_size , CRYPT_ACTIVATE_READONLY );
959952 if (r < 0 )
960- goto fail ;
953+ return r ;
961954
962955 d -> decrypted [d -> n_decrypted ].name = name ;
963956 name = NULL ;
964957
965958 d -> decrypted [d -> n_decrypted ].device = cd ;
959+ cd = NULL ;
966960 d -> n_decrypted ++ ;
967961
968962 m -> decrypted_node = node ;
969963 node = NULL ;
970964
971965 return 0 ;
972-
973- fail :
974- crypt_free (cd );
975- return r ;
976966}
977967#endif
978968
0 commit comments