mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julian Vetter <julian@outer-limits.org>
To: Arnd Bergmann <arnd@arndb.de>
Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
	Julian Vetter <julian@outer-limits.org>
Subject: [PATCH] asm-generic: allow unaligned buffers in reads/writes{w,l,q}
Date: Mon,  3 Feb 2025 14:03:23 +0100	[thread overview]
Message-ID: <20250203130323.8172-1-julian@outer-limits.org> (raw)

Access buffers in reads/writes{w,l,q} via get_unaligned and
put_unaligned, to protect from potential unaligned traps.

Signed-off-by: Julian Vetter <julian@outer-limits.org>
---
 include/asm-generic/io.h | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
index a5cbbf3e26ec..920fecd512fc 100644
--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -12,6 +12,7 @@
 #include <linux/sizes.h>
 #include <linux/types.h>
 #include <linux/instruction_pointer.h>
+#include <linux/unaligned.h>
 
 #ifdef CONFIG_GENERIC_IOMAP
 #include <asm-generic/iomap.h>
@@ -422,7 +423,8 @@ static inline void readsw(const volatile void __iomem *addr, void *buffer,
 
 		do {
 			u16 x = __raw_readw(addr);
-			*buf++ = x;
+			put_unaligned(x, buf);
+			buf++;
 		} while (--count);
 	}
 }
@@ -438,7 +440,8 @@ static inline void readsl(const volatile void __iomem *addr, void *buffer,
 
 		do {
 			u32 x = __raw_readl(addr);
-			*buf++ = x;
+			put_unaligned(x, buf);
+			buf++;
 		} while (--count);
 	}
 }
@@ -455,7 +458,8 @@ static inline void readsq(const volatile void __iomem *addr, void *buffer,
 
 		do {
 			u64 x = __raw_readq(addr);
-			*buf++ = x;
+			put_unaligned(x, buf);
+			buf++;
 		} while (--count);
 	}
 }
@@ -486,7 +490,9 @@ static inline void writesw(volatile void __iomem *addr, const void *buffer,
 		const u16 *buf = buffer;
 
 		do {
-			__raw_writew(*buf++, addr);
+			u16 val = get_unaligned(buf);
+			__raw_writew(val, addr);
+			buf++;
 		} while (--count);
 	}
 }
@@ -501,7 +507,9 @@ static inline void writesl(volatile void __iomem *addr, const void *buffer,
 		const u32 *buf = buffer;
 
 		do {
-			__raw_writel(*buf++, addr);
+			u32 val = get_unaligned(buf);
+			__raw_writel(val, addr);
+			buf++;
 		} while (--count);
 	}
 }
@@ -517,7 +525,9 @@ static inline void writesq(volatile void __iomem *addr, const void *buffer,
 		const u64 *buf = buffer;
 
 		do {
-			__raw_writeq(*buf++, addr);
+			u64 val = get_unaligned(buf);
+			__raw_writeq(val, addr);
+			buf++;
 		} while (--count);
 	}
 }
-- 
2.34.1


                 reply	other threads:[~2025-02-03 13:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250203130323.8172-1-julian@outer-limits.org \
    --to=julian@outer-limits.org \
    --cc=arnd@arndb.de \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®