linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: arnd@arndb.de
Cc: linux-arch@vger.kernel.org
Subject: [PATCH] asm-generic/io.h: terser readsb() and friends
Date: Sun, 22 Nov 2020 14:51:39 +0300	[thread overview]
Message-ID: <20201122115139.GA47348@localhost.localdomain> (raw)

	if (count) {
		do {
			...
		} while (--count);
	}

can be rewritten as

	while (count-- > 0) {
		...
	}

Drop useless variables while I'm at it.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 include/asm-generic/io.h |   68 ++++++++++++++++-------------------------------
 1 file changed, 24 insertions(+), 44 deletions(-)

--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -317,13 +317,10 @@ static inline void writeq_relaxed(u64 value, volatile void __iomem *addr)
 static inline void readsb(const volatile void __iomem *addr, void *buffer,
 			  unsigned int count)
 {
-	if (count) {
-		u8 *buf = buffer;
+	u8 *buf = buffer;
 
-		do {
-			u8 x = __raw_readb(addr);
-			*buf++ = x;
-		} while (--count);
+	while (count-- > 0) {
+		*buf++ = __raw_readb(addr);
 	}
 }
 #endif
@@ -333,13 +330,10 @@ static inline void readsb(const volatile void __iomem *addr, void *buffer,
 static inline void readsw(const volatile void __iomem *addr, void *buffer,
 			  unsigned int count)
 {
-	if (count) {
-		u16 *buf = buffer;
+	u16 *buf = buffer;
 
-		do {
-			u16 x = __raw_readw(addr);
-			*buf++ = x;
-		} while (--count);
+	while (count-- > 0) {
+		*buf++ = __raw_readw(addr);
 	}
 }
 #endif
@@ -349,13 +343,10 @@ static inline void readsw(const volatile void __iomem *addr, void *buffer,
 static inline void readsl(const volatile void __iomem *addr, void *buffer,
 			  unsigned int count)
 {
-	if (count) {
-		u32 *buf = buffer;
+	u32 *buf = buffer;
 
-		do {
-			u32 x = __raw_readl(addr);
-			*buf++ = x;
-		} while (--count);
+	while (count-- > 0) {
+		*buf++ = __raw_readl(addr);
 	}
 }
 #endif
@@ -366,13 +357,10 @@ static inline void readsl(const volatile void __iomem *addr, void *buffer,
 static inline void readsq(const volatile void __iomem *addr, void *buffer,
 			  unsigned int count)
 {
-	if (count) {
-		u64 *buf = buffer;
+	u64 *buf = buffer;
 
-		do {
-			u64 x = __raw_readq(addr);
-			*buf++ = x;
-		} while (--count);
+	while (count-- > 0) {
+		*buf++ = __raw_readq(addr);
 	}
 }
 #endif
@@ -383,12 +371,10 @@ static inline void readsq(const volatile void __iomem *addr, void *buffer,
 static inline void writesb(volatile void __iomem *addr, const void *buffer,
 			   unsigned int count)
 {
-	if (count) {
-		const u8 *buf = buffer;
+	const u8 *buf = buffer;
 
-		do {
-			__raw_writeb(*buf++, addr);
-		} while (--count);
+	while (count-- > 0) {
+		__raw_writeb(*buf++, addr);
 	}
 }
 #endif
@@ -398,12 +384,10 @@ static inline void writesb(volatile void __iomem *addr, const void *buffer,
 static inline void writesw(volatile void __iomem *addr, const void *buffer,
 			   unsigned int count)
 {
-	if (count) {
-		const u16 *buf = buffer;
+	const u16 *buf = buffer;
 
-		do {
-			__raw_writew(*buf++, addr);
-		} while (--count);
+	while (count-- > 0) {
+		__raw_writew(*buf++, addr);
 	}
 }
 #endif
@@ -413,12 +397,10 @@ static inline void writesw(volatile void __iomem *addr, const void *buffer,
 static inline void writesl(volatile void __iomem *addr, const void *buffer,
 			   unsigned int count)
 {
-	if (count) {
-		const u32 *buf = buffer;
+	const u32 *buf = buffer;
 
-		do {
-			__raw_writel(*buf++, addr);
-		} while (--count);
+	while (count-- > 0) {
+		__raw_writel(*buf++, addr);
 	}
 }
 #endif
@@ -429,12 +411,10 @@ static inline void writesl(volatile void __iomem *addr, const void *buffer,
 static inline void writesq(volatile void __iomem *addr, const void *buffer,
 			   unsigned int count)
 {
-	if (count) {
-		const u64 *buf = buffer;
+	const u64 *buf = buffer;
 
-		do {
-			__raw_writeq(*buf++, addr);
-		} while (--count);
+	while (count-- > 0) {
+		__raw_writeq(*buf++, addr);
 	}
 }
 #endif

                 reply	other threads:[~2020-11-22 11:52 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=20201122115139.GA47348@localhost.localdomain \
    --to=adobriyan@gmail.com \
    --cc=arnd@arndb.de \
    --cc=linux-arch@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;
as well as URLs for NNTP newsgroup(s).