* [PATCH] lsprop: Fixes to work correctly when built little endian
@ 2013-01-07 4:23 Michael Ellerman
2013-01-08 2:12 ` Benjamin Herrenschmidt
0 siblings, 1 reply; 3+ messages in thread
From: Michael Ellerman @ 2013-01-07 4:23 UTC (permalink / raw)
To: nfont; +Cc: 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 <michael@ellerman.id.au>
---
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 <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
+#include <endian.h>
+#include <byteswap.h>
+
+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 {
--
1.7.10.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] lsprop: Fixes to work correctly when built little endian
2013-01-07 4:23 [PATCH] lsprop: Fixes to work correctly when built little endian Michael Ellerman
@ 2013-01-08 2:12 ` Benjamin Herrenschmidt
2013-01-08 3:55 ` Nathan Fontenot
0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Herrenschmidt @ 2013-01-08 2:12 UTC (permalink / raw)
To: Michael Ellerman; +Cc: nfont, linuxppc-dev
On Mon, 2013-01-07 at 15:23 +1100, Michael Ellerman wrote:
> 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 <michael@ellerman.id.au>
> ---
>
> Ben, based on your patch, can you add your s-o-b? :
> https://lists.ozlabs.org/pipermail/linuxppc-dev/2008-May/056088.html
I didn't know powerpc-utils required sob's :-)
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> ---
> 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 <sys/stat.h>
> #include <sys/types.h>
> #include <dirent.h>
> +#include <endian.h>
> +#include <byteswap.h>
> +
> +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 {
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] lsprop: Fixes to work correctly when built little endian
2013-01-08 2:12 ` Benjamin Herrenschmidt
@ 2013-01-08 3:55 ` Nathan Fontenot
0 siblings, 0 replies; 3+ messages in thread
From: Nathan Fontenot @ 2013-01-08 3:55 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: linuxppc-dev
On 01/07/2013 08:12 PM, Benjamin Herrenschmidt wrote:
> On Mon, 2013-01-07 at 15:23 +1100, Michael Ellerman wrote:
>> 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 <michael@ellerman.id.au>
>> ---
>>
>> Ben, based on your patch, can you add your s-o-b? :
>> https://lists.ozlabs.org/pipermail/linuxppc-dev/2008-May/056088.html
>
> I didn't know powerpc-utils required sob's :-)
Not technically, it's more a CYA thing. It (hopefully) keeps big blue legal
happy, which keeps me happy.
-Nathan
>
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
>
>> ---
>> 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 <sys/stat.h>
>> #include <sys/types.h>
>> #include <dirent.h>
>> +#include <endian.h>
>> +#include <byteswap.h>
>> +
>> +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 {
>
>
--
-Nathan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-01-08 3:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-07 4:23 [PATCH] lsprop: Fixes to work correctly when built little endian Michael Ellerman
2013-01-08 2:12 ` Benjamin Herrenschmidt
2013-01-08 3:55 ` Nathan Fontenot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).