x86, cpufeature: Catch duplicate CPU feature strings
We had a case of duplicate CPU feature strings, a user space ABI violation, for almost two years. Make it a build error so that doesn't happen again. Link: http://lkml.kernel.org/r/4FE34BCB.5050305@linux.intel.com Cc: Jan Beulich <JBeulich@suse.com> Cc: Jean Delvare <khali@linux-fr.org>
This commit is contained in:
		
					parent
					
						
							
								4ad3341130
							
						
					
				
			
			
				commit
				
					
						55f6cb9d0b
					
				
			
		
					 1 changed files with 18 additions and 5 deletions
				
			
		| 
						 | 
					@ -11,22 +11,35 @@ open(OUT, "> $out\0") or die "$0: cannot create: $out: $!\n";
 | 
				
			||||||
print OUT "#include <asm/cpufeature.h>\n\n";
 | 
					print OUT "#include <asm/cpufeature.h>\n\n";
 | 
				
			||||||
print OUT "const char * const x86_cap_flags[NCAPINTS*32] = {\n";
 | 
					print OUT "const char * const x86_cap_flags[NCAPINTS*32] = {\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%features = ();
 | 
				
			||||||
 | 
					$err = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
while (defined($line = <IN>)) {
 | 
					while (defined($line = <IN>)) {
 | 
				
			||||||
	if ($line =~ /^\s*\#\s*define\s+(X86_FEATURE_(\S+))\s+(.*)$/) {
 | 
						if ($line =~ /^\s*\#\s*define\s+(X86_FEATURE_(\S+))\s+(.*)$/) {
 | 
				
			||||||
		$macro = $1;
 | 
							$macro = $1;
 | 
				
			||||||
		$feature = $2;
 | 
							$feature = "\L$2";
 | 
				
			||||||
		$tail = $3;
 | 
							$tail = $3;
 | 
				
			||||||
		if ($tail =~ /\/\*\s*\"([^"]*)\".*\*\//) {
 | 
							if ($tail =~ /\/\*\s*\"([^"]*)\".*\*\//) {
 | 
				
			||||||
			$feature = $1;
 | 
								$feature = "\L$1";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ($feature ne '') {
 | 
							next if ($feature eq '');
 | 
				
			||||||
			printf OUT "\t%-32s = \"%s\",\n",
 | 
					
 | 
				
			||||||
				"[$macro]", "\L$feature";
 | 
							if ($features{$feature}++) {
 | 
				
			||||||
 | 
								print STDERR "$in: duplicate feature name: $feature\n";
 | 
				
			||||||
 | 
								$err++;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							printf OUT "\t%-32s = \"%s\",%s\n", "[$macro]", $feature;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
print OUT "};\n";
 | 
					print OUT "};\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
close(IN);
 | 
					close(IN);
 | 
				
			||||||
close(OUT);
 | 
					close(OUT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if ($err) {
 | 
				
			||||||
 | 
						unlink($out);
 | 
				
			||||||
 | 
						exit(1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit(0);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue