Re: Xawtv sparc 64bit fix

2010-04-26 Thread Guy Martin

Hi Mauro,

Thanks for the feedback. Here is the fixed version.

Cheers,
  Guy

On Sun, 25 Apr 2010 13:55:44 -0300
Mauro Carvalho Chehab  wrote:

> Guy Martin wrote:
> > 
> > Hi,
> > 
> > Here is an old patch of mine which I tried to submit in 2006 but
> > never got it. I didn't really know who was xawtv's maintainer at
> > that time.
> > 
> > 
> > 
> > The calculation to compute the 64bit alignement in struct-dump.c is
> > plain wrong. The alignment has to be computed with a structure
> > containing a char and then a 64bit integer and then substract the
> > pointer of the 64bit int to the one of the char.
> > 
> > This fix v4l-info doing a Bus Error on sparc with structs containing
> > 64 bit integer following a non 64bit field aligned on a 8 byte
> > boundary like v4l2_standard.
> > 
> > 
> > Signed-off-by: Guy Martin 
> 
> I tried to compile it (x86_64 arch) and your patch produced two
> warnings:
> 
> ../structs/struct-dump.c: In function ‘print_struct’:
> ../structs/struct-dump.c:48: warning: cast from pointer to integer of
> different size ../structs/struct-dump.c:48: warning: cast from
> pointer to integer of different size
> 
> Could you please fix it?
> 
> > 
> > 
> > Regards,
> >   Guy
> > 
> 
> 

diff --git a/structs/struct-dump.c b/structs/struct-dump.c
index 0ee7fc8..49bfe2d 100644
--- a/structs/struct-dump.c
+++ b/structs/struct-dump.c
@@ -43,7 +43,9 @@ int print_struct(FILE *fp, struct struct_desc *desc, void *data,
 	int16_t  s16;
 	uint8_t  u8;
 	int8_t   s8;
-	int al = sizeof(long)-1; /* struct + union + 64bit alignment */
+	struct al64_t { char c; uint64_t t; } al64_t;
+	int al = sizeof(long)-1; /* struct + union */
+	int al64 = (unsigned long)&al64_t.t - (unsigned long)&al64_t.c - 1; /* 64 bit alignement */
 	void *p;
 	unsigned int i,j,first;
 
@@ -149,7 +151,7 @@ int print_struct(FILE *fp, struct struct_desc *desc, void *data,
 			ptr += 4;
 			break;
 		case BITS64:
-			ptr = (void*)(((intptr_t)ptr + al) & ~al);
+			ptr = (void*)(((intptr_t)ptr + al64) & ~al64);
 			u64 = *((uint64_t*)ptr);
 			first = 1;
 			fprintf(fp,"0x%" PRIx64 " [",u64);
@@ -166,13 +168,13 @@ int print_struct(FILE *fp, struct struct_desc *desc, void *data,
 			break;
 
 		case UINT64:
-			ptr = (void*)(((intptr_t)ptr + al) & ~al);
+			ptr = (void*)(((intptr_t)ptr + al64) & ~al64);
 			u64 = *((uint64_t*)ptr);
 			fprintf(fp,"%" PRIu64,u64);
 			ptr += 8;
 			break;
 		case SINT64:
-			ptr = (void*)(((intptr_t)ptr + al) & ~al);
+			ptr = (void*)(((intptr_t)ptr + al64) & ~al64);
 			s64 = *((int64_t*)ptr);
 			fprintf(fp,"%" PRId64,s64);
 			ptr += 8;


Re: Xawtv sparc 64bit fix

2010-04-25 Thread Mauro Carvalho Chehab
Guy Martin wrote:
> 
> Hi,
> 
> Here is an old patch of mine which I tried to submit in 2006 but never
> got it. I didn't really know who was xawtv's maintainer at that time.
> 
> 
> 
> The calculation to compute the 64bit alignement in struct-dump.c is
> plain wrong. The alignment has to be computed with a structure
> containing a char and then a 64bit integer and then substract the
> pointer of the 64bit int to the one of the char.
> 
> This fix v4l-info doing a Bus Error on sparc with structs containing
> 64 bit integer following a non 64bit field aligned on a 8 byte boundary
> like v4l2_standard.
> 
> 
> Signed-off-by: Guy Martin 

I tried to compile it (x86_64 arch) and your patch produced two warnings:

../structs/struct-dump.c: In function ‘print_struct’:
../structs/struct-dump.c:48: warning: cast from pointer to integer of different 
size
../structs/struct-dump.c:48: warning: cast from pointer to integer of different 
size

Could you please fix it?

> 
> 
> Regards,
>   Guy
> 


-- 

Cheers,
Mauro
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Xawtv sparc 64bit fix

2010-04-23 Thread Guy Martin


Hi,

Here is an old patch of mine which I tried to submit in 2006 but never
got it. I didn't really know who was xawtv's maintainer at that time.



The calculation to compute the 64bit alignement in struct-dump.c is
plain wrong. The alignment has to be computed with a structure
containing a char and then a 64bit integer and then substract the
pointer of the 64bit int to the one of the char.

This fix v4l-info doing a Bus Error on sparc with structs containing
64 bit integer following a non 64bit field aligned on a 8 byte boundary
like v4l2_standard.


Signed-off-by: Guy Martin 


Regards,
  Guydiff --git a/structs/struct-dump.c b/structs/struct-dump.c
index 0ee7fc8..ba1dc6f 100644
--- a/structs/struct-dump.c
+++ b/structs/struct-dump.c
@@ -43,7 +43,9 @@ int print_struct(FILE *fp, struct struct_desc *desc, void *data,
 	int16_t  s16;
 	uint8_t  u8;
 	int8_t   s8;
-	int al = sizeof(long)-1; /* struct + union + 64bit alignment */
+	struct al64_t { char c; uint64_t t; } al64_t;
+	int al = sizeof(long)-1; /* struct + union */
+	int al64 = (unsigned)&al64_t.t - (unsigned)&al64_t.c - 1; /* 64 bit alignement */
 	void *p;
 	unsigned int i,j,first;
 
@@ -149,7 +151,7 @@ int print_struct(FILE *fp, struct struct_desc *desc, void *data,
 			ptr += 4;
 			break;
 		case BITS64:
-			ptr = (void*)(((intptr_t)ptr + al) & ~al);
+			ptr = (void*)(((intptr_t)ptr + al64) & ~al64);
 			u64 = *((uint64_t*)ptr);
 			first = 1;
 			fprintf(fp,"0x%" PRIx64 " [",u64);
@@ -166,13 +168,13 @@ int print_struct(FILE *fp, struct struct_desc *desc, void *data,
 			break;
 
 		case UINT64:
-			ptr = (void*)(((intptr_t)ptr + al) & ~al);
+			ptr = (void*)(((intptr_t)ptr + al64) & ~al64);
 			u64 = *((uint64_t*)ptr);
 			fprintf(fp,"%" PRIu64,u64);
 			ptr += 8;
 			break;
 		case SINT64:
-			ptr = (void*)(((intptr_t)ptr + al) & ~al);
+			ptr = (void*)(((intptr_t)ptr + al64) & ~al64);
 			s64 = *((int64_t*)ptr);
 			fprintf(fp,"%" PRId64,s64);
 			ptr += 8;