All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: PATCH] firewire: add padding to some struct
@ 2008-07-18 11:16 JiSheng Zhang
  2008-07-18 11:38 ` Stefan Richter
  0 siblings, 1 reply; 13+ messages in thread
From: JiSheng Zhang @ 2008-07-18 11:16 UTC (permalink / raw)
  To: stefanr; +Cc: linux-kernel, linux1394-devel, krh

Hi,
If p is a pointer to struct fw_cdev_event_response), p->data will point to the
padding data rather than the right place, it will cause problem under some
platforms. For example, in the function handle_device_event of libraw1394(ported
to juju stack):
.....
case FW_CDEV_EVENT_RESPONSE:
    rc = u64_to_ptr(u->response.closure);
    if (rc->data != NULL)
	memcpy(rc->data, u->response.data, rc->length);//here it will lost the last four
bytes
    errcode = juju_to_raw1394_errcode(u->response.rcode);
.....

Although this problem can be solved by add the offset to the pointer, but the
member:__u32 data[0] lost its original meaning.

Thanks in advance,
JiSheng
>From: Stefan Richter <stefanr@s5r6.in-berlin.de>
>Reply-To: 
>To: JiSheng Zhang <jszhang3@mail.ustc.edu.cn>
>Subject: Re: PATCH] firewire: add padding to some struct
>Date:Fri, 18 Jul 2008 12:49:11 +0200
>
>JiSheng Zhang wrote:
> > struct fw_cdev_event_response and struct fw_cdev_event_iso_interrupt need
padding.
> > Otherwise, offset of the zero length array is not equal to the struct size. It
may
> > cause some strange problems under some platforms such as sparc32. This
> > patch(against 2.6.26) should fix it.
> 
> The best solution to this problem would be to use
> 
> 	offsetof(struct fw_cdev_event_XYZ, data)
> 
> instead of sizeof(struct fw_cdev_event_XYZ) in all the places where the
> offset is required.
> 
> Your proposed solution to add padding...
> 
> > --- old/include/linux/firewire-cdev.h	2008-07-18 16:34:01.181794046 +0800
> > +++ new/include/linux/firewire-cdev.h	2008-07-18 16:35:46.649294275 +0800
> > @@ -92,6 +92,7 @@
> >  	__u32 type;
> >  	__u32 rcode;
>



^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: PATCH] firewire: add padding to some struct
@ 2008-07-18 12:31 JiSheng Zhang
  2008-07-18 15:27 ` Mikael Pettersson
       [not found] ` <416443505.10974@ustc.edu.cn>
  0 siblings, 2 replies; 13+ messages in thread
From: JiSheng Zhang @ 2008-07-18 12:31 UTC (permalink / raw)
  To: stefanr; +Cc: linux-kernel, linux1394-devel, krh

Hi,
>From: Stefan Richter <stefanr@s5r6.in-berlin.de>
>Reply-To: 
>To: JiSheng Zhang <jszhang3@mail.ustc.edu.cn>
>Subject: Re: PATCH] firewire: add padding to some struct
>Date:Fri, 18 Jul 2008 13:38:25 +0200
>
>JiSheng Zhang wrote:
> > If p is a pointer to struct fw_cdev_event_response), p->data will point to
the
> > padding data rather than the right place, it will cause problem under some
> > platforms. For example, in the function handle_device_event of
libraw1394(ported
> > to juju stack):
> > .....
> > case FW_CDEV_EVENT_RESPONSE:
> >     rc = u64_to_ptr(u->response.closure);
> >     if (rc->data != NULL)
> > 	memcpy(rc->data, u->response.data, rc->length);//here it will lost the last
four
> > bytes
> >     errcode = juju_to_raw1394_errcode(u->response.rcode);
> > .....
> > 
> > Although this problem can be solved by add the offset to the pointer, but the
> > member:__u32 data[0] lost its original meaning.
> 
> I don't understand what the problem is.  As long as both kernel and
> library use "response.data" or "&response + offsetof(typeof(response),
> data)", they will write and read at the correct location.
>
This patch can fix the problem while not changing the struct definition.


Thanks in advance,
JiSheng

--- old/drivers/firewire/fw-cdev.c	2008-07-14 05:51:29.000000000 +0800
+++ new/drivers/firewire/fw-cdev.c	2008-07-18 20:20:45.841328585 +0800
@@ -382,9 +382,9 @@
 
 	response->response.type   = FW_CDEV_EVENT_RESPONSE;
 	response->response.rcode  = rcode;
-	queue_event(client, &response->event,
-		    &response->response, sizeof(response->response),
-		    response->response.data, response->response.length);
+	queue_event(client, &response->event, &response->response, 
+		    sizeof(response->response) + response->response.length,
+		    NULL, 0);
 }
 
 static int ioctl_send_request(struct client *client, void *buffer)



^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: PATCH] firewire: add padding to some struct
@ 2008-07-18 12:07 JiSheng Zhang
  0 siblings, 0 replies; 13+ messages in thread
From: JiSheng Zhang @ 2008-07-18 12:07 UTC (permalink / raw)
  To: stefanr; +Cc: linux-kernel, linux1394-devel, krh

Hi,

>From: Stefan Richter <stefanr@s5r6.in-berlin.de>
>Reply-To: 
>To: JiSheng Zhang <jszhang3@mail.ustc.edu.cn>
>Subject: Re: PATCH] firewire: add padding to some struct
>Date:Fri, 18 Jul 2008 13:38:25 +0200
>
>JiSheng Zhang wrote:
> > If p is a pointer to struct fw_cdev_event_response), p->data will point to
the
> > padding data rather than the right place, it will cause problem under some
> > platforms. For example, in the function handle_device_event of
libraw1394(ported
> > to juju stack):
> > .....
> > case FW_CDEV_EVENT_RESPONSE:
> >     rc = u64_to_ptr(u->response.closure);
> >     if (rc->data != NULL)
> > 	memcpy(rc->data, u->response.data, rc->length);//here it will lost the last
four
> > bytes
> >     errcode = juju_to_raw1394_errcode(u->response.rcode);
> > .....
> > 
> > Although this problem can be solved by add the offset to the pointer, but the
> > member:__u32 data[0] lost its original meaning.
> 
> I don't understand what the problem is.  As long as both kernel and
> library use "response.data" or "&response + offsetof(typeof(response),
> data)", they will write and read at the correct location.
>
> There would be a problem if one of the two used "&response +
> sizeof(response)" instead.  Does this happen anywhere?  If so, then
> these places need to be fixed, not the struct definition.
yes, complete_transaction in fw-cdev.c, it queues the response and data.

how about adding __attribute__((packed)) to the two struct definition? It will not
break abi compatibility.

Thanks in advance,
JiSheng


--- old/include/linux/firewire-cdev.h	2008-07-18 16:34:01.181794046 +0800
+++ new/include/linux/firewire-cdev.h	2008-07-18 19:39:16.389293987 +0800
@@ -93,7 +93,7 @@ struct fw_cdev_event_response {
 	__u32 rcode;
 	__u32 length;
 	__u32 data[0];
-};
+} __attribute__((packed));
 
 /**
  * struct fw_cdev_event_request - Sent on incoming request to an address region
@@ -144,7 +144,7 @@ struct fw_cdev_event_iso_interrupt {
 	__u32 cycle;
 	__u32 header_length;
 	__u32 header[0];
-};
+} __attribute__((packed));
 
 /**
  * union fw_cdev_event - Convenience union of fw_cdev_event_ types



^ permalink raw reply	[flat|nested] 13+ messages in thread
* PATCH] firewire: add padding to some struct
@ 2008-07-18  8:58 JiSheng Zhang
  2008-07-18 10:49 ` Stefan Richter
  0 siblings, 1 reply; 13+ messages in thread
From: JiSheng Zhang @ 2008-07-18  8:58 UTC (permalink / raw)
  To: stefanr; +Cc: linux-kernel, linux1394-devel, krh

>From JiSheng Zhang <jszhang3@mail.ustc.edu.cn>

struct fw_cdev_event_response and struct fw_cdev_event_iso_interrupt need padding.
Otherwise, offset of the zero length array is not equal to the struct size. It may
cause some strange problems under some platforms such as sparc32. This
patch(against 2.6.26) should fix it.


--- old/include/linux/firewire-cdev.h	2008-07-18 16:34:01.181794046 +0800
+++ new/include/linux/firewire-cdev.h	2008-07-18 16:35:46.649294275 +0800
@@ -92,6 +92,7 @@
 	__u32 type;
 	__u32 rcode;
 	__u32 length;
+	__u32 pad;
 	__u32 data[0];
 };
 
@@ -143,6 +144,7 @@
 	__u32 type;
 	__u32 cycle;
 	__u32 header_length;
+	__u32 pad;
 	__u32 header[0];
 };
 



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2008-07-21  7:39 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-18 11:16 PATCH] firewire: add padding to some struct JiSheng Zhang
2008-07-18 11:38 ` Stefan Richter
2008-07-18 11:58   ` Stefan Richter
  -- strict thread matches above, loose matches on Subject: below --
2008-07-18 12:31 JiSheng Zhang
2008-07-18 15:27 ` Mikael Pettersson
     [not found] ` <416443505.10974@ustc.edu.cn>
2008-07-19  7:41   ` JiSheng Zhang
2008-07-19  7:41     ` JiSheng Zhang
2008-07-19 10:09       ` Mikael Pettersson
2008-07-19 10:32       ` Stefan Richter
     [not found]       ` <416463624.22263@ustc.edu.cn>
2008-07-20  6:20         ` JiSheng Zhang
2008-07-20  6:20           ` JiSheng Zhang
     [not found]     ` <416625421.30590@ustc.edu.cn>
2008-07-21  7:37       ` JiSheng Zhang
2008-07-21  7:37         ` JiSheng Zhang
2008-07-18 12:07 JiSheng Zhang
2008-07-18  8:58 JiSheng Zhang
2008-07-18 10:49 ` Stefan Richter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.