]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[uaccess] Remove redundant user_to_virt()
authorMichael Brown <mcb30@ipxe.org>
Sun, 20 Apr 2025 23:15:52 +0000 (00:15 +0100)
committerMichael Brown <mcb30@ipxe.org>
Sun, 20 Apr 2025 23:15:52 +0000 (00:15 +0100)
The user_to_virt() function is now a straightforward wrapper around
addition, with the addend almost invariably being zero.

Remove this redundant wrapper.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
14 files changed:
src/arch/x86/image/bzimage.c
src/arch/x86/image/initrd.c
src/arch/x86/include/librm.h
src/arch/x86/transitions/librm_mgmt.c
src/core/fdt.c
src/core/uaccess.c
src/image/efi_image.c
src/include/ipxe/linux/linux_uaccess.h
src/include/ipxe/uaccess.h
src/interface/efi/efi_pci.c
src/interface/linux/linux_acpi.c
src/interface/linux/linux_smbios.c
src/interface/linux/linux_sysfs.c
src/interface/linux/linux_uaccess.c

index 29ebeb507ad035023305f2836e9d41465d2660f9..32598525f028e4fdeb40f3b30e478ab066ea1879 100644 (file)
@@ -388,7 +388,7 @@ static size_t bzimage_load_initrd ( struct image *image,
                       user_to_phys ( address, ( offset + initrd->len ) ),
                       ( filename ? " " : "" ), ( filename ? filename : "" ) );
                DBGC2_MD5A ( image, user_to_phys ( address, offset ),
-                            user_to_virt ( address, offset ), initrd->len );
+                            ( address + offset ), initrd->len );
        }
        len += initrd->len;
 
@@ -427,7 +427,7 @@ static int bzimage_check_initrds ( struct image *image,
                       ( initrd->cmdline ? " " : "" ),
                       ( initrd->cmdline ? initrd->cmdline : "" ) );
                DBGC2_MD5A ( image, user_to_phys ( initrd->data, 0 ),
-                            user_to_virt ( initrd->data, 0 ), initrd->len );
+                            initrd->data, initrd->len );
        }
 
        /* Calculate lowest usable address */
index 95f12d804d29c0471e242352127e2bc25a6b138e..bcf95deeffdba2029efab6fa7a8553c84063d573 100644 (file)
@@ -211,7 +211,7 @@ static void initrd_dump ( void ) {
                       initrd->name, user_to_phys ( initrd->data, 0 ),
                       user_to_phys ( initrd->data, initrd->len ) );
                DBGC2_MD5A ( &images, user_to_phys ( initrd->data, 0 ),
-                            user_to_virt ( initrd->data, 0 ), initrd->len );
+                            initrd->data, initrd->len );
        }
 }
 
index c117a8b5c59db9e6db2191df1be53c57bd88b723..9ed91022e9e0ab939a6331d23f3812b9568c5262 100644 (file)
@@ -132,11 +132,6 @@ UACCESS_INLINE ( librm, virt_to_user ) ( volatile const void *addr ) {
        return trivial_virt_to_user ( addr );
 }
 
-static inline __always_inline void *
-UACCESS_INLINE ( librm, user_to_virt ) ( userptr_t userptr, off_t offset ) {
-       return trivial_user_to_virt ( userptr, offset );
-}
-
 static inline __always_inline off_t
 UACCESS_INLINE ( librm, memchr_user ) ( userptr_t buffer, off_t offset,
                                        int c, size_t len ) {
index 7ebf621379004f1047b468193844d58ef3098a7a..82e8eab394e74a2e2589ec141dbf9b96fdf7d94c 100644 (file)
@@ -431,7 +431,6 @@ void setup_sipi ( unsigned int vector, uint32_t handler,
 PROVIDE_UACCESS_INLINE ( librm, phys_to_user );
 PROVIDE_UACCESS_INLINE ( librm, user_to_phys );
 PROVIDE_UACCESS_INLINE ( librm, virt_to_user );
-PROVIDE_UACCESS_INLINE ( librm, user_to_virt );
 PROVIDE_UACCESS_INLINE ( librm, memchr_user );
 PROVIDE_IOMAP_INLINE ( pages, io_to_bus );
 PROVIDE_IOMAP ( pages, ioremap, ioremap_pages );
index 54f93028623c1f474d8f132b63e7f76aa0b1c73a..4c709b34258bde0de5817b20ccf3bd0c7ab78349 100644 (file)
@@ -734,8 +734,7 @@ static int fdt_parse_image ( struct fdt *fdt, struct image *image ) {
        int rc;
 
        /* Parse image */
-       if ( ( rc = fdt_parse ( fdt, user_to_virt ( image->data, 0 ),
-                               image->len ) ) != 0 ) {
+       if ( ( rc = fdt_parse ( fdt, image->data, image->len ) ) != 0 ) {
                DBGC ( fdt, "FDT image \"%s\" is invalid: %s\n",
                       image->name, strerror ( rc ) );
                return rc;
@@ -1038,7 +1037,7 @@ static int fdt_urealloc ( struct fdt *fdt, size_t len ) {
        assert ( len >= fdt->used );
 
        /* Attempt reallocation */
-       new = user_to_virt ( urealloc ( virt_to_user ( fdt->raw ), len ), 0 );
+       new = urealloc ( virt_to_user ( fdt->raw ), len );
        if ( ! new ) {
                DBGC ( fdt, "FDT could not reallocate from +%#04zx to "
                       "+%#04zx\n", fdt->len, len );
@@ -1112,7 +1111,7 @@ int fdt_create ( struct fdt_header **hdr, const char *cmdline ) {
        }
 
        /* Create modifiable copy */
-       copy = user_to_virt ( umalloc ( fdt.len ), 0 );
+       copy = umalloc ( fdt.len );
        if ( ! copy ) {
                rc = -ENOMEM;
                goto err_alloc;
index 01089e6fa42e354f57840f745d1af187dae32a31..1c33c10b8eafe356c0b67a2f4ff94749b2eb1c21 100644 (file)
@@ -35,5 +35,4 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 PROVIDE_UACCESS_INLINE ( flat, phys_to_user );
 PROVIDE_UACCESS_INLINE ( flat, user_to_phys );
 PROVIDE_UACCESS_INLINE ( flat, virt_to_user );
-PROVIDE_UACCESS_INLINE ( flat, user_to_virt );
 PROVIDE_UACCESS_INLINE ( flat, memchr_user );
index c8719648779dc57deecbc1a086baa171228d9ad0..2b0ff567a28889c78e66db8ee75e801d7d2a5a9d 100644 (file)
@@ -245,8 +245,8 @@ static int efi_image_exec ( struct image *image ) {
        /* Attempt loading image */
        handle = NULL;
        if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, path,
-                                      user_to_virt ( exec->data, 0 ),
-                                      exec->len, &handle ) ) != 0 ) {
+                                      exec->data, exec->len,
+                                      &handle ) ) != 0 ) {
                /* Not an EFI image */
                rc = -EEFI_LOAD ( efirc );
                DBGC ( image, "EFIIMAGE %s could not load: %s\n",
@@ -379,8 +379,8 @@ static int efi_image_probe ( struct image *image ) {
        /* Attempt loading image */
        handle = NULL;
        if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, &empty_path,
-                                      user_to_virt ( image->data, 0 ),
-                                      image->len, &handle ) ) != 0 ) {
+                                      image->data, image->len,
+                                      &handle ) ) != 0 ) {
                /* Not an EFI image */
                rc = -EEFI_LOAD ( efirc );
                DBGC ( image, "EFIIMAGE %s could not load: %s\n",
index 0c680c08fe6427c3fa1400d7eeb0a3df8b7cf62c..4b1257b1e31502ed4b241eb4b95b861397a11dfd 100644 (file)
@@ -64,11 +64,6 @@ UACCESS_INLINE ( linux, virt_to_user ) ( volatile const void *addr ) {
        return trivial_virt_to_user ( addr );
 }
 
-static inline __always_inline void *
-UACCESS_INLINE ( linux, user_to_virt ) ( userptr_t userptr, off_t offset ) {
-       return trivial_user_to_virt ( userptr, offset );
-}
-
 static inline __always_inline off_t
 UACCESS_INLINE ( linux, memchr_user ) ( userptr_t buffer, off_t offset,
                                        int c, size_t len ) {
index e84ca3eae998e113b0dfcc29d3211e30410080f6..4b3524babcab9059d5b7a3b8d3813c2f3cd473e3 100644 (file)
@@ -51,20 +51,6 @@ trivial_virt_to_user ( volatile const void *addr ) {
        return ( ( userptr_t ) addr );
 }
 
-/**
- * Convert user pointer to virtual address
- *
- * @v userptr          User pointer
- * @v offset           Offset from user pointer
- * @ret addr           Virtual address
- *
- * This operation is not available under all memory models.
- */
-static inline __always_inline void *
-trivial_user_to_virt ( userptr_t userptr, off_t offset ) {
-       return ( ( void * ) userptr + offset );
-}
-
 /**
  * Find character in user buffer
  *
@@ -128,11 +114,6 @@ UACCESS_INLINE ( flat, virt_to_user ) ( volatile const void *addr ) {
        return trivial_virt_to_user ( addr );
 }
 
-static inline __always_inline void *
-UACCESS_INLINE ( flat, user_to_virt ) ( userptr_t userptr, off_t offset ) {
-       return trivial_user_to_virt ( userptr, offset );
-}
-
 static inline __always_inline off_t
 UACCESS_INLINE ( flat, memchr_user ) ( userptr_t buffer, off_t offset,
                                       int c, size_t len ) {
@@ -170,17 +151,6 @@ unsigned long user_to_phys ( userptr_t userptr, off_t offset );
  */
 userptr_t virt_to_user ( volatile const void *addr );
 
-/**
- * Convert user pointer to virtual address
- *
- * @v userptr          User pointer
- * @v offset           Offset from user pointer
- * @ret addr           Virtual address
- *
- * This operation is not available under all memory models.
- */
-void * user_to_virt ( userptr_t userptr, off_t offset );
-
 /**
  * Convert virtual address to a physical address
  *
@@ -201,7 +171,7 @@ virt_to_phys ( volatile const void *addr ) {
  * This operation is not available under all memory models.
  */
 static inline __always_inline void * phys_to_virt ( unsigned long phys_addr ) {
-       return user_to_virt ( phys_to_user ( phys_addr ), 0 );
+       return ( phys_to_user ( phys_addr ) );
 }
 
 /**
index dd11dd3425a0baf90a4bafe0c25d94214a7b3c07..01351df511198d9e079eba2e04a535896e20fd40 100644 (file)
@@ -669,7 +669,7 @@ static userptr_t efipci_dma_umalloc ( struct dma_device *dma,
 static void efipci_dma_ufree ( struct dma_device *dma, struct dma_mapping *map,
                               userptr_t addr, size_t len ) {
 
-       efipci_dma_free ( dma, map, user_to_virt ( addr, 0 ), len );
+       efipci_dma_free ( dma, map, addr, len );
 }
 
 /**
index e658936f2a447a9c982d33abbe108f0a0c6e1664..846db2f1f68755264cef1022af3b935c59e7ee02 100644 (file)
@@ -101,7 +101,7 @@ static userptr_t linux_acpi_find ( uint32_t signature, unsigned int index ) {
                       filename, strerror ( rc ) );
                goto err_read;
        }
-       header = user_to_virt ( table->data, 0 );
+       header = table->data;
        if ( ( ( ( size_t ) len ) < sizeof ( *header ) ) ||
             ( ( ( size_t ) len ) < le32_to_cpu ( header->length ) ) ) {
                rc = -ENOENT;
index 981873943b93dd74582dc3c0c449ec1793f5935b..abe1b19d709c3ea0b0e75aa61c488564e504d31d 100644 (file)
@@ -59,7 +59,7 @@ static int linux_find_smbios ( struct smbios *smbios ) {
                       smbios_entry_filename, strerror ( rc ) );
                goto err_entry;
        }
-       data = user_to_virt ( entry, 0 );
+       data = entry;
        smbios3_entry = data;
        smbios_entry = data;
        if ( ( len >= ( ( int ) sizeof ( *smbios3_entry ) ) ) &&
index 4f0027cd440278c26df8990cbb05af3d1ede590e..cbb23d81d26413da684428c825f349732f538fc6 100644 (file)
@@ -70,8 +70,7 @@ int linux_sysfs_read ( const char *filename, userptr_t *data ) {
                *data = tmp;
 
                /* Read from file */
-               read = linux_read ( fd, user_to_virt ( *data, len ),
-                                   LINUX_SYSFS_BLKSIZE );
+               read = linux_read ( fd, ( *data + len ), LINUX_SYSFS_BLKSIZE );
                if ( read == 0 )
                        break;
                if ( read < 0 ) {
index d777bf3dd23b125920e1d0fca0e153428e8b214a..e5c3943654a8361202c9a9c75da91933e1ffaa07 100644 (file)
@@ -29,5 +29,4 @@ FILE_LICENCE(GPL2_OR_LATER);
 
 PROVIDE_UACCESS_INLINE(linux, user_to_phys);
 PROVIDE_UACCESS_INLINE(linux, virt_to_user);
-PROVIDE_UACCESS_INLINE(linux, user_to_virt);
 PROVIDE_UACCESS_INLINE(linux, memchr_user);