From 61233adbcab4c8964e2093563ecaa94d76a0e2a4 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 8 May 2024 13:32:04 +0200 Subject: [PATCH] treewide: replace xnfreallocarray macro call by XNFreallocarray() The xnfreallocarray was added along (and just as an alias to) XNFreallocarray back a decade ago. It's just used in a few places and it's only saves us from passing the first parameter (NULL), so the actual benefit isn't really huge. No (known) driver is using it, so the macro can be dropped entirely. Fixes: ae75d50395fdd7a6bc382ba73e923c460764c702 Signed-off-by: Enrico Weigelt, metux IT consult Part-of: --- Xi/exevents.c | 2 +- dix/devices.c | 2 +- hw/xfree86/common/xf86AutoConfig.c | 2 +- hw/xfree86/common/xf86Bus.c | 10 +++++----- hw/xfree86/common/xf86Config.c | 2 +- hw/xfree86/common/xf86Configure.c | 2 +- hw/xfree86/common/xf86Helper.c | 18 +++++++++--------- hw/xfree86/common/xf86pciBus.c | 4 ++-- hw/xfree86/common/xf86platformBus.c | 2 +- hw/xfree86/common/xf86sbusBus.c | 6 +++--- hw/xfree86/i2c/xf86i2c.c | 2 +- hw/xfree86/os-support/bus/Sbus.c | 2 +- hw/xwayland/xwayland-dmabuf.c | 2 +- hw/xwayland/xwayland-glamor-xv.c | 2 +- include/os.h | 1 - os/connection.c | 4 ++-- 16 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Xi/exevents.c b/Xi/exevents.c index 6bfc9a6de..71384254d 100644 --- a/Xi/exevents.c +++ b/Xi/exevents.c @@ -615,7 +615,7 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to) if (from->button->xkb_acts) { size_t maxbuttons = max(to->button->numButtons, from->button->numButtons); - to->button->xkb_acts = xnfreallocarray(to->button->xkb_acts, + to->button->xkb_acts = XNFreallocarray(to->button->xkb_acts, maxbuttons, sizeof(XkbAction)); memset(to->button->xkb_acts, 0, maxbuttons * sizeof(XkbAction)); diff --git a/dix/devices.c b/dix/devices.c index 9ffe52c45..d63cebbb3 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -2569,7 +2569,7 @@ RecalculateMasterButtons(DeviceIntPtr slave) master->button->numButtons = maxbuttons; if (last_num_buttons < maxbuttons) { - master->button->xkb_acts = xnfreallocarray(master->button->xkb_acts, + master->button->xkb_acts = XNFreallocarray(master->button->xkb_acts, maxbuttons, sizeof(XkbAction)); memset(&master->button->xkb_acts[last_num_buttons], diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c index 65773ef00..7311d8ddc 100644 --- a/hw/xfree86/common/xf86AutoConfig.c +++ b/hw/xfree86/common/xf86AutoConfig.c @@ -107,7 +107,7 @@ AppendToList(const char *s, const char ***list, int *lines) str = xnfstrdup(s); for (p = strtok(str, "\n"); p; p = strtok(NULL, "\n")) { (*lines)++; - *list = xnfreallocarray(*list, *lines + 1, sizeof(**list)); + *list = XNFreallocarray(*list, *lines + 1, sizeof(**list)); newstr = XNFalloc(strlen(p) + 2); strcpy(newstr, p); strcat(newstr, "\n"); diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c index 6c5c730a1..98cbd6d0b 100644 --- a/hw/xfree86/common/xf86Bus.c +++ b/hw/xfree86/common/xf86Bus.c @@ -297,7 +297,7 @@ int xf86AllocateEntity(void) { xf86NumEntities++; - xf86Entities = xnfreallocarray(xf86Entities, + xf86Entities = XNFreallocarray(xf86Entities, xf86NumEntities, sizeof(EntityPtr)); xf86Entities[xf86NumEntities - 1] = xnfcalloc(1, sizeof(EntityRec)); xf86Entities[xf86NumEntities - 1]->entityPrivates = @@ -355,11 +355,11 @@ xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex) } pScrn->numEntities++; - pScrn->entityList = xnfreallocarray(pScrn->entityList, + pScrn->entityList = XNFreallocarray(pScrn->entityList, pScrn->numEntities, sizeof(int)); pScrn->entityList[pScrn->numEntities - 1] = entityIndex; xf86Entities[entityIndex]->inUse = TRUE; - pScrn->entityInstanceList = xnfreallocarray(pScrn->entityInstanceList, + pScrn->entityInstanceList = XNFreallocarray(pScrn->entityInstanceList, pScrn->numEntities, sizeof(int)); pScrn->entityInstanceList[pScrn->numEntities - 1] = 0; @@ -457,7 +457,7 @@ xf86AddDevToEntity(int entityIndex, GDevPtr dev) pEnt = xf86Entities[entityIndex]; pEnt->numInstances++; - pEnt->devices = xnfreallocarray(pEnt->devices, + pEnt->devices = XNFreallocarray(pEnt->devices, pEnt->numInstances, sizeof(GDevPtr)); pEnt->devices[pEnt->numInstances - 1] = dev; dev->claimed = TRUE; @@ -651,7 +651,7 @@ xf86AllocateEntityPrivateIndex(void) idx = xf86EntityPrivateCount++; for (i = 0; i < xf86NumEntities; i++) { pEnt = xf86Entities[i]; - nprivs = xnfreallocarray(pEnt->entityPrivates, + nprivs = XNFreallocarray(pEnt->entityPrivates, xf86EntityPrivateCount, sizeof(DevUnion)); /* Zero the new private */ memset(&nprivs[idx], 0, sizeof(DevUnion)); diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c index d64138bb4..8c4c9842c 100644 --- a/hw/xfree86/common/xf86Config.c +++ b/hw/xfree86/common/xf86Config.c @@ -1014,7 +1014,7 @@ addDevice(InputInfoPtr * list, InputInfoPtr pInfo) for (devs = list; devs && *devs; devs++) count++; - list = xnfreallocarray(list, count + 1, sizeof(InputInfoPtr)); + list = XNFreallocarray(list, count + 1, sizeof(InputInfoPtr)); list[count] = NULL; list[count - 1] = pInfo; diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index 1da9aa613..c342829e3 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -115,7 +115,7 @@ xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, /* Allocate new structure occurrence */ i = nDevToConfig++; DevToConfig = - xnfreallocarray(DevToConfig, nDevToConfig, sizeof(DevToConfigRec)); + XNFreallocarray(DevToConfig, nDevToConfig, sizeof(DevToConfigRec)); memset(DevToConfig + i, 0, sizeof(DevToConfigRec)); DevToConfig[i].GDev.chipID = diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c index 9794b9cb0..25d23b85b 100644 --- a/hw/xfree86/common/xf86Helper.c +++ b/hw/xfree86/common/xf86Helper.c @@ -81,7 +81,7 @@ xf86AddDriver(DriverPtr driver, void *module, int flags) xf86NumDrivers = 0; xf86NumDrivers++; - xf86DriverList = xnfreallocarray(xf86DriverList, + xf86DriverList = XNFreallocarray(xf86DriverList, xf86NumDrivers, sizeof(DriverPtr)); xf86DriverList[xf86NumDrivers - 1] = XNFalloc(sizeof(DriverRec)); *xf86DriverList[xf86NumDrivers - 1] = *driver; @@ -114,7 +114,7 @@ xf86AddInputDriver(InputDriverPtr driver, void *module, int flags) xf86NumInputDrivers = 0; xf86NumInputDrivers++; - xf86InputDriverList = xnfreallocarray(xf86InputDriverList, + xf86InputDriverList = XNFreallocarray(xf86InputDriverList, xf86NumInputDrivers, sizeof(InputDriverPtr)); xf86InputDriverList[xf86NumInputDrivers - 1] = @@ -170,7 +170,7 @@ xf86AllocateScreen(DriverPtr drv, int flags) if (xf86GPUScreens == NULL) xf86NumGPUScreens = 0; i = xf86NumGPUScreens++; - xf86GPUScreens = xnfreallocarray(xf86GPUScreens, xf86NumGPUScreens, + xf86GPUScreens = XNFreallocarray(xf86GPUScreens, xf86NumGPUScreens, sizeof(ScrnInfoPtr)); xf86GPUScreens[i] = xnfcalloc(1, sizeof(ScrnInfoRec)); pScrn = xf86GPUScreens[i]; @@ -181,7 +181,7 @@ xf86AllocateScreen(DriverPtr drv, int flags) xf86NumScreens = 0; i = xf86NumScreens++; - xf86Screens = xnfreallocarray(xf86Screens, xf86NumScreens, + xf86Screens = XNFreallocarray(xf86Screens, xf86NumScreens, sizeof(ScrnInfoPtr)); xf86Screens[i] = xnfcalloc(1, sizeof(ScrnInfoRec)); pScrn = xf86Screens[i]; @@ -292,7 +292,7 @@ xf86AllocateScrnInfoPrivateIndex(void) idx = xf86ScrnInfoPrivateCount++; for (i = 0; i < xf86NumScreens; i++) { pScr = xf86Screens[i]; - nprivs = xnfreallocarray(pScr->privates, + nprivs = XNFreallocarray(pScr->privates, xf86ScrnInfoPrivateCount, sizeof(DevUnion)); /* Zero the new private */ memset(&nprivs[idx], 0, sizeof(DevUnion)); @@ -300,7 +300,7 @@ xf86AllocateScrnInfoPrivateIndex(void) } for (i = 0; i < xf86NumGPUScreens; i++) { pScr = xf86GPUScreens[i]; - nprivs = xnfreallocarray(pScr->privates, + nprivs = XNFreallocarray(pScr->privates, xf86ScrnInfoPrivateCount, sizeof(DevUnion)); /* Zero the new private */ memset(&nprivs[idx], 0, sizeof(DevUnion)); @@ -560,7 +560,7 @@ xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp, if (i == scrp->confScreen->numdisplays) { scrp->confScreen->numdisplays++; scrp->confScreen->displays = - xnfreallocarray(scrp->confScreen->displays, + XNFreallocarray(scrp->confScreen->displays, scrp->confScreen->numdisplays, sizeof(DispPtr)); xf86DrvMsg(scrp->scrnIndex, X_INFO, "Creating default Display subsection in Screen section\n" @@ -1329,7 +1329,7 @@ xf86MatchDevice(const char *drivername, GDevPtr ** sectlist) /* * we have a matching driver that wasn't claimed, yet */ - pgdp = xnfreallocarray(pgdp, i + 2, sizeof(GDevPtr)); + pgdp = XNFreallocarray(pgdp, i + 2, sizeof(GDevPtr)); pgdp[i++] = screensecptr->device; } for (k = 0; k < screensecptr->num_gpu_devices; k++) { @@ -1352,7 +1352,7 @@ xf86MatchDevice(const char *drivername, GDevPtr ** sectlist) if (gdp->driver && !gdp->claimed && !xf86NameCmp(gdp->driver, drivername)) { /* we have a matching driver that wasn't claimed yet */ - pgdp = xnfreallocarray(pgdp, i + 2, sizeof(GDevPtr)); + pgdp = XNFreallocarray(pgdp, i + 2, sizeof(GDevPtr)); pgdp[i++] = gdp; } j++; diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c index 15c304d26..586ca9a9d 100644 --- a/hw/xfree86/common/xf86pciBus.c +++ b/hw/xfree86/common/xf86pciBus.c @@ -102,7 +102,7 @@ xf86PciProbe(void) while ((info = pci_device_next(iter)) != NULL) { if (PCIINFOCLASSES(info->device_class)) { num++; - xf86PciVideoInfo = xnfreallocarray(xf86PciVideoInfo, + xf86PciVideoInfo = XNFreallocarray(xf86PciVideoInfo, num + 1, sizeof(struct pci_device *)); xf86PciVideoInfo[num] = NULL; @@ -979,7 +979,7 @@ xf86MatchPciInstances(const char *driverName, int vendorID, /* Allocate an entry in the lists to be returned */ numFound++; - retEntities = xnfreallocarray(retEntities, numFound, sizeof(int)); + retEntities = XNFreallocarray(retEntities, numFound, sizeof(int)); retEntities[numFound - 1] = xf86ClaimPciSlot(pPci, drvp, instances[i].chip, instances[i].dev, diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c index eeeff2b88..2a2387ed7 100644 --- a/hw/xfree86/common/xf86platformBus.c +++ b/hw/xfree86/common/xf86platformBus.c @@ -65,7 +65,7 @@ struct xf86_platform_device *xf86_platform_devices; int xf86_add_platform_device(struct OdevAttributes *attribs, Bool unowned) { - xf86_platform_devices = xnfreallocarray(xf86_platform_devices, + xf86_platform_devices = XNFreallocarray(xf86_platform_devices, xf86_num_platform_devices + 1, sizeof(struct xf86_platform_device)); diff --git a/hw/xfree86/common/xf86sbusBus.c b/hw/xfree86/common/xf86sbusBus.c index eeee3ebfd..7048f1d16 100644 --- a/hw/xfree86/common/xf86sbusBus.c +++ b/hw/xfree86/common/xf86sbusBus.c @@ -68,7 +68,7 @@ CheckSbusDevice(const char *device, int fbNum) if (!sbusDeviceTable[i].devId) return; xf86SbusInfo = - xnfreallocarray(xf86SbusInfo, ++xf86nSbusInfo + 1, sizeof(psdp)); + XNFreallocarray(xf86SbusInfo, ++xf86nSbusInfo + 1, sizeof(psdp)); xf86SbusInfo[xf86nSbusInfo] = NULL; xf86SbusInfo[xf86nSbusInfo - 1] = psdp = xnfcalloc(1, sizeof(sbusDevice)); psdp->devId = sbusDeviceTable[i].devId; @@ -406,7 +406,7 @@ xf86MatchSbusInstances(const char *driverName, int sbusDevId, if (psdp->fd == -2) continue; ++allocatedInstances; - instances = xnfreallocarray(instances, + instances = XNFreallocarray(instances, allocatedInstances, sizeof(struct Inst)); instances[allocatedInstances - 1].sbus = psdp; instances[allocatedInstances - 1].dev = NULL; @@ -532,7 +532,7 @@ xf86MatchSbusInstances(const char *driverName, int sbusDevId, /* Allocate an entry in the lists to be returned */ numFound++; - retEntities = xnfreallocarray(retEntities, numFound, sizeof(int)); + retEntities = XNFreallocarray(retEntities, numFound, sizeof(int)); retEntities[numFound - 1] = xf86ClaimSbusSlot(psdp, drvp, instances[i].dev, instances[i].dev->active ? TRUE : FALSE); diff --git a/hw/xfree86/i2c/xf86i2c.c b/hw/xfree86/i2c/xf86i2c.c index 59733b032..3c295b6dd 100644 --- a/hw/xfree86/i2c/xf86i2c.c +++ b/hw/xfree86/i2c/xf86i2c.c @@ -872,7 +872,7 @@ xf86I2CGetScreenBuses(int scrnIndex, I2CBusPtr ** pppI2CBus) if (!pppI2CBus) continue; - *pppI2CBus = xnfreallocarray(*pppI2CBus, n, sizeof(I2CBusPtr)); + *pppI2CBus = XNFreallocarray(*pppI2CBus, n, sizeof(I2CBusPtr)); (*pppI2CBus)[n - 1] = pI2CBus; } diff --git a/hw/xfree86/os-support/bus/Sbus.c b/hw/xfree86/os-support/bus/Sbus.c index 3c7119d46..4a18afdd6 100644 --- a/hw/xfree86/os-support/bus/Sbus.c +++ b/hw/xfree86/os-support/bus/Sbus.c @@ -440,7 +440,7 @@ sparcPromAssignNodes(void) for (i = 0, j = 0; i < 32; i++) if (devicePtrs[i] && devicePtrs[i]->fbNum == -1) j++; - xf86SbusInfo = xnfreallocarray(xf86SbusInfo, n + j + 1, sizeof(psdp)); + xf86SbusInfo = XNFreallocarray(xf86SbusInfo, n + j + 1, sizeof(psdp)); for (i = 0, psdpp = xf86SbusInfo; i < 32; i++) if (devicePtrs[i]) { if (devicePtrs[i]->fbNum == -1) { diff --git a/hw/xwayland/xwayland-dmabuf.c b/hw/xwayland/xwayland-dmabuf.c index e485e5b1c..e7a5af23c 100644 --- a/hw/xwayland/xwayland-dmabuf.c +++ b/hw/xwayland/xwayland-dmabuf.c @@ -204,7 +204,7 @@ xwl_dmabuf_get_formats_for_device(struct xwl_dmabuf_feedback *xwl_feedback, drmD struct xwl_device_formats *dev_formats = &xwl_feedback->dev_formats[i]; /* Append the formats from this tranche to the list */ - ret = xnfreallocarray(ret, count + dev_formats->num_formats, sizeof(CARD32)); + ret = XNFreallocarray(ret, count + dev_formats->num_formats, sizeof(CARD32)); for (int j = 0; j < dev_formats->num_formats; j++) { Bool found = FALSE; diff --git a/hw/xwayland/xwayland-glamor-xv.c b/hw/xwayland/xwayland-glamor-xv.c index 23e7100e4..f1c5ca1b2 100644 --- a/hw/xwayland/xwayland-glamor-xv.c +++ b/hw/xwayland/xwayland-glamor-xv.c @@ -216,7 +216,7 @@ xwl_glamor_xv_add_formats(XvAdaptorPtr pa) void *moreSpace; totFormat *= 2; - moreSpace = xnfreallocarray(pFormat, totFormat, + moreSpace = XNFreallocarray(pFormat, totFormat, sizeof(XvFormatRec)); pFormat = moreSpace; pf = pFormat + numFormat; diff --git a/include/os.h b/include/os.h index 4f89f9696..0c81818b0 100644 --- a/include/os.h +++ b/include/os.h @@ -81,7 +81,6 @@ typedef struct _NewClientRec *NewClientPtr; #define xnfstrdup(s) XNFstrdup(s) #define xallocarray(num, size) reallocarray(NULL, (num), (size)) -#define xnfreallocarray(ptr, num, size) XNFreallocarray((ptr), (num), (size)) #endif #include diff --git a/os/connection.c b/os/connection.c index c47cf6ea7..f7eb95b1e 100644 --- a/os/connection.c +++ b/os/connection.c @@ -1034,9 +1034,9 @@ ListenOnOpenFD(int fd, int noxauth) /* Allocate space to store it */ ListenTransFds = - xnfreallocarray(ListenTransFds, ListenTransCount + 1, sizeof(int)); + XNFreallocarray(ListenTransFds, ListenTransCount + 1, sizeof(int)); ListenTransConns = - xnfreallocarray(ListenTransConns, ListenTransCount + 1, + XNFreallocarray(ListenTransConns, ListenTransCount + 1, sizeof(XtransConnInfo)); /* Store it */