kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] edac i5000: fix pointer math in i5000_get_mc_regs()
@ 2012-03-02  6:54 Dan Carpenter
  2012-03-02  9:00 ` walter harms
  0 siblings, 1 reply; 10+ messages in thread
From: Dan Carpenter @ 2012-03-02  6:54 UTC (permalink / raw)
  To: Eric Wollesen; +Cc: Doug Thompson, list-edac, linux-kernel, kernel-janitors

"pvt->ambase" is a u64 datatype.  The intent here is to fill the first
half in the first call to pci_read_config_dword() and the other half in
the second.  Unfortunately the pointer math is wrong so we set the wrong
data.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
I don't have the hardware to test this.  Please review carefully.

diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
index 4dc3ac2..fcdc4ab 100644
--- a/drivers/edac/i5000_edac.c
+++ b/drivers/edac/i5000_edac.c
@@ -1130,7 +1130,7 @@ static void i5000_get_mc_regs(struct mem_ctl_info *mci)
 	pci_read_config_dword(pvt->system_address, AMBASE,
 			(u32 *) & pvt->ambase);
 	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
-			((u32 *) & pvt->ambase) + sizeof(u32));
+			(u32 *)((char *) &pvt->ambase + sizeof(u32)));
 
 	maxdimmperch = pvt->maxdimmperch;
 	maxch = pvt->maxch;

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

* Re: [patch] edac i5000: fix pointer math in i5000_get_mc_regs()
  2012-03-02  6:54 [patch] edac i5000: fix pointer math in i5000_get_mc_regs() Dan Carpenter
@ 2012-03-02  9:00 ` walter harms
  2012-03-02 19:09   ` Dan Carpenter
  2012-03-05  8:59   ` [patch v2] edac i5000, i5400: " Dan Carpenter
  0 siblings, 2 replies; 10+ messages in thread
From: walter harms @ 2012-03-02  9:00 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Eric Wollesen, Doug Thompson, list-edac, linux-kernel,
	kernel-janitors



Am 02.03.2012 07:54, schrieb Dan Carpenter:
> "pvt->ambase" is a u64 datatype.  The intent here is to fill the first
> half in the first call to pci_read_config_dword() and the other half in
> the second.  Unfortunately the pointer math is wrong so we set the wrong
> data.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> I don't have the hardware to test this.  Please review carefully.
> 
> diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
> index 4dc3ac2..fcdc4ab 100644
> --- a/drivers/edac/i5000_edac.c
> +++ b/drivers/edac/i5000_edac.c
> @@ -1130,7 +1130,7 @@ static void i5000_get_mc_regs(struct mem_ctl_info *mci)
>  	pci_read_config_dword(pvt->system_address, AMBASE,
>  			(u32 *) & pvt->ambase);
>  	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
> -			((u32 *) & pvt->ambase) + sizeof(u32));
> +			(u32 *)((char *) &pvt->ambase + sizeof(u32)));
>  
>  	maxdimmperch = pvt->maxdimmperch;
>  	maxch = pvt->maxch;

i think this is hard to understand. personally i would prefer a union or other
more obvious solutions. my suggestion would be to get rid of this.

u32 bottom,top;
 	pci_read_config_dword(pvt->system_address, AMBASE,
  			&bottom);
	pci_read_config_dword(pvt->system_address, AMBASE+ sizeof(u32),
  			&top);
	maxdimmperch=(u64)top<<32|bottom;
	
you can find this pattern in other parts of the kernel also.

hope that helps
re,
 wh



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

* Re: [patch] edac i5000: fix pointer math in i5000_get_mc_regs()
  2012-03-02  9:00 ` walter harms
@ 2012-03-02 19:09   ` Dan Carpenter
  2012-03-02 19:20     ` walter harms
  2012-03-05  8:59   ` [patch v2] edac i5000, i5400: " Dan Carpenter
  1 sibling, 1 reply; 10+ messages in thread
From: Dan Carpenter @ 2012-03-02 19:09 UTC (permalink / raw)
  To: walter harms
  Cc: Eric Wollesen, Doug Thompson, list-edac, linux-kernel,
	kernel-janitors

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

On Fri, Mar 02, 2012 at 10:00:06AM +0100, walter harms wrote:
> > diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
> > index 4dc3ac2..fcdc4ab 100644
> > --- a/drivers/edac/i5000_edac.c
> > +++ b/drivers/edac/i5000_edac.c
> > @@ -1130,7 +1130,7 @@ static void i5000_get_mc_regs(struct mem_ctl_info *mci)
> >  	pci_read_config_dword(pvt->system_address, AMBASE,
> >  			(u32 *) & pvt->ambase);
> >  	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
> > -			((u32 *) & pvt->ambase) + sizeof(u32));
> > +			(u32 *)((char *) &pvt->ambase + sizeof(u32)));
> >  
> >  	maxdimmperch = pvt->maxdimmperch;
> >  	maxch = pvt->maxch;
> 
> i think this is hard to understand. personally i would prefer a union or other
> more obvious solutions. my suggestion would be to get rid of this.
> 
> u32 bottom,top;
>  	pci_read_config_dword(pvt->system_address, AMBASE,
>   			&bottom);
> 	pci_read_config_dword(pvt->system_address, AMBASE+ sizeof(u32),
>   			&top);
> 	maxdimmperch=(u64)top<<32|bottom;
> 	
> you can find this pattern in other parts of the kernel also.
> 

Sure.  I want to do this again anyway because I see I've missed some
other parts which have the same bug.  I'll resend a patch later.

regards,
dan carpenter

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

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

* Re: [patch] edac i5000: fix pointer math in i5000_get_mc_regs()
  2012-03-02 19:09   ` Dan Carpenter
@ 2012-03-02 19:20     ` walter harms
  0 siblings, 0 replies; 10+ messages in thread
From: walter harms @ 2012-03-02 19:20 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-kernel, kernel-janitors



Am 02.03.2012 20:09, schrieb Dan Carpenter:
> On Fri, Mar 02, 2012 at 10:00:06AM +0100, walter harms wrote:
>>> diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
>>> index 4dc3ac2..fcdc4ab 100644
>>> --- a/drivers/edac/i5000_edac.c
>>> +++ b/drivers/edac/i5000_edac.c
>>> @@ -1130,7 +1130,7 @@ static void i5000_get_mc_regs(struct mem_ctl_info *mci)
>>>  	pci_read_config_dword(pvt->system_address, AMBASE,
>>>  			(u32 *) & pvt->ambase);
>>>  	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
>>> -			((u32 *) & pvt->ambase) + sizeof(u32));
>>> +			(u32 *)((char *) &pvt->ambase + sizeof(u32)));
>>>  
>>>  	maxdimmperch = pvt->maxdimmperch;
>>>  	maxch = pvt->maxch;
>>
>> i think this is hard to understand. personally i would prefer a union or other
>> more obvious solutions. my suggestion would be to get rid of this.
>>
>> u32 bottom,top;
>>  	pci_read_config_dword(pvt->system_address, AMBASE,
>>   			&bottom);
>> 	pci_read_config_dword(pvt->system_address, AMBASE+ sizeof(u32),
>>   			&top);
>> 	maxdimmperch=(u64)top<<32|bottom;
>> 	
>> you can find this pattern in other parts of the kernel also.
>>
> 
> Sure.  I want to do this again anyway because I see I've missed some
> other parts which have the same bug.  I'll resend a patch later.
> 
> regards,
> dan carpenter

I have no idea how ofter a64bit value is need but perhaps is pci_read_config_qword()
an option ?

re,
 wh

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

* [patch v2] edac i5000, i5400: fix pointer math in i5000_get_mc_regs()
  2012-03-02  9:00 ` walter harms
  2012-03-02 19:09   ` Dan Carpenter
@ 2012-03-05  8:59   ` Dan Carpenter
  2012-03-05  9:45     ` walter harms
  1 sibling, 1 reply; 10+ messages in thread
From: Dan Carpenter @ 2012-03-05  8:59 UTC (permalink / raw)
  To: walter harms
  Cc: Eric Wollesen, Doug Thompson, list-edac, linux-kernel,
	kernel-janitors

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

"pvt->ambase" is a u64 datatype.  The intent here is to fill the first
half in the first call to pci_read_config_dword() and the other half in
the second.  Unfortunately the pointer math is wrong so we set the wrong
data.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: Redid it as with a union as Walter Harms suggested.
    Fixed the same bug in i5400_edac.c as well.

I don't have this hardware, so please review carefully.

diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
index 74d6ec34..083e80a 100644
--- a/drivers/edac/i5400_edac.c
+++ b/drivers/edac/i5400_edac.c
@@ -343,7 +343,13 @@ struct i5400_pvt {
 	struct pci_dev *branch_1;		/* 22.0 */
 
 	u16 tolm;				/* top of low memory */
-	u64 ambase;				/* AMB BAR */
+	union {
+		u64 ambase;				/* AMB BAR */
+		struct {
+			u32 ambase_bottom;
+			u32 ambase_top;
+		} u;
+	};
 
 	u16 mir0, mir1;
 
@@ -1024,9 +1030,9 @@ static void i5400_get_mc_regs(struct mem_ctl_info *mci)
 	pvt = mci->pvt_info;
 
 	pci_read_config_dword(pvt->system_address, AMBASE,
-			(u32 *) &pvt->ambase);
+			&pvt->u.ambase_bottom);
 	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
-			((u32 *) &pvt->ambase) + sizeof(u32));
+			&pvt->u.ambase_top);
 
 	maxdimmperch = pvt->maxdimmperch;
 	maxch = pvt->maxch;
diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
index 4dc3ac2..ecc2401 100644
--- a/drivers/edac/i5000_edac.c
+++ b/drivers/edac/i5000_edac.c
@@ -343,7 +343,13 @@ struct i5000_pvt {
 	struct pci_dev *branch_1;	/* 22.0 */
 
 	u16 tolm;		/* top of low memory */
-	u64 ambase;		/* AMB BAR */
+	union {
+		u64 ambase;		/* AMB BAR */
+		struct {
+			u32 ambase_bottom;
+			u32 ambase_top;
+		} u;
+	};
 
 	u16 mir0, mir1, mir2;
 
@@ -1128,9 +1134,9 @@ static void i5000_get_mc_regs(struct mem_ctl_info *mci)
 	pvt = mci->pvt_info;
 
 	pci_read_config_dword(pvt->system_address, AMBASE,
-			(u32 *) & pvt->ambase);
+			&pvt->u.ambase_bottom);
 	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
-			((u32 *) & pvt->ambase) + sizeof(u32));
+			&pvt->u.ambase_top);
 
 	maxdimmperch = pvt->maxdimmperch;
 	maxch = pvt->maxch;

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

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

* Re: [patch v2] edac i5000, i5400: fix pointer math in i5000_get_mc_regs()
  2012-03-05  8:59   ` [patch v2] edac i5000, i5400: " Dan Carpenter
@ 2012-03-05  9:45     ` walter harms
  2012-03-05  9:52       ` Dan Carpenter
  0 siblings, 1 reply; 10+ messages in thread
From: walter harms @ 2012-03-05  9:45 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Eric Wollesen, Doug Thompson, list-edac, linux-kernel,
	kernel-janitors



Am 05.03.2012 10:01, schrieb Dan Carpenter:
> "pvt->ambase" is a u64 datatype.  The intent here is to fill the first
> half in the first call to pci_read_config_dword() and the other half in
> the second.  Unfortunately the pointer math is wrong so we set the wrong
> data.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: Redid it as with a union as Walter Harms suggested.
>     Fixed the same bug in i5400_edac.c as well.
> 
> I don't have this hardware, so please review carefully.
> 
> diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
> index 74d6ec34..083e80a 100644
> --- a/drivers/edac/i5400_edac.c
> +++ b/drivers/edac/i5400_edac.c
> @@ -343,7 +343,13 @@ struct i5400_pvt {
>  	struct pci_dev *branch_1;		/* 22.0 */
>  
>  	u16 tolm;				/* top of low memory */
> -	u64 ambase;				/* AMB BAR */
> +	union {
> +		u64 ambase;				/* AMB BAR */
> +		struct {
> +			u32 ambase_bottom;
> +			u32 ambase_top;
> +		} u;
> +	};
>  

would this work with alignment=8 ?
 re,
  wh

>  	u16 mir0, mir1;
>  
> @@ -1024,9 +1030,9 @@ static void i5400_get_mc_regs(struct mem_ctl_info *mci)
>  	pvt = mci->pvt_info;
>  
>  	pci_read_config_dword(pvt->system_address, AMBASE,
> -			(u32 *) &pvt->ambase);
> +			&pvt->u.ambase_bottom);
>  	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
> -			((u32 *) &pvt->ambase) + sizeof(u32));
> +			&pvt->u.ambase_top);
>  
>  	maxdimmperch = pvt->maxdimmperch;
>  	maxch = pvt->maxch;
> diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
> index 4dc3ac2..ecc2401 100644
> --- a/drivers/edac/i5000_edac.c
> +++ b/drivers/edac/i5000_edac.c
> @@ -343,7 +343,13 @@ struct i5000_pvt {
>  	struct pci_dev *branch_1;	/* 22.0 */
>  
>  	u16 tolm;		/* top of low memory */
> -	u64 ambase;		/* AMB BAR */
> +	union {
> +		u64 ambase;		/* AMB BAR */
> +		struct {
> +			u32 ambase_bottom;
> +			u32 ambase_top;
> +		} u;
> +	};
>  
>  	u16 mir0, mir1, mir2;
>  
> @@ -1128,9 +1134,9 @@ static void i5000_get_mc_regs(struct mem_ctl_info *mci)
>  	pvt = mci->pvt_info;
>  
>  	pci_read_config_dword(pvt->system_address, AMBASE,
> -			(u32 *) & pvt->ambase);
> +			&pvt->u.ambase_bottom);
>  	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
> -			((u32 *) & pvt->ambase) + sizeof(u32));
> +			&pvt->u.ambase_top);
>  
>  	maxdimmperch = pvt->maxdimmperch;
>  	maxch = pvt->maxch;

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

* Re: [patch v2] edac i5000, i5400: fix pointer math in i5000_get_mc_regs()
  2012-03-05  9:45     ` walter harms
@ 2012-03-05  9:52       ` Dan Carpenter
  2012-03-05 10:07         ` walter harms
  2012-03-06  6:38         ` [patch v3] " Dan Carpenter
  0 siblings, 2 replies; 10+ messages in thread
From: Dan Carpenter @ 2012-03-05  9:52 UTC (permalink / raw)
  To: walter harms
  Cc: Eric Wollesen, Doug Thompson, list-edac, linux-kernel,
	kernel-janitors

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

On Mon, Mar 05, 2012 at 10:45:39AM +0100, walter harms wrote:
> 
> 
> Am 05.03.2012 10:01, schrieb Dan Carpenter:
> > "pvt->ambase" is a u64 datatype.  The intent here is to fill the first
> > half in the first call to pci_read_config_dword() and the other half in
> > the second.  Unfortunately the pointer math is wrong so we set the wrong
> > data.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > v2: Redid it as with a union as Walter Harms suggested.
> >     Fixed the same bug in i5400_edac.c as well.
> > 
> > I don't have this hardware, so please review carefully.
> > 
> > diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
> > index 74d6ec34..083e80a 100644
> > --- a/drivers/edac/i5400_edac.c
> > +++ b/drivers/edac/i5400_edac.c
> > @@ -343,7 +343,13 @@ struct i5400_pvt {
> >  	struct pci_dev *branch_1;		/* 22.0 */
> >  
> >  	u16 tolm;				/* top of low memory */
> > -	u64 ambase;				/* AMB BAR */
> > +	union {
> > +		u64 ambase;				/* AMB BAR */
> > +		struct {
> > +			u32 ambase_bottom;
> > +			u32 ambase_top;
> > +		} u;
> > +	};
> >  
> 
> would this work with alignment=8 ?

Are you asking or telling?

I guess I'll add a __packed and resend in case it's an issue.

regards,
dan carpenter


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

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

* Re: [patch v2] edac i5000, i5400: fix pointer math in i5000_get_mc_regs()
  2012-03-05  9:52       ` Dan Carpenter
@ 2012-03-05 10:07         ` walter harms
  2012-03-06  6:38         ` [patch v3] " Dan Carpenter
  1 sibling, 0 replies; 10+ messages in thread
From: walter harms @ 2012-03-05 10:07 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-kernel, kernel-janitors



Am 05.03.2012 10:52, schrieb Dan Carpenter:
> On Mon, Mar 05, 2012 at 10:45:39AM +0100, walter harms wrote:
>>
>>
>> Am 05.03.2012 10:01, schrieb Dan Carpenter:
>>> "pvt->ambase" is a u64 datatype.  The intent here is to fill the first
>>> half in the first call to pci_read_config_dword() and the other half in
>>> the second.  Unfortunately the pointer math is wrong so we set the wrong
>>> data.
>>>
>>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>>> ---
>>> v2: Redid it as with a union as Walter Harms suggested.
>>>     Fixed the same bug in i5400_edac.c as well.
>>>
>>> I don't have this hardware, so please review carefully.
>>>
>>> diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
>>> index 74d6ec34..083e80a 100644
>>> --- a/drivers/edac/i5400_edac.c
>>> +++ b/drivers/edac/i5400_edac.c
>>> @@ -343,7 +343,13 @@ struct i5400_pvt {
>>>  	struct pci_dev *branch_1;		/* 22.0 */
>>>  
>>>  	u16 tolm;				/* top of low memory */
>>> -	u64 ambase;				/* AMB BAR */
>>> +	union {
>>> +		u64 ambase;				/* AMB BAR */
>>> +		struct {
>>> +			u32 ambase_bottom;
>>> +			u32 ambase_top;
>>> +		} u;
>>> +	};
>>>  
>>
>> would this work with alignment=8 ?
> 
> Are you asking or telling?
> 

asking, i am really curious.

re,
 wh

> I guess I'll add a __packed and resend in case it's an issue.
> 
> regards,
> dan carpenter
> 

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

* [patch v3] edac i5000, i5400: fix pointer math in i5000_get_mc_regs()
  2012-03-05  9:52       ` Dan Carpenter
  2012-03-05 10:07         ` walter harms
@ 2012-03-06  6:38         ` Dan Carpenter
  2012-03-06  8:50           ` walter harms
  1 sibling, 1 reply; 10+ messages in thread
From: Dan Carpenter @ 2012-03-06  6:38 UTC (permalink / raw)
  To: walter harms
  Cc: Eric Wollesen, Doug Thompson, list-edac, linux-kernel,
	kernel-janitors

"pvt->ambase" is a u64 datatype.  The intent here is to fill the first
half in the first call to pci_read_config_dword() and the other half in
the second.  Unfortunately the pointer math is wrong so we set the wrong
data.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: Redid it as with a union as Walter Harms suggested.
    Fixed the same bug in i5400_edac.c as well.
v3: Make the struct __packed just in case.

I don't have this hardware, so please review carefully.

diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
index 74d6ec34..083e80a 100644
--- a/drivers/edac/i5400_edac.c
+++ b/drivers/edac/i5400_edac.c
@@ -343,7 +343,13 @@ struct i5400_pvt {
 	struct pci_dev *branch_1;		/* 22.0 */
 
 	u16 tolm;				/* top of low memory */
-	u64 ambase;				/* AMB BAR */
+	union {
+		u64 ambase;				/* AMB BAR */
+		struct {
+			u32 ambase_bottom;
+			u32 ambase_top;
+		} u __packed;
+	};
 
 	u16 mir0, mir1;
 
@@ -1024,9 +1030,9 @@ static void i5400_get_mc_regs(struct mem_ctl_info *mci)
 	pvt = mci->pvt_info;
 
 	pci_read_config_dword(pvt->system_address, AMBASE,
-			(u32 *) &pvt->ambase);
+			&pvt->u.ambase_bottom);
 	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
-			((u32 *) &pvt->ambase) + sizeof(u32));
+			&pvt->u.ambase_top);
 
 	maxdimmperch = pvt->maxdimmperch;
 	maxch = pvt->maxch;
diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
index 4dc3ac2..ecc2401 100644
--- a/drivers/edac/i5000_edac.c
+++ b/drivers/edac/i5000_edac.c
@@ -343,7 +343,13 @@ struct i5000_pvt {
 	struct pci_dev *branch_1;	/* 22.0 */
 
 	u16 tolm;		/* top of low memory */
-	u64 ambase;		/* AMB BAR */
+	union {
+		u64 ambase;		/* AMB BAR */
+		struct {
+			u32 ambase_bottom;
+			u32 ambase_top;
+		} u __packed;
+	};
 
 	u16 mir0, mir1, mir2;
 
@@ -1128,9 +1134,9 @@ static void i5000_get_mc_regs(struct mem_ctl_info *mci)
 	pvt = mci->pvt_info;
 
 	pci_read_config_dword(pvt->system_address, AMBASE,
-			(u32 *) & pvt->ambase);
+			&pvt->u.ambase_bottom);
 	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
-			((u32 *) & pvt->ambase) + sizeof(u32));
+			&pvt->u.ambase_top);
 
 	maxdimmperch = pvt->maxdimmperch;
 	maxch = pvt->maxch;




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

* Re: [patch v3] edac i5000, i5400: fix pointer math in i5000_get_mc_regs()
  2012-03-06  6:38         ` [patch v3] " Dan Carpenter
@ 2012-03-06  8:50           ` walter harms
  0 siblings, 0 replies; 10+ messages in thread
From: walter harms @ 2012-03-06  8:50 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Eric Wollesen, Doug Thompson, list-edac, linux-kernel,
	kernel-janitors



Am 06.03.2012 07:38, schrieb Dan Carpenter:
> "pvt->ambase" is a u64 datatype.  The intent here is to fill the first
> half in the first call to pci_read_config_dword() and the other half in
> the second.  Unfortunately the pointer math is wrong so we set the wrong
> data.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: Redid it as with a union as Walter Harms suggested.
>     Fixed the same bug in i5400_edac.c as well.
> v3: Make the struct __packed just in case.
> 
> I don't have this hardware, so please review carefully.
> 
> diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
> index 74d6ec34..083e80a 100644
> --- a/drivers/edac/i5400_edac.c
> +++ b/drivers/edac/i5400_edac.c
> @@ -343,7 +343,13 @@ struct i5400_pvt {
>  	struct pci_dev *branch_1;		/* 22.0 */
>  
>  	u16 tolm;				/* top of low memory */
> -	u64 ambase;				/* AMB BAR */
> +	union {
> +		u64 ambase;				/* AMB BAR */
> +		struct {
> +			u32 ambase_bottom;
> +			u32 ambase_top;
> +		} u __packed;
> +	};
>  
>  	u16 mir0, mir1;
>  
> @@ -1024,9 +1030,9 @@ static void i5400_get_mc_regs(struct mem_ctl_info *mci)
>  	pvt = mci->pvt_info;
>  
>  	pci_read_config_dword(pvt->system_address, AMBASE,
> -			(u32 *) &pvt->ambase);
> +			&pvt->u.ambase_bottom);
>  	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
> -			((u32 *) &pvt->ambase) + sizeof(u32));
> +			&pvt->u.ambase_top);
>  
>  	maxdimmperch = pvt->maxdimmperch;
>  	maxch = pvt->maxch;
> diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
> index 4dc3ac2..ecc2401 100644
> --- a/drivers/edac/i5000_edac.c
> +++ b/drivers/edac/i5000_edac.c
> @@ -343,7 +343,13 @@ struct i5000_pvt {
>  	struct pci_dev *branch_1;	/* 22.0 */
>  
>  	u16 tolm;		/* top of low memory */
> -	u64 ambase;		/* AMB BAR */
> +	union {
> +		u64 ambase;		/* AMB BAR */
> +		struct {
> +			u32 ambase_bottom;
> +			u32 ambase_top;
> +		} u __packed;
> +	};
>  
>  	u16 mir0, mir1, mir2;
>  
> @@ -1128,9 +1134,9 @@ static void i5000_get_mc_regs(struct mem_ctl_info *mci)
>  	pvt = mci->pvt_info;
>  
>  	pci_read_config_dword(pvt->system_address, AMBASE,
> -			(u32 *) & pvt->ambase);
> +			&pvt->u.ambase_bottom);
>  	pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32),
> -			((u32 *) & pvt->ambase) + sizeof(u32));
> +			&pvt->u.ambase_top);
>  
>  	maxdimmperch = pvt->maxdimmperch;
>  	maxch = pvt->maxch;
> 

nice work dan,
i can not find anything to worry about.


Acked-by: walter harms <wharms@bfs.de>


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

end of thread, other threads:[~2012-03-06  8:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-02  6:54 [patch] edac i5000: fix pointer math in i5000_get_mc_regs() Dan Carpenter
2012-03-02  9:00 ` walter harms
2012-03-02 19:09   ` Dan Carpenter
2012-03-02 19:20     ` walter harms
2012-03-05  8:59   ` [patch v2] edac i5000, i5400: " Dan Carpenter
2012-03-05  9:45     ` walter harms
2012-03-05  9:52       ` Dan Carpenter
2012-03-05 10:07         ` walter harms
2012-03-06  6:38         ` [patch v3] " Dan Carpenter
2012-03-06  8:50           ` walter harms

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