Skip to contentSkip to conversation

PATCH] firewire: add padding to some struct

DISCUSSION JiSheng Zhang 2 participants 3 messages Jul 18, 2008

lore
Share & tools
lore
#0 lore raw

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

Quoted 8 lines

From: Stefan Richter <[email protected]> Reply-To:
To: JiSheng Zhang <[email protected]>
Subject: Re: PATCH] firewire: add padding to some struct Date:Fri, 18 Jul 2008 12:49:11 +0200

Quoted 1 line · JiSheng Zhang

struct fw_cdev_event_response and struct fw_cdev_event_iso_interrupt need

padding.

Quoted 1 line
Quoted 1 line

Otherwise, offset of the zero length array is not equal to the struct size. It

may

Quoted 18 lines
Quoted 2 lines

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...

Quoted 5 lines
include/linux/firewire-cdev.h +0 -0
@@ -92,6 +92,7 @@
 	__u32 type;
 	__u32 rcode;
#1 lore raw
Quoted 11 lines · JiSheng Zhang

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);
Quoted 4 lines

.....

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.

Signature · 3 lines
Stefan Richter
-=====-==--- -=== =--=-
http://arcgraph.de/sr/
#2 lore raw
Quoted 3 lines · Stefan Richter

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.

PS, of course the math of the latter should look more like

	(char *)&response + offsetof(...)
Signature · 3 lines
Stefan Richter
-=====-==--- -=== =--=-
http://arcgraph.de/sr/