Skip to content

Commit c7ba333

Browse files
mchehabgregkh
authored andcommitted
scripts: get_abi.pl: detect duplicated ABI definitions
The ABI should define only once each What. The current script logic assumes that. However, that's not the case, currently: there are several symbols with a generic definition, and per-driver ones. Better handle such cases, by preserving the cross-references with the files that define them, but also track such cases, producing warnings, as they should be fixed. Acked-by: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Link: https://lore.kernel.org/r/d7a73b8b3aae5b2bff9279996ff9ca4cdfc89196.1604042072.git.mchehab+huawei@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 234948b commit c7ba333

1 file changed

Lines changed: 58 additions & 27 deletions

File tree

scripts/get_abi.pl

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,16 @@ sub parse_abi {
114114
$space = "";
115115
$content =~ s/[,.;]$//;
116116

117+
push @{$symbols{$content}->{file}}, " $file:" . ($ln - 1);
118+
117119
if ($tag =~ m/what/) {
118120
$what .= ", " . $content;
119121
} else {
120122
if ($what) {
121123
parse_error($file, $ln, "What '$what' doesn't have a description", "") if (!$data{$what}->{description});
122124

123125
foreach my $w(split /, /, $what) {
124-
$symbols{$w} = $what;
126+
$symbols{$w}->{xref} = $what;
125127
};
126128
}
127129

@@ -139,18 +141,26 @@ sub parse_abi {
139141
if ($tag ne "" && $new_tag) {
140142
$tag = $new_tag;
141143

142-
$data{$what}->{line_no} = $ln;
143-
144144
if ($new_what) {
145145
@{$data{$what}->{label_list}} = @labels if ($data{$nametag}->{what});
146146
@labels = ();
147147
$label = "";
148148
$new_what = 0;
149149

150150
$data{$what}->{type} = $type;
151-
$data{$what}->{file} = $name;
152-
$data{$what}->{filepath} = $file;
151+
if (!defined($data{$what}->{file})) {
152+
$data{$what}->{file} = $name;
153+
$data{$what}->{filepath} = $file;
154+
} else {
155+
if ($name ne $data{$what}->{file}) {
156+
$data{$what}->{file} .= " " . $name;
157+
$data{$what}->{filepath} .= " " . $file;
158+
}
159+
}
153160
print STDERR "\twhat: $what\n" if ($debug > 1);
161+
$data{$what}->{line_no} = $ln;
162+
} else {
163+
$data{$what}->{line_no} = $ln if (!defined($data{$what}->{line_no}));
154164
}
155165

156166
if (!$what) {
@@ -218,7 +228,7 @@ sub parse_abi {
218228
parse_error($file, $ln, "What '$what' doesn't have a description", "") if (!$data{$what}->{description});
219229

220230
foreach my $w(split /, /,$what) {
221-
$symbols{$w} = $what;
231+
$symbols{$w}->{xref} = $what;
222232
};
223233
}
224234
close IN;
@@ -267,29 +277,20 @@ sub output_rest {
267277
$a cmp $b
268278
} keys %data) {
269279
my $type = $data{$what}->{type};
270-
my $file = $data{$what}->{file};
271-
my $filepath = $data{$what}->{filepath};
280+
281+
my @file = split / /, $data{$what}->{file};
282+
my @filepath = split / /, $data{$what}->{filepath};
272283

273284
if ($enable_lineno) {
274285
printf "#define LINENO %s%s#%s\n\n",
275-
$prefix, $data{$what}->{file},
286+
$prefix, $file[0],
276287
$data{$what}->{line_no};
277288
}
278289

279290
my $w = $what;
280291
$w =~ s/([\(\)\_\-\*\=\^\~\\])/\\$1/g;
281292

282-
$filepath =~ s,.*/(.*/.*),$1,;;
283-
$filepath =~ s,[/\-],_,g;;
284-
my $fileref = "abi_file_".$filepath;
285-
286-
if ($type eq "File") {
287-
my $bar = $w;
288-
$bar =~ s/./-/g;
289-
290-
print ".. _$fileref:\n\n";
291-
print "$w\n$bar\n\n";
292-
} else {
293+
if ($type ne "File") {
293294
printf ".. _%s:\n\n", $data{$what}->{label};
294295

295296
my @names = split /, /,$w;
@@ -307,7 +308,26 @@ sub output_rest {
307308
print "+-" . "-" x $len . "-+\n";
308309
}
309310

310-
print "\nDefined on file :ref:`$file <$fileref>`\n\n";
311+
print "\n";
312+
}
313+
314+
for (my $i = 0; $i < scalar(@filepath); $i++) {
315+
my $path = $filepath[$i];
316+
my $f = $file[$i];
317+
318+
$path =~ s,.*/(.*/.*),$1,;;
319+
$path =~ s,[/\-],_,g;;
320+
my $fileref = "abi_file_".$path;
321+
322+
if ($type eq "File") {
323+
my $bar = $w;
324+
$bar =~ s/./-/g;
325+
326+
print ".. _$fileref:\n\n";
327+
print "$w\n$bar\n\n";
328+
} else {
329+
print "Defined on file :ref:`$f <$fileref>`\n\n";
330+
}
311331
}
312332

313333
my $desc = "";
@@ -343,7 +363,7 @@ sub output_rest {
343363
printf "Has the following ABI:\n\n";
344364

345365
foreach my $content(@{$data{$what}->{symbols}}) {
346-
my $label = $data{$symbols{$content}}->{label};
366+
my $label = $data{$symbols{$content}->{xref}}->{label};
347367

348368
# Escape special chars from content
349369
$content =~s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g;
@@ -390,7 +410,7 @@ sub search_symbols {
390410
printf "Date:\t\t\t%s\n", $date if ($date);
391411
printf "Contact:\t\t%s\n", $contact if ($contact);
392412
printf "Users:\t\t\t%s\n", $users if ($users);
393-
print "Defined on file:\t$file\n\n";
413+
print "Defined on file(s):\t$file\n\n";
394414
print "Description:\n\n$desc";
395415
}
396416
}
@@ -410,12 +430,23 @@ sub search_symbols {
410430
#
411431
# Handles the command
412432
#
413-
if ($cmd eq "rest") {
414-
output_rest;
415-
} elsif ($cmd eq "search") {
433+
if ($cmd eq "search") {
416434
search_symbols;
417-
}
435+
} else {
436+
if ($cmd eq "rest") {
437+
output_rest;
438+
}
439+
440+
# Warn about duplicated ABI entries
441+
foreach my $what(sort keys %symbols) {
442+
my @files = @{$symbols{$what}->{file}};
443+
444+
next if (scalar(@files) == 1);
418445

446+
printf STDERR "Warning: $what is defined %d times: @files\n",
447+
scalar(@files);
448+
}
449+
}
419450

420451
__END__
421452

0 commit comments

Comments
 (0)