scripts/get_abi.pl: avoid creating duplicate names
authorMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Thu, 20 Jun 2019 17:23:02 +0000 (14:23 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Jun 2019 14:57:45 +0000 (16:57 +0200)
The file the Documentation/ABI/testing/sysfs-class-power has
voltage_min, voltage_max and voltage_now symbols duplicated.

They are defined first for "General Properties" and then for
"USB Properties".

This cause those warnings:

get_abi.pl rest --dir $srctree/Documentation/ABI/testing:26933: WARNING: Duplicate explicit target name: "abi_sys_class_power_supply_supply_name_voltage_max".
get_abi.pl rest --dir $srctree/Documentation/ABI/testing:26968: WARNING: Duplicate explicit target name: "abi_sys_class_power_supply_supply_name_voltage_min".
get_abi.pl rest --dir $srctree/Documentation/ABI/testing:27008: WARNING: Duplicate explicit target name: "abi_sys_class_power_supply_supply_name_voltage_now".

And, as the references are not valid, it will also generate
warnings about links to undefined references.

Fix it by storing labels into a hash table and, when a duplicated
one is found, appending random characters at the end.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
scripts/get_abi.pl

index 116f0c33c16dbae7430fe49256adc7e3ac5f695b..329ace635ac2b6561e8399deb8abc18e2e184cb9 100755 (executable)
@@ -194,6 +194,8 @@ sub parse_abi {
 # Outputs the book on ReST format
 #
 
+my %labels;
+
 sub output_rest {
        foreach my $what (sort {
                                ($data{$a}->{type} eq "File") cmp ($data{$b}->{type} eq "File") ||
@@ -217,6 +219,13 @@ sub output_rest {
                        $label =~ s,_+,_,g;
                        $label =~ s,_$,,;
 
+                       # Avoid duplicated labels
+                       while (defined($labels{$label})) {
+                           my @chars = ("A".."Z", "a".."z");
+                           $label .= $chars[rand @chars];
+                       }
+                       $labels{$label} = 1;
+
                        $data{$what}->{label} .= $label;
 
                        printf ".. _%s:\n\n", $label;