@@ -656,6 +656,31 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
656
656
return 0 ;
657
657
}
658
658
659
+ /**
660
+ * utf16_le_to_7bit(): Naively converts a UTF-16LE string to 7-bit ASCII characters
661
+ * @in: input UTF-16LE string
662
+ * @size: size of the input string
663
+ * @out: output string ptr, should be capable to store @size+1 characters
664
+ *
665
+ * Description: Converts @size UTF16-LE symbols from @in string to 7-bit
666
+ * ASCII characters and stores them to @out. Adds trailing zero to @out array.
667
+ */
668
+ static void utf16_le_to_7bit (const __le16 * in , unsigned int size , u8 * out )
669
+ {
670
+ unsigned int i = 0 ;
671
+
672
+ out [size ] = 0 ;
673
+
674
+ while (i < size ) {
675
+ u8 c = le16_to_cpu (in [i ]) & 0xff ;
676
+
677
+ if (c && !isprint (c ))
678
+ c = '!' ;
679
+ out [i ] = c ;
680
+ i ++ ;
681
+ }
682
+ }
683
+
659
684
/**
660
685
* efi_partition(struct parsed_partitions *state)
661
686
* @state: disk parsed partitions
@@ -692,7 +717,6 @@ int efi_partition(struct parsed_partitions *state)
692
717
693
718
for (i = 0 ; i < le32_to_cpu (gpt -> num_partition_entries ) && i < state -> limit - 1 ; i ++ ) {
694
719
struct partition_meta_info * info ;
695
- unsigned label_count = 0 ;
696
720
unsigned label_max ;
697
721
u64 start = le64_to_cpu (ptes [i ].starting_lba );
698
722
u64 size = le64_to_cpu (ptes [i ].ending_lba ) -
@@ -713,14 +737,7 @@ int efi_partition(struct parsed_partitions *state)
713
737
/* Naively convert UTF16-LE to 7 bits. */
714
738
label_max = min (ARRAY_SIZE (info -> volname ) - 1 ,
715
739
ARRAY_SIZE (ptes [i ].partition_name ));
716
- info -> volname [label_max ] = 0 ;
717
- while (label_count < label_max ) {
718
- u8 c = ptes [i ].partition_name [label_count ] & 0xff ;
719
- if (c && !isprint (c ))
720
- c = '!' ;
721
- info -> volname [label_count ] = c ;
722
- label_count ++ ;
723
- }
740
+ utf16_le_to_7bit (ptes [i ].partition_name , label_max , info -> volname );
724
741
state -> parts [i + 1 ].has_info = true;
725
742
}
726
743
kfree (ptes );
0 commit comments