linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Any reason why we don't initialize all members of struct Xgt_desc_struct in doublefault.c ?
@ 2004-11-24 23:21 Jesper Juhl
  2004-11-25 16:45 ` Zwane Mwaikambo
  2004-11-26 15:14 ` Jeff Garzik
  0 siblings, 2 replies; 5+ messages in thread
From: Jesper Juhl @ 2004-11-24 23:21 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm


Yes, this is nitpicking, but I just can't leave small corners like this 
unpolished ;)

in arch/i386/kernel/doublefault.c you will find this (line 20) :

struct Xgt_desc_struct gdt_desc = {0, 0};

but, struct Xgt_desc_struct has 3 members, 

struct Xgt_desc_struct {
        unsigned short size;
        unsigned long address __attribute__((packed));
        unsigned short pad;
} __attribute__ ((packed));

so why only initialize two of them explicitly?


Wouldn't this be nicer? :

Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>

diff -up linux-2.6.10-rc2-bk9-orig/arch/i386/kernel/doublefault.c linux-2.6.10-rc2-bk9/arch/i386/kernel/doublefault.c
--- linux-2.6.10-rc2-bk9-orig/arch/i386/kernel/doublefault.c	2004-10-18 23:53:21.000000000 +0200
+++ linux-2.6.10-rc2-bk9/arch/i386/kernel/doublefault.c	2004-11-25 00:02:34.000000000 +0100
@@ -17,7 +17,7 @@ static unsigned long doublefault_stack[D
 
 static void doublefault_fn(void)
 {
-	struct Xgt_desc_struct gdt_desc = {0, 0};
+	struct Xgt_desc_struct gdt_desc = {0, 0, 0};
 	unsigned long gdt, tss;
 
 	__asm__ __volatile__("sgdt %0": "=m" (gdt_desc): :"memory");


or, if we want to be completely explicit about it how about :

Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>

diff -up linux-2.6.10-rc2-bk9-orig/arch/i386/kernel/doublefault.c linux-2.6.10-rc2-bk9/arch/i386/kernel/doublefault.c
--- linux-2.6.10-rc2-bk9-orig/arch/i386/kernel/doublefault.c	2004-10-18 23:53:21.000000000 +0200
+++ linux-2.6.10-rc2-bk9/arch/i386/kernel/doublefault.c	2004-11-25 00:06:18.000000000 +0100
@@ -17,7 +17,11 @@ static unsigned long doublefault_stack[D
 
 static void doublefault_fn(void)
 {
-	struct Xgt_desc_struct gdt_desc = {0, 0};
+	struct Xgt_desc_struct gdt_desc = {
+		.size = 0,
+		.address = 0,
+		.pad = 0
+	};
 	unsigned long gdt, tss;
 
 	__asm__ __volatile__("sgdt %0": "=m" (gdt_desc): :"memory");


--
Jesper Juhl



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

* Re: Any reason why we don't initialize all members of struct Xgt_desc_struct in doublefault.c ?
  2004-11-24 23:21 Any reason why we don't initialize all members of struct Xgt_desc_struct in doublefault.c ? Jesper Juhl
@ 2004-11-25 16:45 ` Zwane Mwaikambo
  2004-11-26 15:14 ` Jeff Garzik
  1 sibling, 0 replies; 5+ messages in thread
From: Zwane Mwaikambo @ 2004-11-25 16:45 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: linux-kernel, akpm

On Thu, 25 Nov 2004, Jesper Juhl wrote:

> Yes, this is nitpicking, but I just can't leave small corners like this 
> unpolished ;)
> 
> in arch/i386/kernel/doublefault.c you will find this (line 20) :
> 
> struct Xgt_desc_struct gdt_desc = {0, 0};
> 
> but, struct Xgt_desc_struct has 3 members, 
> 
> struct Xgt_desc_struct {
>         unsigned short size;
>         unsigned long address __attribute__((packed));
>         unsigned short pad;
> } __attribute__ ((packed));
> 
> so why only initialize two of them explicitly?
> 
> 
> Wouldn't this be nicer? :

I can't see what the point is, it's a machine defined struct which only 
uses the first 6bytes. It'll never bother with the pad variable.

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

* Re: Any reason why we don't initialize all members of struct Xgt_desc_struct in doublefault.c ?
  2004-11-24 23:21 Any reason why we don't initialize all members of struct Xgt_desc_struct in doublefault.c ? Jesper Juhl
  2004-11-25 16:45 ` Zwane Mwaikambo
@ 2004-11-26 15:14 ` Jeff Garzik
  2004-11-26 15:24   ` Jesper Juhl
  2004-11-26 20:24   ` Andreas Dilger
  1 sibling, 2 replies; 5+ messages in thread
From: Jeff Garzik @ 2004-11-26 15:14 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: linux-kernel, akpm

Jesper Juhl wrote:
> Yes, this is nitpicking, but I just can't leave small corners like this 
> unpolished ;)
> 
> in arch/i386/kernel/doublefault.c you will find this (line 20) :
> 
> struct Xgt_desc_struct gdt_desc = {0, 0};
> 
> but, struct Xgt_desc_struct has 3 members, 
> 
> struct Xgt_desc_struct {
>         unsigned short size;
>         unsigned long address __attribute__((packed));
>         unsigned short pad;
> } __attribute__ ((packed));
> 
> so why only initialize two of them explicitly?

'pad' is a dummy variable... nobody cares about its value.

	Jeff



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

* Re: Any reason why we don't initialize all members of struct Xgt_desc_struct in doublefault.c ?
  2004-11-26 15:14 ` Jeff Garzik
@ 2004-11-26 15:24   ` Jesper Juhl
  2004-11-26 20:24   ` Andreas Dilger
  1 sibling, 0 replies; 5+ messages in thread
From: Jesper Juhl @ 2004-11-26 15:24 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: linux-kernel, akpm

Jeff Garzik wrote:
> Jesper Juhl wrote:
> 
>> Yes, this is nitpicking, but I just can't leave small corners like 
>> this unpolished ;)
>>
>> in arch/i386/kernel/doublefault.c you will find this (line 20) :
>>
>> struct Xgt_desc_struct gdt_desc = {0, 0};
>>
>> but, struct Xgt_desc_struct has 3 members,
>> struct Xgt_desc_struct {
>>         unsigned short size;
>>         unsigned long address __attribute__((packed));
>>         unsigned short pad;
>> } __attribute__ ((packed));
>>
>> so why only initialize two of them explicitly?
> 
> 
> 'pad' is a dummy variable... nobody cares about its value.
> 
Ok, good reason. Thank you for taking the time to reply.

--
Jesper Juhl

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

* Re: Any reason why we don't initialize all members of struct Xgt_desc_struct in doublefault.c ?
  2004-11-26 15:14 ` Jeff Garzik
  2004-11-26 15:24   ` Jesper Juhl
@ 2004-11-26 20:24   ` Andreas Dilger
  1 sibling, 0 replies; 5+ messages in thread
From: Andreas Dilger @ 2004-11-26 20:24 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Jesper Juhl, linux-kernel, akpm

[-- Attachment #1: Type: text/plain, Size: 1027 bytes --]

On Nov 26, 2004  10:14 -0500, Jeff Garzik wrote:
> Jesper Juhl wrote:
> >Yes, this is nitpicking, but I just can't leave small corners like this 
> >unpolished ;)
> >
> >in arch/i386/kernel/doublefault.c you will find this (line 20) :
> >
> >struct Xgt_desc_struct gdt_desc = {0, 0};
> >
> >but, struct Xgt_desc_struct has 3 members, 
> >
> >struct Xgt_desc_struct {
> >        unsigned short size;
> >        unsigned long address __attribute__((packed));
> >        unsigned short pad;
> >} __attribute__ ((packed));
> >
> >so why only initialize two of them explicitly?
> 
> 'pad' is a dummy variable... nobody cares about its value.

Also, for struct initializations if you don't specify a field explicitly
it will be initialized to zero anyways, so even "gdt_desc = { }" is enough
in this case to initialize all of the fields to zero.

Cheers, Andreas
--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://members.shaw.ca/adilger/             http://members.shaw.ca/golinux/


[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

end of thread, other threads:[~2004-11-30  3:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-24 23:21 Any reason why we don't initialize all members of struct Xgt_desc_struct in doublefault.c ? Jesper Juhl
2004-11-25 16:45 ` Zwane Mwaikambo
2004-11-26 15:14 ` Jeff Garzik
2004-11-26 15:24   ` Jesper Juhl
2004-11-26 20:24   ` Andreas Dilger

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