From patchwork Mon Jan 7 04:23:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 209855 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id D4F352C03AC for ; Mon, 7 Jan 2013 16:07:41 +1100 (EST) Received: by ozlabs.org (Postfix) id 6806F2C007A; Mon, 7 Jan 2013 16:07:13 +1100 (EST) Delivered-To: linuxppc-dev@ozlabs.org Received: by ozlabs.org (Postfix, from userid 1034) id 637E62C007B; Mon, 7 Jan 2013 16:07:13 +1100 (EST) From: Michael Ellerman To: nfont@linux.vnet.ibm.com Subject: [PATCH] lsprop: Fixes to work correctly when built little endian Date: Mon, 7 Jan 2013 15:23:30 +1100 Message-Id: <1357532610-19416-1-git-send-email-michael@ellerman.id.au> X-Mailer: git-send-email 1.7.10.4 Cc: linuxppc-dev@ozlabs.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add and use dt_swap_int() to byte swap on little endian. Also declare buf as unsigned char, so that we don't sign extend when printing values from it. Signed-off-by: Michael Ellerman Signed-off-by: Benjamin Herrenschmidt --- Ben, based on your patch, can you add your s-o-b? : https://lists.ozlabs.org/pipermail/linuxppc-dev/2008-May/056088.html --- src/lsprop.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/lsprop.c b/src/lsprop.c index 5969a97..38a8fa5 100644 --- a/src/lsprop.c +++ b/src/lsprop.c @@ -13,11 +13,22 @@ #include #include #include +#include +#include + +static inline unsigned int dt_swap_int(unsigned int data) +{ +#if __BYTE_ORDER == __LITTLE_ENDIAN + return bswap_32(data); +#else + return data; +#endif +} int recurse; int maxbytes = 128; int words_per_line = 0; -char *buf; +unsigned char *buf; void lsprop(FILE *f, char *name); void lsdir(char *name); @@ -183,7 +194,7 @@ void lsprop(FILE *f, char *name) } else if ((n & 3) == 0) { nw = n >> 2; if (nw == 1) { - i = *(int *)buf; + i = dt_swap_int(*(int *)buf); printf(" %.8x", i); if (i > -0x10000 && !(i >= 0 && i <= 9)) printf(" (%d)", i); @@ -201,7 +212,7 @@ void lsprop(FILE *f, char *name) if (i != 0) printf("\n\t\t"); for (j = 0; j < npl && i + j < nw; ++j) - printf(" %.8x", ((unsigned int *)buf)[i+j]); + printf(" %.8x", dt_swap_int(((unsigned int *)buf)[i+j])); } } } else {