diff mbox

[i386] : Fix PR 68491, __get_cpuid with 0 level breaks on early 486

Message ID CAFULd4a3EHafFvUokfud2e4uVvg0aNXgvkBnE_wdR5jDu4aRmQ@mail.gmail.com
State New
Headers show

Commit Message

Uros Bizjak May 1, 2017, 3:42 p.m. UTC
Hello!

> I've been asked to send the patch against trunk here.

I have fixed the PR in a slightly different way.

2017-05-01  Uros Bizjak  <ubizjak@gmail.com>

    PR target/68491
    * config/i386/cpuid.h (__get_cpuid): Always return 0 when
    __get_cpuid_max returns 0.
    (__get_cpuid_count): Ditto.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Committed to mainline SVN, and will port to release branches in a
couple of days.

Uros.
diff mbox

Patch

Index: config/i386/cpuid.h
===================================================================
--- config/i386/cpuid.h	(revision 247428)
+++ config/i386/cpuid.h	(working copy)
@@ -246,8 +246,9 @@  __get_cpuid (unsigned int __leaf,
 	     unsigned int *__ecx, unsigned int *__edx)
 {
   unsigned int __ext = __leaf & 0x80000000;
+  unsigned int __maxlevel = __get_cpuid_max (__ext, 0);
 
-  if (__get_cpuid_max (__ext, 0) < __leaf)
+  if (__maxlevel == 0 || __maxlevel < __leaf)
     return 0;
 
   __cpuid (__leaf, *__eax, *__ebx, *__ecx, *__edx);
@@ -262,8 +263,9 @@  __get_cpuid_count (unsigned int __leaf, unsigned i
 		   unsigned int *__ecx, unsigned int *__edx)
 {
   unsigned int __ext = __leaf & 0x80000000;
+  unsigned int __maxlevel = __get_cpuid_max (__ext, 0);
 
-  if (__get_cpuid_max (__ext, 0) < __leaf)
+  if (__maxlevel == 0 || __maxlevel < __leaf)
     return 0;
 
   __cpuid_count (__leaf, __subleaf, *__eax, *__ebx, *__ecx, *__edx);