Skip to contentSkip to conversation

weird padding in linux/timex.h, struct timex

PATCH Muli Ben-Yehuda 2 participants 3 messages Aug 6, 2002 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore
#0 lore raw

Hi,

struct timex in include/linux/timex.h is defined as

struct timex

{
	...
	int  :32; int  :32; int  :32; int  :32;
	int  :32; int  :32; int  :32; int  :32;
	int  :32; int  :32; int  :32; int  :32;
}; 

I assume that this is used as padding. Is there any reason for using bitfields as padding? If there is, a comment to that effect would be nice. If there isn't, the following patch makes the padding explicit.

include/linux/timex.h +1 -3
@@ -182,9 +182,7 @@
 	long errcnt;            /* calibration errors (ro) */
 	long stbcnt;            /* stability limit exceeded (ro) */
 
-	int  :32; int  :32; int  :32; int  :32;
-	int  :32; int  :32; int  :32; int  :32;
-	int  :32; int  :32; int  :32; int  :32;
+	char __pad[12 * 4];     /* padding */ 
 };
 
 /*
Signature · 4 lines
I am PINK, hear me ROAR

http://vipe.technion.ac.il/~mulix/
http://syscalltrack.sf.net/
#1 lore raw
Quoted 12 lines · Muli Ben-Yehuda

Hi,

struct timex in include/linux/timex.h is defined as

struct timex

{
	...
	int  :32; int  :32; int  :32; int  :32;
	int  :32; int  :32; int  :32; int  :32;
	int  :32; int  :32; int  :32; int  :32;
}; 
Quoted 4 lines

I assume that this is used as padding. Is there any reason for using bitfields as padding? If there is, a comment to that effect would be nice. If there isn't, the following patch makes the padding explicit.

That is how the interface has always been defined. I think we inherited that from the world of xntpd but I may be wrong. Your __pad is not always the same thing - you assume 4 byte ints and ints aligned the same way as char [], which may not always be true.

#2 lore raw
Quoted 18 lines · Alan Cox
Quoted 12 lines · Muli Ben-Yehuda

Hi,

struct timex in include/linux/timex.h is defined as

struct timex

{
	...
	int  :32; int  :32; int  :32; int  :32;
	int  :32; int  :32; int  :32; int  :32;
	int  :32; int  :32; int  :32; int  :32;
}; 
Quoted 4 lines

I assume that this is used as padding. Is there any reason for using bitfields as padding? If there is, a comment to that effect would be nice. If there isn't, the following patch makes the padding explicit.

Quoted 4 lines

That is how the interface has always been defined. I think we inherited that from the world of xntpd but I may be wrong. Your __pad is not always the same thing - you assume 4 byte ints and ints aligned the same way as char [], which may not always be true.

I assume 4 byte ints, because I assume that the length of a 32 bit bitfield will be 32 bits. As for alignment, you're correct.

I guess my question becomes: is the original code defined in any special way, in regards to padding and size? If it isn't, my __pad patch would be cleaner and just as correct in principle. If it is, I can make a __pad which will behave exactly the same way.

Thanks, Muli.

Signature · 4 lines
I am PINK, hear me ROAR

http://vipe.technion.ac.il/~mulix/
http://syscalltrack.sf.net/