diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-04-09 11:34:23 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-04-09 11:40:40 -0700 |
commit | a67dcc1e6ef6c0140087ee1cac630ea6ba664a3c (patch) | |
tree | b9ec008e2d00ac5570323523b815c4a66da0cbcd | |
parent | 56efa96c5a0cee362342b3cfa63d52f57611d6c2 (diff) |
Variable scope reductions as suggested by cppcheck
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | src/atiadjust.c | 4 | ||||
-rw-r--r-- | src/aticlock.c | 13 | ||||
-rw-r--r-- | src/aticonfig.c | 3 | ||||
-rw-r--r-- | src/atidac.c | 34 | ||||
-rw-r--r-- | src/atidga.c | 3 | ||||
-rw-r--r-- | src/atii2c.c | 10 | ||||
-rw-r--r-- | src/atimach64accel.c | 3 | ||||
-rw-r--r-- | src/atimach64exa.c | 5 | ||||
-rw-r--r-- | src/atimach64i2c.c | 6 | ||||
-rw-r--r-- | src/atimach64probe.c | 3 | ||||
-rw-r--r-- | src/atimach64render.c | 3 | ||||
-rw-r--r-- | src/atimach64xv.c | 3 | ||||
-rw-r--r-- | src/atimode.c | 7 | ||||
-rw-r--r-- | src/atiscreen.c | 20 | ||||
-rw-r--r-- | src/ativga.c | 4 |
15 files changed, 53 insertions, 68 deletions
diff --git a/src/atiadjust.c b/src/atiadjust.c index 7e3e4f8..a6a7b56 100644 --- a/src/atiadjust.c +++ b/src/atiadjust.c @@ -89,7 +89,7 @@ ATIAdjustFrame(ADJUST_FRAME_ARGS_DECL) { SCRN_INFO_PTR(arg); ATIPtr pATI = ATIPTR(pScreenInfo); - int Base, xy; + int Base; /* * Assume the caller has already done its homework in ensuring the physical @@ -111,7 +111,7 @@ ATIAdjustFrame(ADJUST_FRAME_ARGS_DECL) * Not in DGA. This reverse-calculates pScreenInfo->frame[XY][01] so * that the cursor does not move on mode switches. */ - xy = (Base << 3) / pATI->AdjustDepth; + int xy = (Base << 3) / pATI->AdjustDepth; pScreenInfo->frameX0 = xy % pATI->displayWidth; pScreenInfo->frameY0 = xy / pATI->displayWidth; pScreenInfo->frameX1 = diff --git a/src/aticlock.c b/src/aticlock.c index 53e28b5..cb2d07c 100644 --- a/src/aticlock.c +++ b/src/aticlock.c @@ -181,9 +181,7 @@ ATIClockCalculate DisplayModePtr pMode ) { - int N, M, D; - int ClockSelect, N1, MinimumGap; - int Frequency, Multiple; /* Used as temporaries */ + int ClockSelect; /* Set default values */ pATIHW->FeedbackDivider = pATIHW->ReferenceDivider = pATIHW->PostDivider = 0; @@ -198,16 +196,19 @@ ATIClockCalculate { /* Generate clock programme word, using units of kHz */ - MinimumGap = ((unsigned int)(-1)) >> 1; + int MinimumGap = ((unsigned int)(-1)) >> 1; + int Frequency, Multiple; /* Used as temporaries */ /* Loop through reference dividers */ - for (M = pATI->ClockDescriptor.MinM; + for (int M = pATI->ClockDescriptor.MinM; M <= pATI->ClockDescriptor.MaxM; M++) { /* Loop through post-dividers */ - for (D = 0; D < pATI->ClockDescriptor.NumD; D++) + for (int D = 0; D < pATI->ClockDescriptor.NumD; D++) { + int N, N1; + if (!pATI->ClockDescriptor.PostDividers[D]) continue; diff --git a/src/aticonfig.c b/src/aticonfig.c index 92ebecb..cc8435e 100644 --- a/src/aticonfig.c +++ b/src/aticonfig.c @@ -403,10 +403,9 @@ ATIProcessOptions xf86DrvMsg(pScreenInfo->scrnIndex, X_WARNING, "TV Out not supported for this chip.\n"); } else { - ATITVStandard std; pATI->OptionTvOut = TvOut; pATI->OptionTvStd = ATI_TV_STD_INVALID; - for (std = 0; std < ATI_TV_STDS_MAX_VALID; std++) { + for (ATITVStandard std = 0; std < ATI_TV_STDS_MAX_VALID; std++) { if (std != ATI_TV_STD_RESERVED1 && std != ATI_TV_STD_RESERVED2) { if (strncasecmp(TvStd, ATITVStandardNames[std], ATI_TV_STDS_NAME_MAXLEN)==0) { pATI->OptionTvStd = std; diff --git a/src/atidac.c b/src/atidac.c index f94e8ad..569e744 100644 --- a/src/atidac.c +++ b/src/atidac.c @@ -153,7 +153,6 @@ ATIDACPreInit ATIHWPtr pATIHW ) { - int Index, Index2; CARD8 maxColour = (1 << pATI->rgbBits) - 1; pATIHW->dac_read = pATIHW->dac_write = 0x00U; @@ -163,9 +162,9 @@ ATIDACPreInit * Set colour lookup table. The first entry has already been zeroed out. */ if (pATI->depth > 8) - for (Index = 1; Index < (NumberOf(pATIHW->lut) / 3); Index++) + for (int Index = 1; Index < (NumberOf(pATIHW->lut) / 3); Index++) { - Index2 = Index * 3; + int Index2 = Index * 3; pATIHW->lut[Index2 + 0] = pATIHW->lut[Index2 + 1] = pATIHW->lut[Index2 + 2] = Index; @@ -178,9 +177,9 @@ ATIDACPreInit * modes, this doesn't remain effective for very long... */ pATIHW->lut[3] = pATIHW->lut[4] = pATIHW->lut[5] = 0xFFU; - for (Index = 2; Index < (NumberOf(pATIHW->lut) / 3); Index++) + for (int Index = 2; Index < (NumberOf(pATIHW->lut) / 3); Index++) { - Index2 = Index * 3; + int Index2 = Index * 3; pATIHW->lut[Index2 + 0] = maxColour; pATIHW->lut[Index2 + 1] = 0x00U; pATIHW->lut[Index2 + 2] = maxColour; @@ -201,8 +200,6 @@ ATIDACSave ATIHWPtr pATIHW ) { - int Index; - #ifdef AVOID_CPIO pATIHW->dac_read = in8(M64_DAC_READ); @@ -217,7 +214,7 @@ ATIDACSave DACDelay; out8(M64_DAC_READ, 0x00U); DACDelay; - for (Index = 0; Index < NumberOf(pATIHW->lut); Index++) + for (int Index = 0; Index < NumberOf(pATIHW->lut); Index++) { pATIHW->lut[Index] = in8(M64_DAC_DATA); DACDelay; @@ -244,7 +241,7 @@ ATIDACSave DACDelay; outb(pATI->CPIO_DAC_READ, 0x00U); DACDelay; - for (Index = 0; Index < NumberOf(pATIHW->lut); Index++) + for (int Index = 0; Index < NumberOf(pATIHW->lut); Index++) { pATIHW->lut[Index] = inb(pATI->CPIO_DAC_DATA); DACDelay; @@ -271,8 +268,6 @@ ATIDACSet ATIHWPtr pATIHW ) { - int Index; - #ifdef AVOID_CPIO /* Load DAC's colour lookup table */ @@ -280,7 +275,7 @@ ATIDACSet DACDelay; out8(M64_DAC_WRITE, 0x00U); DACDelay; - for (Index = 0; Index < NumberOf(pATIHW->lut); Index++) + for (int Index = 0; Index < NumberOf(pATIHW->lut); Index++) { out8(M64_DAC_DATA, pATIHW->lut[Index]); DACDelay; @@ -302,7 +297,7 @@ ATIDACSet DACDelay; outb(pATI->CPIO_DAC_WRITE, 0x00U); DACDelay; - for (Index = 0; Index < NumberOf(pATIHW->lut); Index++) + for (int Index = 0; Index < NumberOf(pATIHW->lut); Index++) { outb(pATI->CPIO_DAC_DATA, pATIHW->lut[Index]); DACDelay; @@ -375,7 +370,6 @@ ATILoadPalette { ATIPtr pATI = ATIPTR(pScreenInfo); CARD8 *LUTEntry; - int i, j, Index; if (((pVisual->class | DynamicClass) == DirectColor) && ((1 << pVisual->nplanes) > (SizeOf(pATI->NewHW.lut) / 3))) @@ -404,8 +398,10 @@ ATILoadPalette if (minShift > blueShift) minShift = blueShift; - for (i = 0; i < nColours; i++) + for (int i = 0; i < nColours; i++) { + int j, Index; + if((Index = Indices[i]) < 0) continue; @@ -432,10 +428,10 @@ ATILoadPalette if (pScreenInfo->vtSema || pATI->currentMode) { /* Rewrite LUT entries that could have been changed */ - i = 1 << minShift; + int i = 1 << minShift; LUTEntry = pATI->NewHW.lut; - for (Index = 0; + for (int Index = 0; Index < (SizeOf(pATI->NewHW.lut) / 3); Index += i, LUTEntry += i * 3) if (fChanged[Index]) @@ -444,9 +440,9 @@ ATILoadPalette } else { - for (i = 0; i < nColours; i++) + for (int i = 0; i < nColours; i++) { - Index = Indices[i]; + int Index = Indices[i]; if ((Index < 0) || (Index >= (SizeOf(pATI->NewHW.lut) / 3))) continue; diff --git a/src/atidga.c b/src/atidga.c index 2560e6b..64ac428 100644 --- a/src/atidga.c +++ b/src/atidga.c @@ -70,10 +70,9 @@ BitsSet unsigned long data ) { - unsigned long mask = 1; int set = 0; - for (; mask; mask <<= 1) + for (unsigned long mask = 1; mask; mask <<= 1) if (data & mask) set++; diff --git a/src/atii2c.c b/src/atii2c.c index 72b7eac..a0fa050 100644 --- a/src/atii2c.c +++ b/src/atii2c.c @@ -226,13 +226,12 @@ ATII2CPutByte I2CBusPtr pI2CBus = pI2CDev->pI2CBus; ATII2CPtr pATII2C = pI2CBus->DriverPrivate.ptr; ATIPtr pATI = pATII2C->pATI; - int i; Bool Result; ATII2CSDADirOn; /* Set data line direction to out-bound */ /* Send data byte */ - for (i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { ATII2CSDABitSet(Data & 0x80U); ATII2CSCLBitOn; @@ -381,15 +380,14 @@ ATII2CFreeScreen int iScreen ) { - I2CBusPtr pI2CBus, *ppI2CBus; - ATII2CPtr pATII2C; + I2CBusPtr *ppI2CBus; int nI2CBus; nI2CBus = xf86I2CGetScreenBuses(iScreen, &ppI2CBus); while (--nI2CBus >= 0) { - pI2CBus = ppI2CBus[nI2CBus]; - pATII2C = pI2CBus->DriverPrivate.ptr; + I2CBusPtr pI2CBus = ppI2CBus[nI2CBus]; + ATII2CPtr pATII2C = pI2CBus->DriverPrivate.ptr; xf86DestroyI2CBusRec(pI2CBus, TRUE, TRUE); free(pATII2C); diff --git a/src/atimach64accel.c b/src/atimach64accel.c index f40155d..f35af53 100644 --- a/src/atimach64accel.c +++ b/src/atimach64accel.c @@ -886,7 +886,6 @@ ATIMach64SubsequentColorExpandScanline ATIPtr pATI = ATIPTR(pScreenInfo); CARD32 *pBitmapData = pATI->ExpansionBitmapScanlinePtr[iBuffer]; int w = pATI->ExpansionBitmapWidth; - int nDWord; ATIDRISync(pScreenInfo); @@ -896,7 +895,7 @@ ATIMach64SubsequentColorExpandScanline * Transfers are done in chunks of up to 64 bytes in length (32 on * earlier controllers). */ - nDWord = w; + int nDWord = w; if (nDWord > pATI->nHostFIFOEntries) nDWord = pATI->nHostFIFOEntries; diff --git a/src/atimach64exa.c b/src/atimach64exa.c index 99a924c..22bc210 100644 --- a/src/atimach64exa.c +++ b/src/atimach64exa.c @@ -410,8 +410,6 @@ Mach64SetupMemEXA(ScreenPtr pScreen) int cpp = (pScreenInfo->bitsPerPixel + 7) / 8; /* front and back buffer */ int bufferSize = pScreenInfo->virtualY * pScreenInfo->displayWidth * cpp; - /* always 16-bit z-buffer */ - int depthSize = pScreenInfo->virtualY * pScreenInfo->displayWidth * 2; ExaDriverPtr pExa = pATI->pExa; @@ -429,6 +427,9 @@ Mach64SetupMemEXA(ScreenPtr pScreen) int pixmapCache = 0; int next = 0; + /* always 16-bit z-buffer */ + int depthSize = pScreenInfo->virtualY * pScreenInfo->displayWidth * 2; + /* front buffer */ pATIDRIServer->frontOffset = 0; pATIDRIServer->frontPitch = pScreenInfo->displayWidth; diff --git a/src/atimach64i2c.c b/src/atimach64i2c.c index 2f243e5..ad7b63e 100644 --- a/src/atimach64i2c.c +++ b/src/atimach64i2c.c @@ -297,8 +297,6 @@ ATITVAddOnProbe ) { I2CDevPtr pI2CDev = xnfcalloc(1, SizeOf(I2CDevRec)); - int Index; - I2CByte tmp; static const CARD8 ATITVAddOnAddresses[] = {0x70, 0x40, 0x78, 0x72, 0x42}; @@ -309,8 +307,10 @@ ATITVAddOnProbe pI2CDev->AcknTimeout = pI2CBus->AcknTimeout; pI2CDev->ByteTimeout = pI2CBus->ByteTimeout; - for (Index = 0; Index < NumberOf(ATITVAddOnAddresses); Index++) + for (int Index = 0; Index < NumberOf(ATITVAddOnAddresses); Index++) { + I2CByte tmp; + pI2CDev->SlaveAddr = ATITVAddOnAddresses[Index]; if (xf86I2CFindDev(pI2CBus, pI2CDev->SlaveAddr)) diff --git a/src/atimach64probe.c b/src/atimach64probe.c index 430af6c..6d09834 100644 --- a/src/atimach64probe.c +++ b/src/atimach64probe.c @@ -257,7 +257,6 @@ Mach64Probe(DriverPtr pDriver, int flags) int numDevSections; int numUsed; Bool ProbeSuccess = FALSE; - int i; if (xf86GetPciVideoInfo() == NULL) return FALSE; @@ -279,7 +278,7 @@ Mach64Probe(DriverPtr pDriver, int flags) if (flags & PROBE_DETECT) { ProbeSuccess = TRUE; } else { - for (i = 0; i < numUsed; i++) { + for (int i = 0; i < numUsed; i++) { if (mach64_get_scrninfo(usedChips[i])) ProbeSuccess = TRUE; } diff --git a/src/atimach64render.c b/src/atimach64render.c index dae939e..ad104fa 100644 --- a/src/atimach64render.c +++ b/src/atimach64render.c @@ -819,7 +819,6 @@ Mach64Composite int y; } srcvert[4]; float dxy = 0.0, dwh = 0.0; - int i; ATIDRISync(pScreenInfo); @@ -843,7 +842,7 @@ Mach64Composite srcvert[3].x = srcX; srcvert[3].y = srcY + h; if (m3d->transform) { - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { v.vector[0] = IntToxFixed(srcvert[i].x); v.vector[1] = IntToxFixed(srcvert[i].y); v.vector[2] = xFixed1; diff --git a/src/atimach64xv.c b/src/atimach64xv.c index 6e34594..0aa8852 100644 --- a/src/atimach64xv.c +++ b/src/atimach64xv.c @@ -1353,7 +1353,6 @@ ATIMach64XVInitialiseAdaptor ATIPtr pATI = ATIPTR(pScreenInfo); XF86VideoAdaptorPtr *ppAdaptor = NULL; XF86VideoAdaptorPtr pAdaptor; - int Index; XF86VideoEncodingPtr enc = &(ATIMach64VideoEncoding[0]); XF86OffscreenImagePtr surf0 = &(ATIMach64Surface[0]); @@ -1426,6 +1425,8 @@ ATIMach64XVInitialiseAdaptor if (ATIMach64XVAtomGeneration != serverGeneration) { + int Index; + /* Refresh static data */ ATIMach64XVAtomGeneration = serverGeneration; diff --git a/src/atimode.c b/src/atimode.c index 00817f0..559a6ec 100644 --- a/src/atimode.c +++ b/src/atimode.c @@ -62,9 +62,7 @@ ATICopyVGAMemory pointer *to ) { - unsigned int iBank; - - for (iBank = 0; iBank < pATIHW->nBank; iBank++) + for (unsigned int iBank = 0; iBank < pATIHW->nBank; iBank++) { (*pATIHW->SetBank)(pATI, iBank); (void)memcpy(*to, *from, 0x00010000U); @@ -88,7 +86,6 @@ ATISwap ) { pointer save, *from, *to; - unsigned int iPlane = 0, PlaneMask = 1; CARD8 seq2, seq4, gra1, gra3, gra4, gra5, gra6, gra8; /* @@ -188,6 +185,8 @@ ATISwap } else { + unsigned int iPlane = 0, PlaneMask = 1; + gra4 = GetReg(GRAX, 0x04U); /* Setup planar mode memory */ diff --git a/src/atiscreen.c b/src/atiscreen.c index bb7fd4b..61bc01a 100644 --- a/src/atiscreen.c +++ b/src/atiscreen.c @@ -80,16 +80,14 @@ ATIRefreshArea ) { ATIPtr pATI = ATIPTR(pScreenInfo); - pointer pSrc, pDst; - int offset, w, h; while (nBox-- > 0) { - w = (pBox->x2 - pBox->x1) * pATI->AdjustDepth; - h = pBox->y2 - pBox->y1; - offset = (pBox->y1 * pATI->FBPitch) + (pBox->x1 * pATI->AdjustDepth); - pSrc = (char *)pATI->pShadow + offset; - pDst = (char *)pATI->pMemory + offset; + int w = (pBox->x2 - pBox->x1) * pATI->AdjustDepth; + int h = pBox->y2 - pBox->y1; + int offset = (pBox->y1 * pATI->FBPitch) + (pBox->x1 * pATI->AdjustDepth); + pointer pSrc = (char *)pATI->pShadow + offset; + pointer pDst = (char *)pATI->pMemory + offset; while (h-- > 0) { @@ -130,17 +128,15 @@ ATIMach64SetupMemXAA_NoDRI { ATIPtr pATI = ATIPTR(pScreenInfo); - int maxScanlines = ATIMach64MaxY; - int maxPixelArea, PixelArea; - { /* * Note: If PixelArea exceeds the engine's maximum, the excess is * never used, even though it would be useful for such things * as XVideo buffers. */ - maxPixelArea = maxScanlines * pScreenInfo->displayWidth; - PixelArea = pScreenInfo->videoRam * 1024 * 8 / pATI->bitsPerPixel; + int maxScanlines = ATIMach64MaxY; + int maxPixelArea = maxScanlines * pScreenInfo->displayWidth; + int PixelArea = pScreenInfo->videoRam * 1024 * 8 / pATI->bitsPerPixel; if (PixelArea > maxPixelArea) PixelArea = maxPixelArea; xf86InitFBManagerArea(pScreen, PixelArea, 2); diff --git a/src/ativga.c b/src/ativga.c index 168c5c1..583e4bc 100644 --- a/src/ativga.c +++ b/src/ativga.c @@ -45,8 +45,6 @@ ATIVGAPreInit ATIHWPtr pATIHW ) { - int Index; - /* Initialise sequencer register values */ pATIHW->seq[0] = 0x03U; pATIHW->seq[2] = 0x0FU; @@ -63,7 +61,7 @@ ATIVGAPreInit /* Initialise attribute controller register values */ { - for (Index = 0; Index < 16; Index++) + for (int Index = 0; Index < 16; Index++) pATIHW->attr[Index] = Index; pATIHW->attr[16] = 0x01U; |