sisfb: Replace creative use of the ternary operator
Subsystems (2)
PATCH 1/1 sisfb: Replace creative use of the ternary operator
GETBITSTR() and related macros are defined in such a way that two of the macro arguments must be pairs of integers joined with a ':', selected between by prepending '1?' or '0?'. This is rather clever but not very readable. Redefine the macros and change the users so that each integer is a separate argument.
While we're at it, add a BUILD_BUG_ON_ZERO() to check that the redundant first part of the 'to' argument is consistent with the other arguments.
Signed-off-by Ben Hutchings <[email protected]>
--- drivers/video/fbdev/sis/init.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-)
drivers/video/fbdev/sis/init.c +15 -17
@@ -3320,11 +3320,9 @@ SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)return true; } -#ifndef GETBITSTR -#define GENBITSMASK (mask) GENMASK(1?mask,0?mask) -#define GETBITS (var,mask) (((var) & GENBITSMASK(mask)) >> (0?mask)) -#define GETBITSTR (val,from,to) ((GETBITS(val,from)) << (0?to)) -#endif +#define GETBITSTR (val, fromhigh, fromlow, tohigh, tolow) \ + (((((val) & GENMASK(fromhigh, fromlow)) >> (fromlow)) << (tolow)) + \ + BUILD_BUG_ON_ZERO((fromhigh) - (fromlow) != (tohigh) - (tolow)))void SiS_CalcCRRegisters (struct SiS_Private *SiS_Pr,int depth)
@@ -3363,23 +3361,23 @@ SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth) SiS_Pr->CCRT1CRTC[12 ] = (SiS_Pr->CVBlankEnd -1 ) &0xFF ;/* CR16 */ SiS_Pr->CCRT1CRTC[13 ] =/* SRA */ - GETBITSTR((SiS_Pr->CVTotal -2), 10:10, 0:0) | - GETBITSTR((SiS_Pr->CVDisplay -1), 10:10, 1:1) | - GETBITSTR((SiS_Pr->CVBlankStart-1), 10:10, 2:2) | - GETBITSTR((SiS_Pr->CVSyncStart -x), 10:10, 3:3) | - GETBITSTR((SiS_Pr->CVBlankEnd -1), 8:8, 4:4) | - GETBITSTR((SiS_Pr->CVSyncEnd ), 4:4, 5:5) ; +GETBITSTR ((SiS_Pr->CVTotal -2 ),10 ,10 ,0 ,0 ) | +GETBITSTR ((SiS_Pr->CVDisplay -1 ),10 ,10 ,1 ,1 ) | +GETBITSTR ((SiS_Pr->CVBlankStart-1 ),10 ,10 ,2 ,2 ) | +GETBITSTR ((SiS_Pr->CVSyncStart -x),10 ,10 ,3 ,3 ) | +GETBITSTR ((SiS_Pr->CVBlankEnd -1 ),8 ,8 ,4 ,4 ) | +GETBITSTR ((SiS_Pr->CVSyncEnd ),4 ,4 ,5 ,5 ) ; SiS_Pr->CCRT1CRTC[14 ] =/* SRB */ - GETBITSTR((SiS_Pr->CHTotal >> 3) - 5, 9:8, 1:0) | - GETBITSTR((SiS_Pr->CHDisplay >> 3) - 1, 9:8, 3:2) | - GETBITSTR((SiS_Pr->CHBlankStart >> 3) - 1, 9:8, 5:4) | - GETBITSTR((SiS_Pr->CHSyncStart >> 3) + 3, 9:8, 7:6) ; +GETBITSTR ((SiS_Pr->CHTotal >>3 ) -5 ,9 ,8 ,1 ,0 ) | +GETBITSTR ((SiS_Pr->CHDisplay >>3 ) -1 ,9 ,8 ,3 ,2 ) | +GETBITSTR ((SiS_Pr->CHBlankStart >>3 ) -1 ,9 ,8 ,5 ,4 ) | +GETBITSTR ((SiS_Pr->CHSyncStart >>3 ) +3 ,9 ,8 ,7 ,6 ) ; SiS_Pr->CCRT1CRTC[15 ] =/* SRC */ - GETBITSTR((SiS_Pr->CHBlankEnd >> 3) - 1, 7:6, 1:0) | - GETBITSTR((SiS_Pr->CHSyncEnd >> 3) + 3, 5:5, 2:2) ; +GETBITSTR ((SiS_Pr->CHBlankEnd >>3 ) -1 ,7 ,6 ,1 ,0 ) | +GETBITSTR ((SiS_Pr->CHSyncEnd >>3 ) +3 ,5 ,5 ,2 ,2 ) ; }void
Signature · 2 lines
Ben Hutchings Sturgeon's Law: Ninety percent of everything is crap.