From 9ce0158b88cc7b9a21bcddeb0d0f4af58738a297 Mon Sep 17 00:00:00 2001 From: Xorg Date: Wed, 18 May 2016 16:32:40 +0200 Subject: [PATCH] Use get_bits_value() inside cpu_rdmsr_range() --- libcpuid/rdmsr.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/libcpuid/rdmsr.c b/libcpuid/rdmsr.c index 21aac36..9ddccd6 100644 --- a/libcpuid/rdmsr.c +++ b/libcpuid/rdmsr.c @@ -420,35 +420,30 @@ static int perfmsr_measure(struct msr_driver_t* handle, int msr) #define MSR_PSTATE_S 0xC0010063 #define MSR_PSTATE_0 0xC0010064 -static int get_bits_value(uint64_t val, int highbit, int lowbit) +static uint64_t get_bits_value(uint64_t val, int highbit, int lowbit) { uint64_t data = val; - int bits = highbit - lowbit + 1; - if(bits < 64){ - data >>= lowbit; - data &= (1ULL<>= lowbit; + data &= (1ULL << bits) - 1; } - return (int) data; + + return data; } static int cpu_rdmsr_range(struct msr_driver_t* handle, uint32_t msr_index, uint8_t highbit, uint8_t lowbit, uint64_t* result) { - const uint8_t bits = highbit - lowbit + 1; - if(highbit > 63 || lowbit > highbit) return set_error(ERR_INVRANGE); if(cpu_rdmsr(handle, msr_index, result)) return set_error(ERR_HANDLE_R); - if(bits < 64) - { - /* Show only part of register */ - *result >>= lowbit; - *result &= (1ULL << bits) - 1; - } - + *result = get_bits_value(*result, highbit, lowbit); return 0; }