staging/xgifb: Consolidate if/else if with identical code branches
PATCH 1/5 staging/xgifb: Consolidate if/else if with identical code branches
Both branches of this if statement execute the same code. Thus we can || them together and remove code duplication
--- drivers/staging/xgifb/vb_setmode.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)
drivers/staging/xgifb/vb_setmode.c +2 -5
@@ -5572,13 +5572,10 @@ static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,if (pVBInfo->VBType & (VB_SIS301B |VB_SIS302B |VB_SIS301LV |VB_SIS302LV |VB_XGI301C )) {if (!(pVBInfo->SetFlag & DisableChA)) { -if (pVBInfo->SetFlag & EnableChA) { +if ((pVBInfo->SetFlag & EnableChA) || + (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {/* Power on */ xgifb_reg_set (pVBInfo->Part1Port,0x1E ,0x20 ); - }else if (pVBInfo->VBInfo & SetCRT2ToDualEdge) { -/* Power on */ -xgifb_reg_set (pVBInfo->Part1Port, -0x1E ,0x20 ); } }
Signature · 1 line
1.7.8.6
PATCH 2/5 staging/xgifb: Remove unnecessary casts
Both functions xgifb_reg_get and inb return an u8 value, so we don't need to cast their return value to unsigned char.
-> remove the cast
--- drivers/staging/xgifb/vb_init.c | 2 +- drivers/staging/xgifb/vb_setmode.c | 66 +++++++++++++++++------------------- 2 files changed, 32 insertions(+), 36 deletions(-)
drivers/staging/xgifb/vb_init.c +1 -1
@@ -1341,7 +1341,7 @@ unsigned char XGIInitNew(struct pci_dev *pdev)xgifb_reg_and_or (pVBInfo->Part0Port,0x3F ,0xEF ,0x00 );xgifb_reg_set (pVBInfo->Part1Port,0x00 ,0x00 );/* chk if BCLK>=100MHz */ - temp1 = (unsigned char )xgifb_reg_get (pVBInfo->P3d4,0x7B ); + temp1 =xgifb_reg_get (pVBInfo->P3d4,0x7B ); temp = (unsigned char ) ((temp1 >>4 ) &0x0F ); xgifb_reg_set(pVBInfo->Part1Port,
drivers/staging/xgifb/vb_setmode.c +31 -35
204 lines not on this page · raw message
Signature · 1 line
1.7.8.6
PATCH 3/5 staging/xgifb: Remove code without effect
In reply to Peter HueweThe tempal variable is assigned and then immediately overwritten. -> remove everything without effect.
The inb is kept for possible side effects.
--- drivers/staging/xgifb/vb_setmode.c | 9 +-------- 1 files changed, 1 insertions(+), 8 deletions(-)
drivers/staging/xgifb/vb_setmode.c +1 -8
@@ -1778,14 +1778,7 @@ static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex, } }/* {End of VB} */ - tempal =inb ((pVBInfo->P3ca +0x02 )); - tempal = tempal >>2 ; - tempal &=0x03 ; - -/* for Dot8 Scaling LCD */ -if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot)) - tempal = tempal ^ tempal;/* ; set to VCLK25MHz always */ - +inb ((pVBInfo->P3ca +0x02 )); tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;return tempal; }
Signature · 1 line
1.7.8.6
Re: [PATCH 3/5] staging/xgifb: Remove code without effect
Quoted 5 lines · Peter Huewe
The tempal variable is assigned and then immediately overwritten. -> remove everything without effect.
The inb is kept for possible side effects.
This was dead code after we removed old mode <= 14 support in 34c13ee2b "staging: xgifb: drop code for legacy VGA modes".
I don't know if the inb() is still needed. Aaro?
regards,
dan carpenter
PATCH 4/5 staging/xgifb: Consolidate return paths
In reply to Peter HueweBoth branches of this if statement end in the same return statement. -> move the return to the bottom and get rid of the else statement.
--- drivers/staging/xgifb/vb_setmode.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/staging/xgifb/vb_setmode.c +1 -3
@@ -2860,10 +2860,8 @@ static unsigned short XGI_GetOffset(unsigned short ModeNo, temp =0x6B ;if (infoflag & InterlaceMode) temp = temp <<1 ; -return temp * colordepth; - }else { -return temp * colordepth; } +return temp * colordepth; } static void XGI_SetCRT2Offset(unsigned short ModeNo,
Signature · 1 line
1.7.8.6
PATCH 5/5 staging/xgifb: Remove duplicated code in loops.
In reply to Peter HueweInstead of calling the same function three times in a loop, multiply the loop counter by three.
And since the value in DAC_TEST_PARMS is always the same we can use the value directly.
--- drivers/staging/xgifb/vb_setmode.c | 11 +++-------- 1 files changed, 3 insertions(+), 8 deletions(-)
drivers/staging/xgifb/vb_setmode.c +3 -8
@@ -5464,7 +5464,6 @@ void XGI_SenseCRT1(struct vb_device_info *pVBInfo)unsigned char CR17 ,CR63 ,SR31 ;unsigned short temp; -unsigned char DAC_TEST_PARMS [3 ] = {0x0F ,0x0F ,0x0F };int i;xgifb_reg_set (pVBInfo->P3c4,0x05 ,0x86 );
@@ -5518,10 +5517,8 @@ void XGI_SenseCRT1(struct vb_device_info *pVBInfo)outb (0x00 , pVBInfo->P3c8); -for (i =0 ; i <256 ; i++) { -outb ((unsigned char )DAC_TEST_PARMS [0 ], (pVBInfo->P3c8 +1 )); -outb ((unsigned char )DAC_TEST_PARMS [1 ], (pVBInfo->P3c8 +1 )); -outb ((unsigned char )DAC_TEST_PARMS [2 ], (pVBInfo->P3c8 +1 )); +for (i =0 ; i <256 *3 ; i++) { +outb (0x0F , (pVBInfo->P3c8 +1 ));/* DAC_TEST_PARMS */ }mdelay (1 );
@@ -5537,9 +5534,7 @@ void XGI_SenseCRT1(struct vb_device_info *pVBInfo)/* avoid display something, set BLACK DAC if not restore DAC */ outb (0x00 , pVBInfo->P3c8); -for (i =0 ; i <256 ; i++) { -outb (0 , (pVBInfo->P3c8 +1 )); -outb (0 , (pVBInfo->P3c8 +1 )); +for (i =0 ; i <256 *3 ; i++) {outb (0 , (pVBInfo->P3c8 +1 )); }
Signature · 1 line
1.7.8.6
Re: [PATCH 5/5] staging/xgifb: Remove duplicated code in loops.
drivers/staging/xgifb/vb_setmode.c void XGI_SenseCRT1(struct vb_device_info *pVBInfo) · line 5521
Quoted 6 lines · Peter Huewe
drivers/staging/xgifb/vb_setmode.c +2
-4-for (i =0 ; i <256 ; i++) { -outb ((unsigned char )DAC_TEST_PARMS [0 ], (pVBInfo->P3c8 +1 )); -outb ((unsigned char )DAC_TEST_PARMS [1 ], (pVBInfo->P3c8 +1 )); -outb ((unsigned char )DAC_TEST_PARMS [2 ], (pVBInfo->P3c8 +1 )); +for (i =0 ; i <256 *3 ; i++) { +outb (0x0F , (pVBInfo->P3c8 +1 ));/* DAC_TEST_PARMS */
The original code looks buggy, but it's been that way from the initial commit so I have no idea what was intended. Perhaps the "+ 1" was supposed to be a "+ i". There is no way to know really.
regards,
dan carpenter