edac i5000: fix pointer math in i5000_get_mc_regs()
Subsystems (4)
PATCH 1/1 edac i5000: fix pointer math in i5000_get_mc_regs()
"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.
---
I don't have the hardware to test this. Please review carefully.
drivers/edac/i5000_edac.c +1 -1
@@ -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;
Am 02.03.2012 07:54, schrieb Dan Carpenter:
Quoted 14 lines
"
pvt->ambase" is a u64 datatype. The intent here is to fill the first half in the first call topci_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 <[email protected]>---
I don't have the hardware to test this. Please review carefully.drivers/edac/i5000_edac.c +0
-0
drivers/edac/i5000_edac.c static void i5000_get_mc_regs(struct mem_ctl_info *mci) · line 1136
Quoted 8 lines
drivers/edac/i5000_edac.c +1
-1@@ -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
Quoted 17 lines · walter harms
drivers/edac/i5000_edac.c static void i5000_get_mc_regs(struct mem_ctl_info *mci) · line 1136
Quoted 13 lines
drivers/edac/i5000_edac.c +1
-1@@ -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.
Quoted 9 lines
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
Am 02.03.2012 20:09, schrieb Dan Carpenter:
Quoted 25 lines · walter harms
Quoted 24 lines
drivers/edac/i5000_edac.c static void i5000_get_mc_regs(struct mem_ctl_info *mci) · line 1136
Quoted 13 lines
drivers/edac/i5000_edac.c +1
-1@@ -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;
Quoted 8 lines
Quoted 2 lines
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
PATCH v2 1/1 edac i5000, i5400: fix pointer math in i5000_get_mc_regs()
In reply to walter harms"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.
---
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.
drivers/edac/i5400_edac.c +9 -3
@@ -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;
drivers/edac/i5000_edac.c +9 -3
@@ -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;
Re: [patch v2] edac i5000, i5400: fix pointer math in i5000_get_mc_regs()
Am 05.03.2012 10:01, schrieb Dan Carpenter:
Quoted 19 lines
"
pvt->ambase" is a u64 datatype. The intent here is to fill the first half in the first call topci_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 <[email protected]>---
v2: Redid it as with a union as Walter Harms suggested.
Fixed the same bug ini5400_edac.cas well.I don't have this hardware, so please review carefully.
drivers/edac/i5400_edac.c +0
-0@@ -343,7 +343,13 @@ struct i5400_pvt {struct pci_dev *branch_1;/* 22.0 */
drivers/edac/i5400_edac.c struct i5400_pvt { · line 353
Quoted 10 lines
drivers/edac/i5400_edac.c +7
-1u16 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
Quoted 45 lines
drivers/edac/i5400_edac.c +2
-2u16 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;drivers/edac/i5000_edac.c +9
-3@@ -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;
Re: [patch v2] edac i5000, i5400: fix pointer math in i5000_get_mc_regs()
Quoted 22 lines · walter harms
Am 05.03.2012 10:01, schrieb Dan Carpenter:
Quoted 19 lines
"
pvt->ambase" is a u64 datatype. The intent here is to fill the first half in the first call topci_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 <[email protected]>---
v2: Redid it as with a union as Walter Harms suggested.
Fixed the same bug ini5400_edac.cas well.I don't have this hardware, so please review carefully.
drivers/edac/i5400_edac.c +0
-0@@ -343,7 +343,13 @@ struct i5400_pvt {struct pci_dev *branch_1;/* 22.0 */
Quoted 12 lines
drivers/edac/i5400_edac.c struct i5400_pvt { · line 353
Quoted 10 lines
drivers/edac/i5400_edac.c +7
-1u16 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
Re: [patch v2] edac i5000, i5400: fix pointer math in i5000_get_mc_regs()
Am 05.03.2012 10:52, schrieb Dan Carpenter:
Quoted 36 lines · walter harms
Quoted 22 lines
Am 05.03.2012 10:01, schrieb Dan Carpenter:
Quoted 19 lines
"
pvt->ambase" is a u64 datatype. The intent here is to fill the first half in the first call topci_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 <[email protected]>---
v2: Redid it as with a union as Walter Harms suggested.
Fixed the same bug ini5400_edac.cas well.I don't have this hardware, so please review carefully.
drivers/edac/i5400_edac.c +0
-0@@ -343,7 +343,13 @@ struct i5400_pvt {struct pci_dev *branch_1;/* 22.0 */ Quoted 12 lines
drivers/edac/i5400_edac.c struct i5400_pvt { · line 353
Quoted 10 lines
drivers/edac/i5400_edac.c +7
-1u16 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 ?
Quoted 2 lines
Are you asking or telling?
asking, i am really curious.
re,
wh
Quoted 5 lines
I guess I'll add a
__packedand resend in case it's an issue.regards,
dan carpenter
PATCH v3 1/1 edac i5000, i5400: fix pointer math in i5000_get_mc_regs()
In reply to 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.
---
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.
drivers/edac/i5400_edac.c +9 -3
@@ -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;
drivers/edac/i5000_edac.c +9 -3
@@ -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;
Re: [patch v3] edac i5000, i5400: fix pointer math in i5000_get_mc_regs()
Am 06.03.2012 07:38, schrieb Dan Carpenter:
Quoted 66 lines
"
pvt->ambase" is a u64 datatype. The intent here is to fill the first half in the first call topci_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 <[email protected]>---
v2: Redid it as with a union as Walter Harms suggested.
Fixed the same bug ini5400_edac.cas well.
v3: Make the struct__packedjust in case.I don't have this hardware, so please review carefully.
drivers/edac/i5400_edac.c +9
-3@@ -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;drivers/edac/i5000_edac.c +7
-1@@ -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;
drivers/edac/i5000_edac.c static void i5000_get_mc_regs(struct mem_ctl_info *mci) · line 1142
Quoted 10 lines
drivers/edac/i5000_edac.c +2
-2pci_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.