[PATCH] arch/alpha: optimize virt_to_phys with compiler automatic sign extension

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In the `virt_to_phys` function, the following changes have been made:
1. **Automatic Sign Extension**:
   - The manual sign extension code has been replaced with the
     compiler's automatic sign extension.
   - This simplifies the code and leverages the
     compiler's optimization.

2. **Fix for 64-bit Address Overflow**:
   - Previously, when the input was a 64-bit address with a
     negative high bit (sign bit), the sign extension caused an
     overflow, resulting in an incorrect conversion to 0.
   - This issue has been addressed by using the compiler's
     automatic sign extension,
     which ensures proper handling of negative addresses.

3. **NULL Pointer Check**:
   - A NULL pointer check has been added at the
     beginning of the function.
   - If the address is NULL, the function now
     returns 0 to prevent potential crashes.

Signed-off-by: stephen.eta.zhou <stephen.eta.zhou@xxxxxxxxxxx>
---
 arch/alpha/include/asm/io.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/alpha/include/asm/io.h b/arch/alpha/include/asm/io.h
index 65fe1e54c6da..4d7cd7486b7d 100644
--- a/arch/alpha/include/asm/io.h
+++ b/arch/alpha/include/asm/io.h
@@ -70,9 +70,11 @@ static inline unsigned long virt_to_phys(volatile void *address)
 {
         unsigned long phys = (unsigned long)address;
 
-	/* Sign-extend from bit 41.  */
-	phys <<= (64 - 41);
-	phys = (long)phys >> (64 - 41);
+	if (!address)
+		return 0;
+
+	/* Automatic Sign-extend  */
+	phys = (long)phys;
 
 	/* Crop to the physical address width of the processor.  */
         phys &= (1ul << hwrpb->pa_bits) - 1;
-- 
2.25.1






[Index of Archives]     [Netdev]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux