diff options
author | Andreas Herrmann <andreas.herrmann3@amd.com> | 2011-04-05 20:24:41 +0200 |
---|---|---|
committer | Dave Jones <davej@redhat.com> | 2011-04-05 18:51:04 -0400 |
commit | b34a661cf5925866dbc9163b3c824f783f9da27b (patch) | |
tree | 9eeb06b87dd6fdcce21fd6ca0ddfa7db76e98cd8 | |
parent | ee0e5976ff01fd157a8abaf65e048e41c6440c3f (diff) |
cpuid: Fix pointer arithmetic
Commit 208fb9613c8c151b2885e89066a3eb22a977df6f (Fix up aliasing warnings.)
changed pointer arithmetic in one part of cpuid function from
- if (eax!=0) *eax = (*(unsigned *)(buffer ));
- if (ebx!=0) *ebx = (*(unsigned *)(buffer+ 4));
- if (ecx!=0) *ecx = (*(unsigned *)(buffer+ 8));
- if (edx!=0) *edx = (*(unsigned *)(buffer+12));
+ if (eax!=0) *eax = *(ptr)++;
+ if (ebx!=0) *ebx = *(ptr)++;
+ if (ecx!=0) *ecx = *(ptr)++;
+ if (edx!=0) *edx = *(ptr);
The post-increment is not equal to what was used before. This
causes generation of wrong cpuid information, e.g. lsmsr fails:
$ ./lsmsr -a -l
CPU not (yet) supported (vendor="(unknown)", family=16, model=10)
Fix this by pre-incrementing the pointer before it is dereferenced.
Signed-off-by: Andreas Herrmann <andreas.herrmann3@amd.com>
-rw-r--r-- | cpuid.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -191,10 +191,10 @@ void cpuid(unsigned int CPU_number, unsigned long long idx, perror(cpuname); exit(EXIT_FAILURE); } - if (eax!=0) *eax = *(ptr)++; - if (ebx!=0) *ebx = *(ptr)++; - if (ecx!=0) *ecx = *(ptr)++; - if (edx!=0) *edx = *(ptr); + if (eax!=0) *eax = *ptr; + if (ebx!=0) *ebx = *(++ptr); + if (ecx!=0) *ecx = *(++ptr); + if (edx!=0) *edx = *(++ptr); if (close(fh) == -1) { perror("close"); exit(EXIT_FAILURE); |