aboutsummaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2022-09-22 22:09:19 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2022-09-22 22:09:19 +0000
commitf49fd63a6a130ae464cdc7756e6f7d0d747c82c4 (patch)
tree218a911d9042b8afbfbb1c6643a2109a85dcf290 /sys/dev
parent7ae99f80b6661760c5de3edd330b279f04b092a2 (diff)
downloadsrc-f49fd63a6a130ae464cdc7756e6f7d0d747c82c4.tar.gz
src-f49fd63a6a130ae464cdc7756e6f7d0d747c82c4.zip
kmem_malloc/free: Use void * instead of vm_offset_t for kernel pointers.
Reviewed by: kib, markj Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D36549
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/agp/agp.c8
-rw-r--r--sys/dev/agp/agp_amd.c12
-rw-r--r--sys/dev/agp/agp_ati.c12
-rw-r--r--sys/dev/agp/agp_i810.c4
-rw-r--r--sys/dev/amd_ecc_inject/ecc_inject.c4
-rw-r--r--sys/dev/drm2/drmP.h2
-rw-r--r--sys/dev/drm2/drm_bufs.c4
-rw-r--r--sys/dev/drm2/drm_scatter.c16
-rw-r--r--sys/dev/hyperv/vmbus/hyperv.c5
-rw-r--r--sys/dev/iommu/busdma_iommu.c4
-rw-r--r--sys/dev/kvm_clock/kvm_clock.c2
-rw-r--r--sys/dev/liquidio/lio_network.h4
-rw-r--r--sys/dev/mlx5/mlx5_core/mlx5_fwdump.c21
13 files changed, 46 insertions, 52 deletions
diff --git a/sys/dev/agp/agp.c b/sys/dev/agp/agp.c
index b973b3d7ce3f..f3ffb91cef3e 100644
--- a/sys/dev/agp/agp.c
+++ b/sys/dev/agp/agp.c
@@ -153,9 +153,8 @@ agp_alloc_gatt(device_t dev)
return 0;
gatt->ag_entries = entries;
- gatt->ag_virtual = (void *)kmem_alloc_contig(entries *
- sizeof(u_int32_t), M_NOWAIT | M_ZERO, 0, ~0, PAGE_SIZE, 0,
- VM_MEMATTR_WRITE_COMBINING);
+ gatt->ag_virtual = kmem_alloc_contig(entries * sizeof(uint32_t),
+ M_NOWAIT | M_ZERO, 0, ~0, PAGE_SIZE, 0, VM_MEMATTR_WRITE_COMBINING);
if (!gatt->ag_virtual) {
if (bootverbose)
device_printf(dev, "contiguous allocation failed\n");
@@ -170,8 +169,7 @@ agp_alloc_gatt(device_t dev)
void
agp_free_gatt(struct agp_gatt *gatt)
{
- kmem_free((vm_offset_t)gatt->ag_virtual, gatt->ag_entries *
- sizeof(u_int32_t));
+ kmem_free(gatt->ag_virtual, gatt->ag_entries * sizeof(uint32_t));
free(gatt, M_AGP);
}
diff --git a/sys/dev/agp/agp_amd.c b/sys/dev/agp/agp_amd.c
index b104ec73f7f7..ff5f5475850c 100644
--- a/sys/dev/agp/agp_amd.c
+++ b/sys/dev/agp/agp_amd.c
@@ -101,7 +101,7 @@ agp_amd_alloc_gatt(device_t dev)
* directory.
*/
gatt->ag_entries = entries;
- gatt->ag_virtual = (void *)kmem_alloc_attr(entries * sizeof(u_int32_t),
+ gatt->ag_virtual = kmem_alloc_attr(entries * sizeof(uint32_t),
M_NOWAIT | M_ZERO, 0, ~0, VM_MEMATTR_WRITE_COMBINING);
if (!gatt->ag_virtual) {
if (bootverbose)
@@ -113,14 +113,13 @@ agp_amd_alloc_gatt(device_t dev)
/*
* Allocate the page directory.
*/
- gatt->ag_vdir = (void *)kmem_alloc_attr(AGP_PAGE_SIZE, M_NOWAIT |
+ gatt->ag_vdir = kmem_alloc_attr(AGP_PAGE_SIZE, M_NOWAIT |
M_ZERO, 0, ~0, VM_MEMATTR_WRITE_COMBINING);
if (!gatt->ag_vdir) {
if (bootverbose)
device_printf(dev,
"failed to allocate page directory\n");
- kmem_free((vm_offset_t)gatt->ag_virtual, entries *
- sizeof(u_int32_t));
+ kmem_free(gatt->ag_virtual, entries * sizeof(uint32_t));
free(gatt, M_AGP);
return 0;
}
@@ -168,9 +167,8 @@ agp_amd_alloc_gatt(device_t dev)
static void
agp_amd_free_gatt(struct agp_amd_gatt *gatt)
{
- kmem_free((vm_offset_t)gatt->ag_vdir, AGP_PAGE_SIZE);
- kmem_free((vm_offset_t)gatt->ag_virtual, gatt->ag_entries *
- sizeof(u_int32_t));
+ kmem_free(gatt->ag_vdir, AGP_PAGE_SIZE);
+ kmem_free(gatt->ag_virtual, gatt->ag_entries * sizeof(uint32_t));
free(gatt, M_AGP);
}
diff --git a/sys/dev/agp/agp_ati.c b/sys/dev/agp/agp_ati.c
index 8fc75a604c8c..2eaeb81cc75b 100644
--- a/sys/dev/agp/agp_ati.c
+++ b/sys/dev/agp/agp_ati.c
@@ -132,7 +132,7 @@ agp_ati_alloc_gatt(device_t dev)
/* Alloc the GATT -- pointers to pages of AGP memory */
sc->ag_entries = entries;
- sc->ag_virtual = (void *)kmem_alloc_attr(entries * sizeof(u_int32_t),
+ sc->ag_virtual = kmem_alloc_attr(entries * sizeof(uint32_t),
M_NOWAIT | M_ZERO, 0, ~0, VM_MEMATTR_WRITE_COMBINING);
if (sc->ag_virtual == NULL) {
if (bootverbose)
@@ -141,13 +141,12 @@ agp_ati_alloc_gatt(device_t dev)
}
/* Alloc the page directory -- pointers to each page of the GATT */
- sc->ag_vdir = (void *)kmem_alloc_attr(AGP_PAGE_SIZE, M_NOWAIT | M_ZERO,
+ sc->ag_vdir = kmem_alloc_attr(AGP_PAGE_SIZE, M_NOWAIT | M_ZERO,
0, ~0, VM_MEMATTR_WRITE_COMBINING);
if (sc->ag_vdir == NULL) {
if (bootverbose)
device_printf(dev, "pagedir allocation failed\n");
- kmem_free((vm_offset_t)sc->ag_virtual, entries *
- sizeof(u_int32_t));
+ kmem_free(sc->ag_virtual, entries * sizeof(uint32_t));
return ENOMEM;
}
sc->ag_pdir = vtophys((vm_offset_t)sc->ag_vdir);
@@ -263,9 +262,8 @@ agp_ati_detach(device_t dev)
temp = pci_read_config(dev, apsize_reg, 4);
pci_write_config(dev, apsize_reg, temp & ~1, 4);
- kmem_free((vm_offset_t)sc->ag_vdir, AGP_PAGE_SIZE);
- kmem_free((vm_offset_t)sc->ag_virtual, sc->ag_entries *
- sizeof(u_int32_t));
+ kmem_free(sc->ag_vdir, AGP_PAGE_SIZE);
+ kmem_free(sc->ag_virtual, sc->ag_entries * sizeof(uint32_t));
bus_release_resource(dev, SYS_RES_MEMORY, ATI_GART_MMADDR, sc->regs);
agp_free_res(dev);
diff --git a/sys/dev/agp/agp_i810.c b/sys/dev/agp/agp_i810.c
index 400e70a402c1..8d6b7da86eef 100644
--- a/sys/dev/agp/agp_i810.c
+++ b/sys/dev/agp/agp_i810.c
@@ -1189,7 +1189,7 @@ agp_i810_install_gatt(device_t dev)
sc->dcache_size = 0;
/* According to the specs the gatt on the i810 must be 64k. */
- sc->gatt->ag_virtual = (void *)kmem_alloc_contig(64 * 1024, M_NOWAIT |
+ sc->gatt->ag_virtual = kmem_alloc_contig(64 * 1024, M_NOWAIT |
M_ZERO, 0, ~0, PAGE_SIZE, 0, VM_MEMATTR_WRITE_COMBINING);
if (sc->gatt->ag_virtual == NULL) {
if (bootverbose)
@@ -1329,7 +1329,7 @@ agp_i810_deinstall_gatt(device_t dev)
sc = device_get_softc(dev);
bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, 0);
- kmem_free((vm_offset_t)sc->gatt->ag_virtual, 64 * 1024);
+ kmem_free(sc->gatt->ag_virtual, 64 * 1024);
}
static void
diff --git a/sys/dev/amd_ecc_inject/ecc_inject.c b/sys/dev/amd_ecc_inject/ecc_inject.c
index 657e10407dbc..6e5fb2c3dc43 100644
--- a/sys/dev/amd_ecc_inject/ecc_inject.c
+++ b/sys/dev/amd_ecc_inject/ecc_inject.c
@@ -177,7 +177,7 @@ ecc_ei_inject_one(void *arg, size_t size)
static void
ecc_ei_inject(int count)
{
- vm_offset_t memory;
+ void *memory;
int injected;
KASSERT((quadrant & ~QUADRANT_MASK) == 0,
@@ -191,7 +191,7 @@ ecc_ei_inject(int count)
VM_MEMATTR_UNCACHEABLE);
for (injected = 0; injected < count; injected++) {
- ecc_ei_inject_one((void*)memory, PAGE_SIZE);
+ ecc_ei_inject_one(memory, PAGE_SIZE);
if (delay_ms != 0 && injected != count - 1)
pause_sbt("ecc_ei_inject", delay_ms * SBT_1MS, 0, 0);
}
diff --git a/sys/dev/drm2/drmP.h b/sys/dev/drm2/drmP.h
index ab11ad7f8cc0..f66f190958b5 100644
--- a/sys/dev/drm2/drmP.h
+++ b/sys/dev/drm2/drmP.h
@@ -497,7 +497,7 @@ struct drm_agp_head {
* Scatter-gather memory.
*/
struct drm_sg_mem {
- vm_offset_t vaddr;
+ void *vaddr;
vm_paddr_t *busaddr;
vm_pindex_t pages;
};
diff --git a/sys/dev/drm2/drm_bufs.c b/sys/dev/drm2/drm_bufs.c
index 9648acebea4f..c2eb7fe19258 100644
--- a/sys/dev/drm2/drm_bufs.c
+++ b/sys/dev/drm2/drm_bufs.c
@@ -392,8 +392,8 @@ static int drm_addmap_core(struct drm_device * dev, resource_size_t offset,
free(map, DRM_MEM_MAPS);
return -EINVAL;
}
- map->handle = (void *)(dev->sg->vaddr + offset);
- map->offset += dev->sg->vaddr;
+ map->handle = (char *)dev->sg->vaddr + offset;
+ map->offset += (uintptr_t)dev->sg->vaddr;
break;
case _DRM_CONSISTENT:
/* dma_addr_t is 64bit on i386 with CONFIG_HIGHMEM64G,
diff --git a/sys/dev/drm2/drm_scatter.c b/sys/dev/drm2/drm_scatter.c
index 1ccc88a5f69c..13040ee43b7b 100644
--- a/sys/dev/drm2/drm_scatter.c
+++ b/sys/dev/drm2/drm_scatter.c
@@ -35,7 +35,7 @@ __FBSDID("$FreeBSD$");
#define DEBUG_SCATTER 0
-static inline vm_offset_t drm_vmalloc_dma(vm_size_t size)
+static inline void *drm_vmalloc_dma(vm_size_t size)
{
return kmem_alloc_attr(size, M_NOWAIT | M_ZERO, 0,
BUS_SPACE_MAXADDR_32BIT, VM_MEMATTR_WRITE_COMBINING);
@@ -46,7 +46,7 @@ void drm_sg_cleanup(struct drm_sg_mem * entry)
if (entry == NULL)
return;
- if (entry->vaddr != 0)
+ if (entry->vaddr != NULL)
kmem_free(entry->vaddr, IDX_TO_OFF(entry->pages));
free(entry->busaddr, DRM_MEM_SGLISTS);
@@ -83,7 +83,7 @@ int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request)
}
entry->vaddr = drm_vmalloc_dma(size);
- if (entry->vaddr == 0) {
+ if (entry->vaddr == NULL) {
free(entry->busaddr, DRM_MEM_DRIVER);
free(entry, DRM_MEM_DRIVER);
return -ENOMEM;
@@ -91,14 +91,14 @@ int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request)
for (pindex = 0; pindex < entry->pages; pindex++) {
entry->busaddr[pindex] =
- vtophys(entry->vaddr + IDX_TO_OFF(pindex));
+ vtophys((uintptr_t)entry->vaddr + IDX_TO_OFF(pindex));
}
- request->handle = entry->vaddr;
+ request->handle = (uintptr_t)entry->vaddr;
dev->sg = entry;
- DRM_DEBUG("allocated %ju pages @ 0x%08zx, contents=%08lx\n",
+ DRM_DEBUG("allocated %ju pages @ %p, contents=%08lx\n",
entry->pages, entry->vaddr, *(unsigned long *)entry->vaddr);
return 0;
@@ -125,10 +125,10 @@ int drm_sg_free(struct drm_device *dev, void *data,
entry = dev->sg;
dev->sg = NULL;
- if (!entry || entry->vaddr != request->handle)
+ if (!entry || (uintptr_t)entry->vaddr != request->handle)
return -EINVAL;
- DRM_DEBUG("free 0x%zx\n", entry->vaddr);
+ DRM_DEBUG("free %p\n", entry->vaddr);
drm_sg_cleanup(entry);
diff --git a/sys/dev/hyperv/vmbus/hyperv.c b/sys/dev/hyperv/vmbus/hyperv.c
index 01e0ad9610d9..b2a74036f6c3 100644
--- a/sys/dev/hyperv/vmbus/hyperv.c
+++ b/sys/dev/hyperv/vmbus/hyperv.c
@@ -268,7 +268,7 @@ SYSINIT(hyperv_initialize, SI_SUB_HYPERVISOR, SI_ORDER_FIRST, hyperv_init,
static void
hypercall_memfree(void)
{
- kmem_free((vm_offset_t)hypercall_context.hc_addr, PAGE_SIZE);
+ kmem_free(hypercall_context.hc_addr, PAGE_SIZE);
hypercall_context.hc_addr = NULL;
}
@@ -286,8 +286,7 @@ hypercall_create(void *arg __unused)
* the NX bit.
* - Assume kmem_malloc() returns properly aligned memory.
*/
- hypercall_context.hc_addr = (void *)kmem_malloc(PAGE_SIZE, M_EXEC |
- M_WAITOK);
+ hypercall_context.hc_addr = kmem_malloc(PAGE_SIZE, M_EXEC | M_WAITOK);
hypercall_context.hc_paddr = vtophys(hypercall_context.hc_addr);
/* Get the 'reserved' bits, which requires preservation. */
diff --git a/sys/dev/iommu/busdma_iommu.c b/sys/dev/iommu/busdma_iommu.c
index 8f63d8b47f19..fac23b730162 100644
--- a/sys/dev/iommu/busdma_iommu.c
+++ b/sys/dev/iommu/busdma_iommu.c
@@ -519,7 +519,7 @@ iommu_bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
DOMAINSET_PREF(tag->common.domain), mflags);
map->flags |= BUS_DMAMAP_IOMMU_MALLOC;
} else {
- *vaddr = (void *)kmem_alloc_attr_domainset(
+ *vaddr = kmem_alloc_attr_domainset(
DOMAINSET_PREF(tag->common.domain), tag->common.maxsize,
mflags, 0ul, BUS_SPACE_MAXADDR, attr);
map->flags |= BUS_DMAMAP_IOMMU_KMEM_ALLOC;
@@ -547,7 +547,7 @@ iommu_bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map1)
} else {
KASSERT((map->flags & BUS_DMAMAP_IOMMU_KMEM_ALLOC) != 0,
("iommu_bus_dmamem_free for non alloced map %p", map));
- kmem_free((vm_offset_t)vaddr, tag->common.maxsize);
+ kmem_free(vaddr, tag->common.maxsize);
map->flags &= ~BUS_DMAMAP_IOMMU_KMEM_ALLOC;
}
diff --git a/sys/dev/kvm_clock/kvm_clock.c b/sys/dev/kvm_clock/kvm_clock.c
index e6b991ba0f77..81c617755385 100644
--- a/sys/dev/kvm_clock/kvm_clock.c
+++ b/sys/dev/kvm_clock/kvm_clock.c
@@ -148,7 +148,7 @@ kvm_clock_attach(device_t dev)
(regs[0] & KVM_FEATURE_CLOCKSOURCE_STABLE_BIT) != 0;
/* Set up 'struct pvclock_vcpu_time_info' page(s): */
- sc->timeinfos = (struct pvclock_vcpu_time_info *)kmem_malloc(mp_ncpus *
+ sc->timeinfos = kmem_malloc(mp_ncpus *
sizeof(struct pvclock_vcpu_time_info), M_WAITOK | M_ZERO);
kvm_clock_system_time_enable(sc);
diff --git a/sys/dev/liquidio/lio_network.h b/sys/dev/liquidio/lio_network.h
index b1f4e1448fe9..5a843e4cf8ae 100644
--- a/sys/dev/liquidio/lio_network.h
+++ b/sys/dev/liquidio/lio_network.h
@@ -198,7 +198,7 @@ lio_dma_alloc(size_t size, vm_paddr_t *dma_handle)
void *mem;
align = PAGE_SIZE << lio_get_order(size);
- mem = (void *)kmem_alloc_contig(size, M_WAITOK, 0, ~0ul, align, 0,
+ mem = kmem_alloc_contig(size, M_WAITOK, 0, ~0ul, align, 0,
VM_MEMATTR_DEFAULT);
if (mem != NULL)
*dma_handle = vtophys(mem);
@@ -212,7 +212,7 @@ static inline void
lio_dma_free(size_t size, void *cpu_addr)
{
- kmem_free((vm_offset_t)cpu_addr, size);
+ kmem_free(cpu_addr, size);
}
static inline uint64_t
diff --git a/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c b/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c
index 315583601831..a272c759ea80 100644
--- a/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c
+++ b/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c
@@ -410,6 +410,7 @@ mlx5_ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
struct mlx5_fw_update *fu;
struct firmware fake_fw;
struct mlx5_eeprom_get *eeprom_info;
+ void *fw_data;
int error;
error = 0;
@@ -461,21 +462,21 @@ mlx5_ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
error = mlx5_dbsf_to_core(devaddr, &mdev);
if (error != 0)
break;
- bzero(&fake_fw, sizeof(fake_fw));
- fake_fw.name = "umlx_fw_up";
- fake_fw.datasize = fu->img_fw_data_len;
- fake_fw.version = 1;
- fake_fw.data = (void *)kmem_malloc(fu->img_fw_data_len,
- M_WAITOK);
+ fw_data = kmem_malloc(fu->img_fw_data_len, M_WAITOK);
if (fake_fw.data == NULL) {
error = ENOMEM;
break;
}
- error = copyin(fu->img_fw_data, __DECONST(void *, fake_fw.data),
- fu->img_fw_data_len);
- if (error == 0)
+ error = copyin(fu->img_fw_data, fw_data, fu->img_fw_data_len);
+ if (error == 0) {
+ bzero(&fake_fw, sizeof(fake_fw));
+ fake_fw.name = "umlx_fw_up";
+ fake_fw.datasize = fu->img_fw_data_len;
+ fake_fw.version = 1;
+ fake_fw.data = fw_data;
error = -mlx5_firmware_flash(mdev, &fake_fw);
- kmem_free((vm_offset_t)fake_fw.data, fu->img_fw_data_len);
+ }
+ kmem_free(fw_data, fu->img_fw_data_len);
break;
case MLX5_FW_RESET:
if ((fflag & FWRITE) == 0) {