]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[uaccess] Remove redundant userptr_add() and userptr_diff()
authorMichael Brown <mcb30@ipxe.org>
Sun, 20 Apr 2025 17:45:55 +0000 (18:45 +0100)
committerMichael Brown <mcb30@ipxe.org>
Sun, 20 Apr 2025 21:31:29 +0000 (22:31 +0100)
The userptr_add() and userptr_diff() functions are now just
straightforward wrappers around addition and subtraction.

Remove these redundant wrappers.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
13 files changed:
src/arch/x86/image/bzimage.c
src/arch/x86/image/initrd.c
src/arch/x86/image/nbi.c
src/arch/x86/include/librm.h
src/arch/x86/interface/pcbios/memtop_umalloc.c
src/arch/x86/transitions/librm_mgmt.c
src/core/sanboot.c
src/core/uaccess.c
src/drivers/net/gve.c
src/image/gzip.c
src/include/ipxe/linux/linux_uaccess.h
src/include/ipxe/uaccess.h
src/interface/linux/linux_uaccess.c

index b4a78cdfced0ed0f411b6f21d19887ac987c9506..d00b9f155dfbf274ad025afa95f7f84e7db96fb7 100644 (file)
@@ -431,7 +431,7 @@ static int bzimage_check_initrds ( struct image *image,
        }
 
        /* Calculate lowest usable address */
-       bottom = userptr_add ( bzimg->pm_kernel, bzimg->pm_sz );
+       bottom = ( bzimg->pm_kernel + bzimg->pm_sz );
 
        /* Check that total length fits within space available for
         * reshuffling.  This is a conservative check, since CPIO
@@ -471,14 +471,12 @@ static void bzimage_load_initrds ( struct image *image,
        size_t len;
 
        /* Reshuffle initrds into desired order */
-       initrd_reshuffle ( userptr_add ( bzimg->pm_kernel, bzimg->pm_sz ) );
+       initrd_reshuffle ( bzimg->pm_kernel + bzimg->pm_sz );
 
        /* Find highest initrd */
        for_each_image ( initrd ) {
-               if ( ( highest == NULL ) ||
-                    ( userptr_diff ( initrd->data, highest->data ) > 0 ) ) {
+               if ( ( highest == NULL ) || ( initrd->data > highest->data ) )
                        highest = initrd;
-               }
        }
 
        /* Do nothing if there are no initrds */
@@ -486,7 +484,7 @@ static void bzimage_load_initrds ( struct image *image,
                return;
 
        /* Find highest usable address */
-       top = userptr_add ( highest->data, bzimage_align ( highest->len ) );
+       top = ( highest->data + bzimage_align ( highest->len ) );
        if ( user_to_phys ( top, -1 ) > bzimg->mem_limit ) {
                top = phys_to_user ( ( bzimg->mem_limit + 1 ) &
                                     ~( INITRD_ALIGN - 1 ) );
@@ -509,7 +507,7 @@ static void bzimage_load_initrds ( struct image *image,
                }
 
                /* Load initrd at this address */
-               dest = userptr_add ( top, -offset );
+               dest = ( top - offset );
                len = bzimage_load_initrd ( image, initrd, dest );
 
                /* Record initrd location */
index c0a56b7f6a2c1bb04614ea00efd18ed595ed090d..e32e403412042145296fd348de375be1b8b279df 100644 (file)
@@ -61,10 +61,9 @@ static userptr_t initrd_squash_high ( userptr_t top ) {
                /* Find the highest image not yet in its final position */
                highest = NULL;
                for_each_image ( initrd ) {
-                       if ( ( userptr_diff ( initrd->data, current ) < 0 ) &&
+                       if ( ( initrd->data < current ) &&
                             ( ( highest == NULL ) ||
-                              ( userptr_diff ( initrd->data,
-                                               highest->data ) > 0 ) ) ) {
+                              ( initrd->data > highest->data ) ) ) {
                                highest = initrd;
                        }
                }
@@ -74,7 +73,7 @@ static userptr_t initrd_squash_high ( userptr_t top ) {
                /* Move this image to its final position */
                len = ( ( highest->len + INITRD_ALIGN - 1 ) &
                        ~( INITRD_ALIGN - 1 ) );
-               current = userptr_add ( current, -len );
+               current -= len;
                DBGC ( &images, "INITRD squashing %s [%#08lx,%#08lx)->"
                       "[%#08lx,%#08lx)\n", highest->name,
                       user_to_phys ( highest->data, 0 ),
@@ -87,10 +86,10 @@ static userptr_t initrd_squash_high ( userptr_t top ) {
 
        /* Copy any remaining initrds (e.g. embedded images) to the region */
        for_each_image ( initrd ) {
-               if ( userptr_diff ( initrd->data, top ) >= 0 ) {
+               if ( initrd->data >= top ) {
                        len = ( ( initrd->len + INITRD_ALIGN - 1 ) &
                                ~( INITRD_ALIGN - 1 ) );
-                       current = userptr_add ( current, -len );
+                       current -= len;
                        DBGC ( &images, "INITRD copying %s [%#08lx,%#08lx)->"
                               "[%#08lx,%#08lx)\n", initrd->name,
                               user_to_phys ( initrd->data, 0 ),
@@ -149,7 +148,7 @@ static void initrd_swap ( struct image *low, struct image *high,
 
        /* Adjust data pointers */
        high->data = low->data;
-       low->data = userptr_add ( low->data, len );
+       low->data += len;
 }
 
 /**
@@ -171,7 +170,7 @@ static int initrd_swap_any ( userptr_t free, size_t free_len ) {
                /* Calculate location of adjacent image (if any) */
                padded_len = ( ( low->len + INITRD_ALIGN - 1 ) &
                               ~( INITRD_ALIGN - 1 ) );
-               adjacent = userptr_add ( low->data, padded_len );
+               adjacent = ( low->data + padded_len );
 
                /* Search for adjacent image */
                for_each_image ( high ) {
@@ -235,7 +234,7 @@ void initrd_reshuffle ( userptr_t bottom ) {
 
        /* Calculate limits of available space for initrds */
        top = initrd_top;
-       if ( userptr_diff ( initrd_bottom, bottom ) > 0 )
+       if ( initrd_bottom > bottom )
                bottom = initrd_bottom;
 
        /* Debug */
@@ -248,7 +247,7 @@ void initrd_reshuffle ( userptr_t bottom ) {
 
        /* Calculate available free space */
        free = bottom;
-       free_len = userptr_diff ( used, free );
+       free_len = ( used - free );
 
        /* Bubble-sort initrds into desired order */
        while ( initrd_swap_any ( free, free_len ) ) {}
@@ -270,9 +269,9 @@ int initrd_reshuffle_check ( size_t len, userptr_t bottom ) {
 
        /* Calculate limits of available space for initrds */
        top = initrd_top;
-       if ( userptr_diff ( initrd_bottom, bottom ) > 0 )
+       if ( initrd_bottom > bottom )
                bottom = initrd_bottom;
-       available = userptr_diff ( top, bottom );
+       available = ( top - bottom );
 
        /* Allow for a sensible minimum amount of free space */
        len += INITRD_MIN_FREE_LEN;
@@ -296,7 +295,7 @@ static void initrd_startup ( void ) {
         * can safely reuse when rearranging).
         */
        len = largest_memblock ( &initrd_bottom );
-       initrd_top = userptr_add ( initrd_bottom, len );
+       initrd_top = ( initrd_bottom + len );
 }
 
 /** initrd startup function */
index b691bee20ea9eb34d392ce8ee46de671113888c6..2f0d3164ad81d4fb97b164325b761375dd18e931 100644 (file)
@@ -184,10 +184,10 @@ static int nbi_process_segments ( struct image *image,
                        dest = phys_to_user ( sh.loadaddr );
                        break;
                case NBI_LOADADDR_AFTER:
-                       dest = userptr_add ( dest, memsz + sh.loadaddr );
+                       dest = ( dest + memsz + sh.loadaddr );
                        break;
                case NBI_LOADADDR_BEFORE:
-                       dest = userptr_add ( dest, -sh.loadaddr );
+                       dest = ( dest - sh.loadaddr );
                        break;
                case NBI_LOADADDR_END:
                        /* Not correct according to the spec, but
index 23ca4650ff9356ea7b7e663349beab3f239fde3d..c0d910287f1b6502a9b4966de51c4d07597ae823 100644 (file)
@@ -137,17 +137,6 @@ UACCESS_INLINE ( librm, user_to_virt ) ( userptr_t userptr, off_t offset ) {
        return trivial_user_to_virt ( userptr, offset );
 }
 
-static inline __always_inline userptr_t
-UACCESS_INLINE ( librm, userptr_add ) ( userptr_t userptr, off_t offset ) {
-       return trivial_userptr_add ( userptr, offset );
-}
-
-static inline __always_inline off_t
-UACCESS_INLINE ( librm, userptr_diff ) ( userptr_t userptr,
-                                        userptr_t subtrahend ) {
-       return trivial_userptr_diff ( userptr, subtrahend );
-}
-
 static inline __always_inline void
 UACCESS_INLINE ( librm, memcpy_user ) ( userptr_t dest, off_t dest_off,
                                        userptr_t src, off_t src_off,
index 1cc3aff915ef48e1e062d472efd7e9ff0f013474..e76b3df93f4a7124b4dc20bf456f3abcfa05e1f9 100644 (file)
@@ -122,7 +122,7 @@ static void init_eheap ( void ) {
        userptr_t base;
 
        heap_size = largest_memblock ( &base );
-       bottom = top = userptr_add ( base, heap_size );
+       bottom = top = ( base + heap_size );
        DBG ( "External heap grows downwards from %lx (size %zx)\n",
              user_to_phys ( top, 0 ), heap_size );
 }
@@ -144,7 +144,7 @@ static void ecollect_free ( void ) {
                DBG ( "EXTMEM freeing [%lx,%lx)\n", user_to_phys ( bottom, 0 ),
                      user_to_phys ( bottom, extmem.size ) );
                len = ( extmem.size + sizeof ( extmem ) );
-               bottom = userptr_add ( bottom, len );
+               bottom += len;
                heap_size += len;
        }
 }
@@ -179,7 +179,7 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) {
                        DBG ( "EXTMEM out of space\n" );
                        return UNULL;
                }
-               ptr = bottom = userptr_add ( bottom, -sizeof ( extmem ) );
+               ptr = bottom = ( bottom - sizeof ( extmem ) );
                heap_size -= sizeof ( extmem );
                DBG ( "EXTMEM allocating [%lx,%lx)\n",
                      user_to_phys ( ptr, 0 ), user_to_phys ( ptr, 0 ) );
@@ -190,10 +190,10 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) {
        /* Expand/shrink block if possible */
        if ( ptr == bottom ) {
                /* Update block */
-               new = userptr_add ( ptr, - ( new_size - extmem.size ) );
+               new = ( ptr - ( new_size - extmem.size ) );
                align = ( user_to_phys ( new, 0 ) & ( EM_ALIGN - 1 ) );
                new_size += align;
-               new = userptr_add ( new, -align );
+               new -= align;
                if ( new_size > ( heap_size + extmem.size ) ) {
                        DBG ( "EXTMEM out of space\n" );
                        return UNULL;
index b3820589c4137d7e41bc087100994451b57154b4..ec31fceb19fb4ae00c8db5bd1905879491943809 100644 (file)
@@ -432,7 +432,6 @@ 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, userptr_add );
 PROVIDE_UACCESS_INLINE ( librm, memcpy_user );
 PROVIDE_UACCESS_INLINE ( librm, memmove_user );
 PROVIDE_UACCESS_INLINE ( librm, memset_user );
index e49a3f92df4cca25abe91ccbbdb60484bfbaf0d9..4facf86b892e1793115e64fe460cc2fe5fe77aa0 100644 (file)
@@ -625,7 +625,7 @@ static int sandev_rw ( struct san_device *sandev, uint64_t lba,
 
                /* Move to next fragment */
                frag_len = ( sandev->capacity.blksize * params.rw.count );
-               params.rw.buffer = userptr_add ( params.rw.buffer, frag_len );
+               params.rw.buffer += frag_len;
                params.rw.lba += params.rw.count;
                remaining -= params.rw.count;
        }
index d3a9ca17d64ccd76ee070f1969b5d17b8d8a460a..ad17a58ab12c03f3ccc315d687e6774ad953ef87 100644 (file)
@@ -36,7 +36,6 @@ 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, userptr_add );
 PROVIDE_UACCESS_INLINE ( flat, memcpy_user );
 PROVIDE_UACCESS_INLINE ( flat, memmove_user );
 PROVIDE_UACCESS_INLINE ( flat, memset_user );
index efc38dd21daf67cd6f9b3f1d76a8e7b397ec69cb..805feee3dcf7064071ae78d6498b78a0a241afdf 100644 (file)
@@ -807,7 +807,7 @@ static inline __attribute__ (( always_inline )) userptr_t
 gve_buffer ( struct gve_queue *queue, unsigned int index ) {
 
        /* Pages are currently allocated as a single contiguous block */
-       return userptr_add ( queue->qpl.data, gve_address ( queue, index ) );
+       return ( queue->qpl.data + gve_address ( queue, index ) );
 }
 
 /**
index 98376e1133b41dc82e02ce256c49e765c47de808..116d912d795d7f6416d03b3302d0608623d2c2f1 100644 (file)
@@ -111,7 +111,7 @@ static int gzip_extract ( struct image *image, struct image *extracted ) {
        }
 
        /* Initialise input chunk */
-       deflate_chunk_init ( &in, userptr_add ( image->data, offset ), 0, len );
+       deflate_chunk_init ( &in, ( image->data + offset ), 0, len );
 
        /* Presize extracted image */
        if ( ( rc = image_set_len ( extracted,
index 1e31afd9ce93bfa7e703a13e81862bafa18ed243..790c75123fb980cfc3dc7e1ff8524938786c94cf 100644 (file)
@@ -69,17 +69,6 @@ UACCESS_INLINE ( linux, user_to_virt ) ( userptr_t userptr, off_t offset ) {
        return trivial_user_to_virt ( userptr, offset );
 }
 
-static inline __always_inline userptr_t
-UACCESS_INLINE ( linux, userptr_add ) ( userptr_t userptr, off_t offset ) {
-       return trivial_userptr_add ( userptr, offset );
-}
-
-static inline __always_inline off_t
-UACCESS_INLINE ( linux, userptr_diff ) ( userptr_t userptr,
-                                        userptr_t subtrahend ) {
-       return trivial_userptr_diff ( userptr, subtrahend );
-}
-
 static inline __always_inline void
 UACCESS_INLINE ( linux, memcpy_user ) ( userptr_t dest, off_t dest_off,
                                        userptr_t src, off_t src_off,
index 1790e4066d64720f78a6b7ab67fe946364d1c287..93dc60d626cfee2a629acc861dd276472300c53c 100644 (file)
@@ -65,30 +65,6 @@ trivial_user_to_virt ( userptr_t userptr, off_t offset ) {
        return ( ( void * ) userptr + offset );
 }
 
-/**
- * Add offset to user pointer
- *
- * @v userptr          User pointer
- * @v offset           Offset
- * @ret userptr                New pointer value
- */
-static inline __always_inline userptr_t
-trivial_userptr_add ( userptr_t userptr, off_t offset ) {
-       return ( userptr + offset );
-}
-
-/**
- * Subtract user pointers
- *
- * @v userptr          User pointer
- * @v subtrahend       User pointer to be subtracted
- * @ret offset         Offset
- */
-static inline __always_inline off_t
-trivial_userptr_diff ( userptr_t userptr, userptr_t subtrahend ) {
-       return ( userptr - subtrahend );
-}
-
 /**
  * Copy data between user buffers
  *
@@ -231,17 +207,6 @@ UACCESS_INLINE ( flat, user_to_virt ) ( userptr_t userptr, off_t offset ) {
        return trivial_user_to_virt ( userptr, offset );
 }
 
-static inline __always_inline userptr_t
-UACCESS_INLINE ( flat, userptr_add ) ( userptr_t userptr, off_t offset ) {
-       return trivial_userptr_add ( userptr, offset );
-}
-
-static inline __always_inline off_t
-UACCESS_INLINE ( flat, userptr_diff ) ( userptr_t userptr,
-                                       userptr_t subtrahend ) {
-       return trivial_userptr_diff ( userptr, subtrahend );
-}
-
 static inline __always_inline void
 UACCESS_INLINE ( flat, memcpy_user ) ( userptr_t dest, off_t dest_off,
                                       userptr_t src, off_t src_off,
@@ -322,24 +287,6 @@ userptr_t virt_to_user ( volatile const void *addr );
  */
 void * user_to_virt ( userptr_t userptr, off_t offset );
 
-/**
- * Add offset to user pointer
- *
- * @v userptr          User pointer
- * @v offset           Offset
- * @ret userptr                New pointer value
- */
-userptr_t userptr_add ( userptr_t userptr, off_t offset );
-
-/**
- * Subtract user pointers
- *
- * @v userptr          User pointer
- * @v subtrahend       User pointer to be subtracted
- * @ret offset         Offset
- */
-off_t userptr_diff ( userptr_t userptr, userptr_t subtrahend );
-
 /**
  * Convert virtual address to a physical address
  *
index ea2d8057ce55a2e2d940417a8ce7dea517fe98dc..9fc99c5e2bf78fc6f6b8d3e586f62d4d3580b781 100644 (file)
@@ -30,7 +30,6 @@ 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, userptr_add);
 PROVIDE_UACCESS_INLINE(linux, memcpy_user);
 PROVIDE_UACCESS_INLINE(linux, memmove_user);
 PROVIDE_UACCESS_INLINE(linux, memset_user);