From 8fe734c4938e4453cdffb9eb07ea05d393196cfd Mon Sep 17 00:00:00 2001 From: Veselin Georgiev Date: Tue, 4 Apr 2017 06:18:47 +0300 Subject: [PATCH] Fix previous commit based on comments in issue #89 thread. This should be correct now. --- libcpuid/rdmsr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libcpuid/rdmsr.c b/libcpuid/rdmsr.c index ec2e2cb..161cf26 100644 --- a/libcpuid/rdmsr.c +++ b/libcpuid/rdmsr.c @@ -631,8 +631,8 @@ static int get_amd_multipliers(struct msr_info_t *info, uint32_t pstate, uint64_ { 0x6, 8 }, { 0x7, 12 }, { 0x8, 16 }, - { CpuDid, 0 }, }; + int num_dids = (int) COUNT_OF(divisor_t); if (pstate < MSR_PSTATE_0 || MSR_PSTATE_7 < pstate) return 1; @@ -646,9 +646,9 @@ static int get_amd_multipliers(struct msr_info_t *info, uint32_t pstate, uint64_ err = cpu_rdmsr_range(info->handle, pstate, 8, 4, &CpuFid); err += cpu_rdmsr_range(info->handle, pstate, 3, 0, &CpuDid); i = 0; - while(divisor_t[i].did != CpuDid) + while (i < num_dids && divisor_t[i].did != CpuDid) i++; - if (divisor_t[i].divisor > 0) + if (i < num_dids) *multiplier = (uint64_t) ((CpuFid + 0x10) / divisor_t[i].divisor); else err++;