linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roman Zippel <zippel@linux-m68k.org>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Daniel Phillips <phillips@bonn-fries.net>,
	David Lang <david.lang@digitalinsight.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [IDEA+RFC] Possible solution for min()/max() war
Date: Thu, 30 Aug 2001 15:49:40 +0200	[thread overview]
Message-ID: <3B8E4474.DA6D281F@linux-m68k.org> (raw)
In-Reply-To: <Pine.LNX.4.33.0108292018380.1062-100000@penguin.transmeta.com>

[-- Attachment #1: Type: text/plain, Size: 1933 bytes --]

Hi,

> Please guys. The issue of sign in comparisons are a LOT more complicated
> than most of you seem to think.

So why won't you let the compiler help you, even if it's not perfect in
every case?

This is my last attempt to get things IMO right. Most of the arguments
for the new macro were about bugs of the past. No question about this,
this had to be fixed, I'm not arguing about this at all.

I'm trying to get your attention to the bugs of the future. I still
don't understand why you think the new macro will be any better. Why do
you think the average kernel hacker will think about the type of the
compare and will come to the correct conclusion? It's far to easy to use
an int as type argument and forget about it. gcc won't warn about this,
so someone first has to hit this bug, before it gets fixed.

Maybe I'm too dumb, but I still fail to see, what sense it should make
to turn a signed compare into an unsigned one. Either one knows both
signed values are only positive, then the sign of the compare and the
destination doesn't matter at all. If the value could be negative,
better test it explicit:

	if (len < 0 || len > MAX)
		len = MAX;

First, it's far more readable and makes the intention so clear, that
even your average kernel hacker understands it. Second, gcc produces
exactly the same code with this, so there is no need to play type tricks
with the min macro.

Just for fun I enabled -Wsign-compare, enabled most of the drivers and I
got this:

$ grep 'comparison between signed and unsigned' make.log | sort | uniq |
wc -l
   3211

So if you want to get people thinking about the types they are using,
here you have at least 3211 chances.

Please reconsider your decision. IMVHO the new macros are a mistake and
will cause only more trouble than they are worth. If you want to keep
the new macros, please apply the attached patch, as I prefer this
version in the source I'm responsible for.

bye, Roman

[-- Attachment #2: affs.diff --]
[-- Type: text/plain, Size: 4223 bytes --]

Index: include/linux/amigaffs.h
===================================================================
RCS file: /cvsroot/linux-apus/2.3/include/linux/amigaffs.h,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 amigaffs.h
--- include/linux/amigaffs.h	2001/07/22 23:22:24	1.1.1.3
+++ include/linux/amigaffs.h	2001/08/30 13:38:24
@@ -122,7 +122,7 @@
 }
 
 
-#define MIN(a, b) ({		\
+#define affs_min(a, b) ({	\
 	typeof(a) _a = (a);	\
 	typeof(b) _b = (b);	\
 	_a < _b ? _a : _b;	\
Index: fs/affs/amigaffs.c
===================================================================
RCS file: /cvsroot/linux-apus/2.3/fs/affs/amigaffs.c,v
retrieving revision 1.6
diff -u -r1.6 amigaffs.c
--- fs/affs/amigaffs.c	2001/08/20 13:23:07	1.6
+++ fs/affs/amigaffs.c	2001/08/30 13:38:24
@@ -507,7 +507,7 @@
 int
 affs_copy_name(unsigned char *bstr, struct dentry *dentry)
 {
-	int len = MIN(dentry->d_name.len, 30);
+	int len = affs_min(dentry->d_name.len, 30);
 
 	*bstr++ = len;
 	memcpy(bstr, dentry->d_name.name, len);
Index: fs/affs/dir.c
===================================================================
RCS file: /cvsroot/linux-apus/2.3/fs/affs/dir.c,v
retrieving revision 1.1.1.6
diff -u -r1.1.1.6 dir.c
--- fs/affs/dir.c	2001/07/22 23:18:04	1.1.1.6
+++ fs/affs/dir.c	2001/08/30 13:38:24
@@ -135,7 +135,7 @@
 				goto readdir_done;
 			}
 
-			namelen = MIN(AFFS_TAIL(sb, fh_bh)->name[0], 30);
+			namelen = affs_min(AFFS_TAIL(sb, fh_bh)->name[0], 30);
 			name = AFFS_TAIL(sb, fh_bh)->name + 1;
 			pr_debug("AFFS: readdir(): filldir(\"%.*s\", ino=%u), hash=%d, f_pos=%x\n",
 				 namelen, name, ino, hash_pos, f_pos);
Index: fs/affs/file.c
===================================================================
RCS file: /cvsroot/linux-apus/2.3/fs/affs/file.c,v
retrieving revision 1.1.1.8
diff -u -r1.1.1.8 file.c
--- fs/affs/file.c	2001/08/20 23:44:37	1.1.1.8
+++ fs/affs/file.c	2001/08/30 13:38:25
@@ -528,7 +528,7 @@
 		bh = affs_bread_ino(inode, bidx, 0);
 		if (IS_ERR(bh))
 			return PTR_ERR(bh);
-		tmp = MIN(bsize - boff, from - to);
+		tmp = affs_min(bsize - boff, from - to);
 		memcpy(data + from, AFFS_DATA(bh) + boff, tmp);
 		affs_brelse(bh);
 		bidx++;
@@ -558,7 +558,7 @@
 		bh = affs_bread_ino(inode, bidx, 0);
 		if (IS_ERR(bh))
 			return PTR_ERR(bh);
-		tmp = MIN(bsize - boff, newsize - size);
+		tmp = affs_min(bsize - boff, newsize - size);
 		memset(AFFS_DATA(bh) + boff, 0, tmp);
 		AFFS_DATA_HEAD(bh)->size = cpu_to_be32(be32_to_cpu(AFFS_DATA_HEAD(bh)->size) + tmp);
 		affs_fix_checksum(sb, bh);
@@ -576,7 +576,7 @@
 		bh = affs_getzeroblk_ino(inode, bidx);
 		if (IS_ERR(bh))
 			goto out;
-		tmp = MIN(bsize, newsize - size);
+		tmp = affs_min(bsize, newsize - size);
 		AFFS_DATA_HEAD(bh)->ptype = cpu_to_be32(T_DATA);
 		AFFS_DATA_HEAD(bh)->key = cpu_to_be32(inode->i_ino);
 		AFFS_DATA_HEAD(bh)->sequence = cpu_to_be32(bidx);
@@ -685,7 +685,7 @@
 		bh = affs_bread_ino(inode, bidx, 0);
 		if (IS_ERR(bh))
 			return PTR_ERR(bh);
-		tmp = MIN(bsize - boff, to - from);
+		tmp = affs_min(bsize - boff, to - from);
 		memcpy(AFFS_DATA(bh) + boff, data + from, tmp);
 		AFFS_DATA_HEAD(bh)->size = cpu_to_be32(be32_to_cpu(AFFS_DATA_HEAD(bh)->size) + tmp);
 		affs_fix_checksum(sb, bh);
@@ -731,7 +731,7 @@
 		bh = affs_bread_ino(inode, bidx, 1);
 		if (IS_ERR(bh))
 			goto out;
-		tmp = MIN(bsize, to - from);
+		tmp = affs_min(bsize, to - from);
 		memcpy(AFFS_DATA(bh), data + from, tmp);
 		if (bh->b_state & (1UL << BH_New)) {
 			AFFS_DATA_HEAD(bh)->ptype = cpu_to_be32(T_DATA);
Index: fs/affs/namei.c
===================================================================
RCS file: /cvsroot/linux-apus/2.3/fs/affs/namei.c,v
retrieving revision 1.9
diff -u -r1.9 namei.c
--- fs/affs/namei.c	2001/08/21 17:57:27	1.9
+++ fs/affs/namei.c	2001/08/30 13:38:25
@@ -81,7 +81,7 @@
 		return i;
 
 	hash = init_name_hash();
-	i = MIN(qstr->len, 30);
+	i = affs_min(qstr->len, 30);
 	for (; i > 0; name++, i--)
 		hash = partial_name_hash(toupper(*name), hash);
 	qstr->hash = end_name_hash(hash);
@@ -172,7 +172,7 @@
 	toupper_t toupper = affs_get_toupper(sb);
 	int hash;
 
-	hash = len = MIN(len, 30);
+	hash = len = affs_min(len, 30);
 	for (; len > 0; len--)
 		hash = (hash * 13 + toupper(*name++)) & 0x7ff;
 

  parent reply	other threads:[~2001-08-30 13:50 UTC|newest]

Thread overview: 159+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-24 22:42 [IDEA+RFC] Possible solution for min()/max() war Brad Chapman
2001-08-24 23:21 ` Ben LaHaise
2001-08-24 23:58   ` Brad Chapman
2001-08-25  0:13     ` Alexander Viro
2001-08-25  0:25       ` Brad Chapman
2001-08-25  0:34         ` Alexander Viro
2001-08-25  0:53           ` Brad Chapman
2001-08-25  1:15             ` Alexander Viro
2001-08-25 11:21               ` Brad Chapman
2001-08-27  0:02               ` Rusty Russell
2001-08-28  4:59                 ` Linus Torvalds
2001-08-28  5:20                   ` Alexander Viro
2001-08-28  5:51                     ` Linus Torvalds
2001-08-28 11:10                       ` Alan Cox
2001-08-28 14:15                         ` Linus Torvalds
2001-08-28 20:06                         ` John Alvord
2001-08-28 12:42                   ` Roman Zippel
2001-08-28 13:27                     ` Linus Torvalds
2001-08-28 14:19                       ` Roman Zippel
2001-08-28 15:14                         ` Linus Torvalds
2001-08-28 15:44                           ` Henning P. Schmiedehausen
2001-08-28 15:55                             ` Russell King
2001-08-28 16:05                             ` Alan Cox
2001-08-28 16:53                               ` Roman Zippel
2001-08-28 16:39                           ` Roman Zippel
2001-08-28 21:51                             ` Mike Castle
2001-08-29  0:33                           ` Daniel Phillips
2001-08-29  1:13                             ` Linus Torvalds
2001-08-29 15:42                               ` Daniel Phillips
2001-08-29 16:02                                 ` David Lang
2001-08-29 23:49                                   ` Daniel Phillips
2001-08-30  2:05                                     ` Bill Rugolsky Jr.
2001-08-30  3:28                                     ` Linus Torvalds
2001-08-30 13:10                                       ` Ion Badulescu
2001-08-30 13:17                                         ` David Woodhouse
2001-08-30 13:26                                           ` Ion Badulescu
2001-08-30 16:09                                         ` Linus Torvalds
2001-08-30 16:28                                           ` Ion Badulescu
2001-08-31 12:50                                             ` Jamie Lokier
2001-08-31 13:45                                               ` Roman Zippel
2001-08-31 16:27                                                 ` Jamie Lokier
2001-08-30 16:31                                           ` Ben LaHaise
2001-08-30 16:38                                           ` Peter T. Breuer
2001-08-30 19:51                                             ` David Weinehall
2001-08-30 20:16                                               ` Peter T. Breuer
2001-08-30 20:31                                               ` Daniel Phillips
     [not found]                                             ` <mit.lcs.mail.linux-kernel/200108301638.SAA04923@nbd.it.uc3m.es>
2001-08-30 22:42                                               ` Patrick J. LoPresti
2001-08-30 23:27                                                 ` Peter T. Breuer
2001-08-31  0:55                                                   ` Linus Torvalds
2001-08-31  1:28                                                     ` Peter T. Breuer
2001-08-31 13:22                                                     ` Peter T. Breuer
2001-08-31 14:02                                                       ` Linus Torvalds
2001-08-31 15:34                                                         ` Peter T. Breuer
2001-08-31 22:25                                                         ` [PATCH] i386 SA_INTERRUPT logic Jonathan Lundell
2001-08-31 12:01                                                   ` [IDEA+RFC] Possible solution for min()/max() war Roman Zippel
2001-08-31 12:13                                                     ` Peter T. Breuer
2001-08-31 12:58                                                       ` Roman Zippel
2001-08-31 13:29                                                         ` Peter T. Breuer
2001-08-31 14:12                                                           ` Roman Zippel
2001-08-31 14:28                                                             ` Peter T. Breuer
2001-08-31 16:30                                                               ` Roman Zippel
2001-09-07  0:52                                                   ` Bill Pringlemeir
2001-09-07  7:26                                                     ` Peter T. Breuer
2001-09-07 12:28                                                       ` Horst von Brand
2001-09-07 18:03                                                         ` Mark H. Wood
2001-09-07 10:58                                                     ` Peter T. Breuer
2001-09-07 14:39                                                       ` Bill Pringlemeir
2001-09-07 15:17                                                         ` Peter T. Breuer
2001-08-30 13:49                                       ` Roman Zippel [this message]
2001-08-30 16:21                                         ` Linus Torvalds
2001-08-30 16:41                                           ` Christopher Friesen
2001-08-30 16:50                                             ` Linus Torvalds
2001-08-30 17:13                                           ` Roman Zippel
2001-08-31  1:28                                           ` Ion Badulescu
2001-08-31  5:08                                             ` Linus Torvalds
2001-08-31 12:37                                               ` Jamie Lokier
2001-08-31 13:54                                                 ` Linus Torvalds
2001-08-30 17:01                                       ` Daniel Phillips
2001-08-30 17:03                                         ` Peter T. Breuer
2001-08-30 17:26                                           ` Daniel Phillips
2001-08-31  8:04                                           ` Kai Henningsen
2001-08-30 21:16                                         ` Graham Murray
2001-08-30 21:47                                           ` David Weinehall
2001-08-31 10:10                                             ` Helge Hafting
     [not found]                                           ` <mit.lcs.mail.linux-kernel/m266b51c5c.fsf@barnowl.demon.co.uk>
2001-08-30 22:26                                             ` Patrick J. LoPresti
2001-08-28 16:09                         ` Andreas Schwab
2001-08-28 16:47                           ` Roman Zippel
2001-08-28 17:12                             ` Bill Rugolsky Jr.
2001-08-28 17:28                               ` Roman Zippel
2001-08-28 17:29                           ` Richard B. Johnson
2001-08-26 17:59             ` Bill Pringlemeir
2001-08-24 23:59   ` Brad Chapman
2001-08-25  0:07   ` David S. Miller
2001-08-25  0:18     ` Brad Chapman
2001-08-25  0:23     ` David S. Miller
     [not found] <20010825021651.I8296@router.ranmachan.dyndns.org>
2001-08-25  0:21 ` Brad Chapman
     [not found] <20010825024248.J8296@router.ranmachan.dyndns.org>
2001-08-25  0:54 ` Brad Chapman
     [not found] <200108281746.f7SHk1O27199@lists.us.dell.com>
2001-08-28 19:33 ` Brad Chapman
2001-08-28 19:02   ` David Lang
2001-08-28 20:38     ` Brad Chapman
2001-08-28 19:25       ` David Lang
2001-08-28 20:34   ` Andreas Schwab
2001-08-28 20:42     ` Brad Chapman
2001-08-28 21:04       ` Christopher Friesen
2001-08-29  9:03       ` Helge Hafting
2001-08-29  1:33 Ignacio Vazquez-Abrams
     [not found] <200108291905.f7TJ59T11456@wildsau.idv-edu.uni-linz.ac.at>
2001-08-29 19:11 ` Herbert Rosmanith
2001-08-30  9:56 Herbert Rosmanith
2001-08-30 13:09 ` Helge Hafting
2001-08-30 17:32 mike_phillips
2001-08-30 17:45 ` Ion Badulescu
2001-08-30 20:35 Herbert Rosmanith
2001-08-30 20:44 Herbert Rosmanith
2001-08-30 21:06 ` Peter T. Breuer
2001-08-30 21:14   ` David Woodhouse
2001-08-30 21:32     ` Peter T. Breuer
2001-08-30 21:47       ` David Woodhouse
2001-08-30 21:56         ` Peter T. Breuer
2001-08-30 22:13           ` David Woodhouse
2001-08-30 22:47             ` Peter T. Breuer
2001-08-30 23:02               ` David Woodhouse
2001-08-31  0:08           ` Daniel Phillips
2001-08-30 21:49       ` Mark Zealey
2001-08-30 22:06         ` Peter T. Breuer
2001-08-30 22:14           ` Mark Zealey
2001-08-31  7:04   ` Herbert Rosmanith
2001-08-30 21:17 ` Richard B. Johnson
2001-08-30 21:45   ` Thomas Dodd
2001-08-30 21:46   ` Peter T. Breuer
2001-08-30 23:16   ` David Woodhouse
2001-08-30 23:33   ` David Wagner
2001-08-31 11:18   ` Bernd Schmidt
     [not found] <791753058.999219857@[169.254.198.40]>
2001-08-31  0:57 ` Peter T. Breuer
     [not found] <20010830174227.A10673@furble>
2001-08-31  1:19 ` Peter T. Breuer
2001-08-31  2:10   ` Peter T. Breuer
2001-08-31  7:43   ` Jonathan Lundell
2001-08-31  8:27     ` Alex Bligh - linux-kernel
2001-08-31  2:34 Andy Chou
2001-08-31  2:48 Rick Hohensee
2001-08-31 14:28 Martin Knoblauch
2001-08-31 14:28 Herbert Rosmanith
2001-08-31 14:37 ` Herbert Rosmanith
     [not found] <fa.ehba65v.10i6abc@ifi.uio.no>
     [not found] ` <fa.odqvefv.g4k4j6@ifi.uio.no>
2001-08-31 15:45   ` ctm
2001-08-31 16:57     ` Roman Zippel
2001-08-31 17:41 Herbert Rosmanith
2001-08-31 17:57 ` Rik van Riel
2001-08-31 18:13 Herbert Rosmanith
2001-08-31 18:24 Herbert Rosmanith
2001-08-31 18:29 Andy Chou
2001-08-31 18:52 ` Roman Zippel
     [not found] <fa.eeq0k8v.1v28iaa@ifi.uio.no>
2001-08-31 18:40 ` Ted Unangst
2001-09-03 20:35 David desJardins
2001-09-04  8:08 ` VDA
2001-09-03 23:16 David desJardins
2001-09-04  9:09 VDA
2001-09-04 13:17 Petr Vandrovec
2001-09-06  1:51 Rick Hohensee
2001-09-06 10:12 ` VDA
     [not found] <m2bskndlkt.fsf@sympatico.ca>
2001-09-07 17:39 ` Peter T. Breuer

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=3B8E4474.DA6D281F@linux-m68k.org \
    --to=zippel@linux-m68k.org \
    --cc=david.lang@digitalinsight.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phillips@bonn-fries.net \
    --cc=torvalds@transmeta.com \
    /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).