e7f01d1e3d
Several places were expecting that the value returned was the number of characters printed, not what would be printed if there was space. Fix it by using the scnprintf and vscnprintf variants we inherited from the kernel sources. Some corner cases where the number of printed characters were not accounted were fixed too. Reported-by: Anton Blanchard <anton@samba.org> Cc: Anton Blanchard <anton@samba.org> Cc: Eric B Munson <emunson@mgebm.net> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Yanmin Zhang <yanmin_zhang@linux.intel.com> Cc: stable@kernel.org Link: http://lkml.kernel.org/n/tip-kwxo2eh29cxmd8ilixi2005x@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
37 lines
858 B
C
37 lines
858 B
C
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "../../util/header.h"
|
|
|
|
#define __stringify_1(x) #x
|
|
#define __stringify(x) __stringify_1(x)
|
|
|
|
#define mfspr(rn) ({unsigned long rval; \
|
|
asm volatile("mfspr %0," __stringify(rn) \
|
|
: "=r" (rval)); rval; })
|
|
|
|
#define SPRN_PVR 0x11F /* Processor Version Register */
|
|
#define PVR_VER(pvr) (((pvr) >> 16) & 0xFFFF) /* Version field */
|
|
#define PVR_REV(pvr) (((pvr) >> 0) & 0xFFFF) /* Revison field */
|
|
|
|
int
|
|
get_cpuid(char *buffer, size_t sz)
|
|
{
|
|
unsigned long pvr;
|
|
int nb;
|
|
|
|
pvr = mfspr(SPRN_PVR);
|
|
|
|
nb = scnprintf(buffer, sz, "%lu,%lu$", PVR_VER(pvr), PVR_REV(pvr));
|
|
|
|
/* look for end marker to ensure the entire data fit */
|
|
if (strchr(buffer, '$')) {
|
|
buffer[nb-1] = '\0';
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|