All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <matthew@wil.cx>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] Minor fixes to generic do_div
Date: Thu, 19 Oct 2006 21:34:00 -0600	[thread overview]
Message-ID: <20061020033359.GR2602@parisc-linux.org> (raw)


While tracking down a problem recently, I noticed the description of
do_div() is not quite right.  We also don't check that 'n' is 64-bit
when running on a 64-bit machine (this would have caused warnings to
appear on more configurations if we had).  And finally, the indentation
of the \ characters in the 64-bit case don't match those in the 32-bit case,
so change those to match.

Signed-off-by: Matthew Wilcox <matthew@wil.cx>

diff --git a/include/asm-generic/div64.h b/include/asm-generic/div64.h
index 8f4e319..0edfb96 100644
--- a/include/asm-generic/div64.h
+++ b/include/asm-generic/div64.h
@@ -6,10 +6,10 @@ #define _ASM_GENERIC_DIV64_H
  *
  * The semantics of do_div() are:
  *
- * uint32_t do_div(uint64_t *n, uint32_t base)
+ * uint32_t do_div(uint64_t n, uint32_t base)
  * {
- * 	uint32_t remainder = *n % base;
- * 	*n = *n / base;
+ * 	uint32_t remainder = n % base;
+ * 	n = n / base;
  * 	return remainder;
  * }
  *
@@ -22,12 +22,16 @@ #include <linux/compiler.h>
 
 #if BITS_PER_LONG == 64
 
-# define do_div(n,base) ({					\
-	uint32_t __base = (base);				\
-	uint32_t __rem;						\
-	__rem = ((uint64_t)(n)) % __base;			\
-	(n) = ((uint64_t)(n)) / __base;				\
-	__rem;							\
+/* The unnecessary pointer compare is there
+ * to check for type safety (n must be 64bit)
+ */
+# define do_div(n,base) ({				\
+	uint32_t __base = (base);			\
+	uint32_t __rem;					\
+	(void)(((typeof((n)) *)0) == ((uint64_t *)0));	\
+	__rem = ((uint64_t)(n)) % __base;		\
+	(n) = ((uint64_t)(n)) / __base;			\
+	__rem;						\
  })
 
 #elif BITS_PER_LONG == 32

             reply	other threads:[~2006-10-20  3:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-20  3:34 Matthew Wilcox [this message]
2006-10-20  4:59 ` [PATCH] Minor fixes to generic do_div Andrew Morton
2006-10-20  5:36   ` Matthew Wilcox
2006-10-20  5:49     ` Andrew Morton
2006-10-23  7:49 ` Paul Mackerras

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=20061020033359.GR2602@parisc-linux.org \
    --to=matthew@wil.cx \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.