2004-11-24 23:26:13

by Jesper Juhl

[permalink] [raw]
Subject: Any reason why we don't initialize all members of struct Xgt_desc_struct in doublefault.c ?


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 <[email protected]>

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 <[email protected]>

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



2004-11-26 19:26:06

by Jeff Garzik

[permalink] [raw]
Subject: Re: Any reason why we don't initialize all members of struct Xgt_desc_struct in doublefault.c ?

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


2004-11-26 20:54:14

by Andreas Dilger

[permalink] [raw]
Subject: Re: Any reason why we don't initialize all members of struct Xgt_desc_struct in doublefault.c ?

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/


Attachments:
(No filename) (996.00 B)
(No filename) (189.00 B)
Download all attachments

2004-11-26 22:08:52

by Jesper Juhl

[permalink] [raw]
Subject: Re: Any reason why we don't initialize all members of struct Xgt_desc_struct in doublefault.c ?

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

2004-11-30 03:05:25

by Zwane Mwaikambo

[permalink] [raw]
Subject: Re: Any reason why we don't initialize all members of struct Xgt_desc_struct in doublefault.c ?

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.