Skip to contentSkip to conversation

cpufrequtils aperf: Fix MSR read on 32-bit

PATCH Applied Frank Arnold 3 participants 3 messages Dec 8, 2010 – Dec 12, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufrequtils aperf: Fix MSR read on 32-bit

The cpufreq-aperf command does not work on 32-bit systems. The reason for that is a wrong count argument passed to the read() call. Instead of the buffer size, the size of the pointer to the buffer is used. On 64-bit systems this just happened to work, because we need to read an 8 byte value and a pointer has a size of 8 bytes on 64-bit. On 32-bit systems only 4 bytes are read, which then triggers the error path.

---
 utils/aperf.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
utils/aperf.c +1 -1
index 1c64501..6302f5a 100644
@@ -100,7 +100,7 @@ static int read_msr(int cpu, unsigned int idx, unsigned long long *val)
 		return -1;
 	if (lseek(fd, idx, SEEK_CUR) == -1)
 		goto err;
-	if (read(fd, val, sizeof val) != sizeof *val)
+	if (read(fd, val, sizeof *val) != sizeof *val)
 		goto err;
 	close(fd);
 	return 0;
Signature · 1 line
1.7.2.3
Reviewed-by on v1 1/1
#1 lore raw

utils/aperf.c static int read_msr(int cpu, unsigned int idx,

Quoted 17 lines · On Wednesday 08 December 2010 17:39:14 Frank Arnold wrote:

The cpufreq-aperf command does not work on 32-bit systems. The reason for that is a wrong count argument passed to the read() call. Instead of the buffer size, the size of the pointer to the buffer is used. On 64-bit systems this just happened to work, because we need to read an 8 byte value and a pointer has a size of 8 bytes on 64-bit. On 32-bit systems only 4 bytes are read, which then triggers the error path.

---
 utils/aperf.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
utils/aperf.c +0 -0
index 1c64501..6302f5a 100644
@@ -100,7 +100,7 @@ static int read_msr(int cpu, unsigned int idx, 

unsigned long long *val)

utils/aperf.c static int read_msr(int cpu, unsigned int idx, unsigned long long *val) · line 103

Quoted 5 lines
utils/aperf.c +1 -1
 		return -1;
 	if (lseek(fd, idx, SEEK_CUR) == -1)
 		goto err;
-	if (read(fd, val, sizeof val) != sizeof *val)
+	if (read(fd, val, sizeof *val) != sizeof *val)
Reviewed-by [email protected]

Thanks,

Thomas