From nobody Tue Apr 29 18:30:34 2025 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Zn8581PMPz5vN1r; Tue, 29 Apr 2025 18:30:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Zn8562gbQz4HMG; Tue, 29 Apr 2025 18:30:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745951434; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7ML9YlBuNI8C2CXGj7DUyxIXtRFWoPfeCWsd5lTNVYk=; b=N8EPuEBwVhcT2PZ5JoLQ5d2wM4OfADs8dT0g32Qve3qwgRapldjtN8cnreypoQqh8PWeS1 KJ5R58pSoZaj6XVlAawDoHqvkFkfYyXnxoPX/EV64p8ucONII1fnUY/f8zFw4BPJg4ovUJ kKKAMHAMQMXcJecBhUlOTM/+hbgs8r5b0ljRE/aDYKONnT11rrMdJ7aboPfmScUlG7Cfq1 H4XFa2N4+Yqkdj1R1gBr4RnI5Tp3GJESHFBYh7CG56sDzwdKJTbCV3F12xFLed4/id4ZxI DNilN1INkx1W17fgfR8hLDqYb23zi/4SX/hpcs66AlbIFeaKKMASMwkyO0HNhg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1745951434; a=rsa-sha256; cv=none; b=Fw6nnYfyg1Ns7029HTOqBuffVEKb1r8t1ijcugSAW8SFLiZtxvPtv/1WUVlLcHZS1yZJDk w6bWAU35RXEJBmC4As/vmGIosVWgIJC9RkaTfOb6MBUM6FvW94H680PFOA/e+MoEbbr/Zh 7z44rwr7/GwLWjUDwYz3g1f1bAJp1xdBKMyaRRTPfxkSEIUFKz7zeqMK4/rw1FSMAywvDf amKoq9McWohPFGQFdh5V5loQeH9Zi6V5KRHvl7KUfmh1HwxSH4LVvXCCr+VPFdzb4qbmmY 5i/sG0vvDbkALSPXLWYXWZgibYh16+KmHNsoe/uy7Tb+2uYQJPOBC/NNjEi+GQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745951434; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7ML9YlBuNI8C2CXGj7DUyxIXtRFWoPfeCWsd5lTNVYk=; b=WVGv2tCTaPXoqtb9dQJ29UmFPBX5b3lJFd3iQ6IGUPum1+hzOMX2j3ZkLaX4xD2do67UiZ fsutwAi4pYqUMIuznXhSjqD+/sryqWsImj+zVVrqdG67RwVPYMOyw0J4XDMGth/Eq1TwXc dzZhAo+wfVVQ9jUkPXT4UIAPubP6HsbJ34T1wQNr+BWJW5g7T8qMOUM53QzYI5BISCS2ae xMMaledoTv8Cn3zNviwHxbVJKoRYTLWT/GYZT67I3bYptmFm/Z+GVjXQsZq6JJ3cZzUNrX OSoUHfaVjdukW+x2pb3MgFYpvyBiT585mbw3SQcJaw75248Bqa+BQaTTBl/CvQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Zn8562HfRzXQN; Tue, 29 Apr 2025 18:30:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53TIUYrO022450; Tue, 29 Apr 2025 18:30:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53TIUYbW022447; Tue, 29 Apr 2025 18:30:34 GMT (envelope-from git) Date: Tue, 29 Apr 2025 18:30:34 GMT Message-Id: <202504291830.53TIUYbW022447@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 14749f40c193 - stable/14 - pci: Cosmetic cleanups to MSI/MSI-X routines List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 14749f40c19341fc6935d619500331fa036a9a54 Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=14749f40c19341fc6935d619500331fa036a9a54 commit 14749f40c19341fc6935d619500331fa036a9a54 Author: John Baldwin AuthorDate: 2025-02-11 14:11:10 +0000 Commit: John Baldwin CommitDate: 2025-04-29 14:24:10 +0000 pci: Cosmetic cleanups to MSI/MSI-X routines - Use unsigned integers for various variables. The count argument to the alloc method as well as the IRQ values used with the pcib_if.m methods should also be unsigned eventually. - Use mallocarray to allocate arrays - Use bool in a few places Reviewed by: Krzysztof Galazka Differential Revision: https://reviews.freebsd.org/D48889 (cherry picked from commit a3835cceb0882494628d5d075f99a86bd3464672) --- sys/dev/pci/pci.c | 63 ++++++++++++++++++++++++++++------------------------ sys/dev/pci/pcivar.h | 4 ++-- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index 8224a6829f3e..07a9534f6b91 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -1775,7 +1775,7 @@ pci_resume_msix(device_t dev) struct pcicfg_msix *msix = &dinfo->cfg.msix; struct msix_table_entry *mte; struct msix_vector *mv; - int i; + u_int i; if (msix->msix_alloc > 0) { /* First, mask all vectors. */ @@ -1808,10 +1808,11 @@ pci_alloc_msix_method(device_t dev, device_t child, int *count) struct pci_devinfo *dinfo = device_get_ivars(child); pcicfgregs *cfg = &dinfo->cfg; struct resource_list_entry *rle; - int actual, error, i, irq, max; + u_int actual, i, max; + int error, irq; /* Don't let count == 0 get us into trouble. */ - if (*count == 0) + if (*count < 1) return (EINVAL); /* If rid 0 is allocated, then fail. */ @@ -1871,7 +1872,7 @@ pci_alloc_msix_method(device_t dev, device_t child, int *count) device_printf(child, "using IRQ %ju for MSI-X\n", rle->start); else { - int run; + bool run; /* * Be fancy and try to print contiguous runs of @@ -1880,14 +1881,14 @@ pci_alloc_msix_method(device_t dev, device_t child, int *count) */ device_printf(child, "using IRQs %ju", rle->start); irq = rle->start; - run = 0; + run = false; for (i = 1; i < actual; i++) { rle = resource_list_find(&dinfo->resources, SYS_RES_IRQ, i + 1); /* Still in a run? */ if (rle->start == irq + 1) { - run = 1; + run = true; irq++; continue; } @@ -1895,7 +1896,7 @@ pci_alloc_msix_method(device_t dev, device_t child, int *count) /* Finish previous range. */ if (run) { printf("-%d", irq); - run = 0; + run = false; } /* Start new range. */ @@ -1915,10 +1916,10 @@ pci_alloc_msix_method(device_t dev, device_t child, int *count) pci_mask_msix(child, i); /* Allocate and initialize vector data and virtual table. */ - cfg->msix.msix_vectors = malloc(sizeof(struct msix_vector) * actual, - M_DEVBUF, M_WAITOK | M_ZERO); - cfg->msix.msix_table = malloc(sizeof(struct msix_table_entry) * actual, + cfg->msix.msix_vectors = mallocarray(actual, sizeof(struct msix_vector), M_DEVBUF, M_WAITOK | M_ZERO); + cfg->msix.msix_table = mallocarray(actual, + sizeof(struct msix_table_entry), M_DEVBUF, M_WAITOK | M_ZERO); for (i = 0; i < actual; i++) { rle = resource_list_find(&dinfo->resources, SYS_RES_IRQ, i + 1); cfg->msix.msix_vectors[i].mv_irq = rle->start; @@ -1983,14 +1984,15 @@ pci_remap_msix_method(device_t dev, device_t child, int count, struct pci_devinfo *dinfo = device_get_ivars(child); struct pcicfg_msix *msix = &dinfo->cfg.msix; struct resource_list_entry *rle; - int i, irq, j, *used; + u_int i, irq, j; + bool *used; /* * Have to have at least one message in the table but the * table can't be bigger than the actual MSI-X table in the * device. */ - if (count == 0 || count > msix->msix_msgnum) + if (count < 1 || count > msix->msix_msgnum) return (EINVAL); /* Sanity check the vectors. */ @@ -2003,17 +2005,17 @@ pci_remap_msix_method(device_t dev, device_t child, int count, * It's a big pain to support it, and it doesn't really make * sense anyway. Also, at least one vector must be used. */ - used = malloc(sizeof(int) * msix->msix_alloc, M_DEVBUF, M_WAITOK | + used = mallocarray(msix->msix_alloc, sizeof(*used), M_DEVBUF, M_WAITOK | M_ZERO); for (i = 0; i < count; i++) if (vectors[i] != 0) - used[vectors[i] - 1] = 1; + used[vectors[i] - 1] = true; for (i = 0; i < msix->msix_alloc - 1; i++) - if (used[i] == 0 && used[i + 1] == 1) { + if (!used[i] && used[i + 1]) { free(used, M_DEVBUF); return (EINVAL); } - if (used[0] != 1) { + if (!used[0]) { free(used, M_DEVBUF); return (EINVAL); } @@ -2046,7 +2048,7 @@ pci_remap_msix_method(device_t dev, device_t child, int count, * used. */ free(msix->msix_table, M_DEVBUF); - msix->msix_table = malloc(sizeof(struct msix_table_entry) * count, + msix->msix_table = mallocarray(count, sizeof(struct msix_table_entry), M_DEVBUF, M_WAITOK | M_ZERO); for (i = 0; i < count; i++) msix->msix_table[i].mte_vector = vectors[i]; @@ -2054,15 +2056,15 @@ pci_remap_msix_method(device_t dev, device_t child, int count, /* Free any unused IRQs and resize the vectors array if necessary. */ j = msix->msix_alloc - 1; - if (used[j] == 0) { + if (!used[j]) { struct msix_vector *vec; - while (used[j] == 0) { + while (!used[j]) { PCIB_RELEASE_MSIX(device_get_parent(dev), child, msix->msix_vectors[j].mv_irq); j--; } - vec = malloc(sizeof(struct msix_vector) * (j + 1), M_DEVBUF, + vec = mallocarray(j + 1, sizeof(struct msix_vector), M_DEVBUF, M_WAITOK); bcopy(msix->msix_vectors, vec, sizeof(struct msix_vector) * (j + 1)); @@ -2104,7 +2106,7 @@ pci_release_msix(device_t dev, device_t child) struct pci_devinfo *dinfo = device_get_ivars(child); struct pcicfg_msix *msix = &dinfo->cfg.msix; struct resource_list_entry *rle; - int i; + u_int i; /* Do we have any messages to release? */ if (msix->msix_alloc == 0) @@ -2425,7 +2427,8 @@ pci_remap_intr_method(device_t bus, device_t dev, u_int irq) struct msix_vector *mv; uint64_t addr; uint32_t data; - int error, i, j; + u_int i, j; + int error; /* * Handle MSI first. We try to find this IRQ among our list @@ -2590,11 +2593,12 @@ pci_alloc_msi_method(device_t dev, device_t child, int *count) struct pci_devinfo *dinfo = device_get_ivars(child); pcicfgregs *cfg = &dinfo->cfg; struct resource_list_entry *rle; - int actual, error, i, irqs[32]; + u_int actual, i; + int error, irqs[32]; uint16_t ctrl; /* Don't let count == 0 get us into trouble. */ - if (*count == 0) + if (*count < 1) return (EINVAL); /* If rid 0 is allocated, then fail. */ @@ -2655,7 +2659,7 @@ pci_alloc_msi_method(device_t dev, device_t child, int *count) if (actual == 1) device_printf(child, "using IRQ %d for MSI\n", irqs[0]); else { - int run; + bool run; /* * Be fancy and try to print contiguous runs @@ -2663,18 +2667,18 @@ pci_alloc_msi_method(device_t dev, device_t child, int *count) * we are in a range. */ device_printf(child, "using IRQs %d", irqs[0]); - run = 0; + run = false; for (i = 1; i < actual; i++) { /* Still in a run? */ if (irqs[i] == irqs[i - 1] + 1) { - run = 1; + run = true; continue; } /* Finish previous range. */ if (run) { printf("-%d", irqs[i - 1]); - run = 0; + run = false; } /* Start new range. */ @@ -2709,7 +2713,8 @@ pci_release_msi_method(device_t dev, device_t child) struct pci_devinfo *dinfo = device_get_ivars(child); struct pcicfg_msi *msi = &dinfo->cfg.msi; struct resource_list_entry *rle; - int error, i, irqs[32]; + u_int i, irqs[32]; + int error; /* Try MSI-X first. */ error = pci_release_msix(dev, child); diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h index c2c1f055def9..37d7daff37f7 100644 --- a/sys/dev/pci/pcivar.h +++ b/sys/dev/pci/pcivar.h @@ -117,8 +117,8 @@ struct pcicfg_msix { uint8_t msix_pba_bar; /* BAR containing PBA. */ uint32_t msix_table_offset; uint32_t msix_pba_offset; - int msix_alloc; /* Number of allocated vectors. */ - int msix_table_len; /* Length of virtual table. */ + u_int msix_alloc; /* Number of allocated vectors. */ + u_int msix_table_len; /* Length of virtual table. */ struct msix_table_entry *msix_table; /* Virtual table. */ struct msix_vector *msix_vectors; /* Array of allocated vectors. */ struct resource *msix_table_res; /* Resource containing vector table. */