Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Aug 2017 16:54:55 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Hans Petter Selasky <hps@selasky.org>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r321920 - head/sys/sys
Message-ID:  <20170802135455.GG1700@kib.kiev.ua>
In-Reply-To: <37abc595-c80e-a8da-04a8-815f42c634de@selasky.org>
References:  <201708021014.v72AEHEk061037@repo.freebsd.org> <f7a4a90c-f1d8-b381-27fe-3cf76b574a29@selasky.org> <37abc595-c80e-a8da-04a8-815f42c634de@selasky.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Aug 02, 2017 at 02:38:50PM +0200, Hans Petter Selasky wrote:
> On 08/02/17 14:36, Hans Petter Selasky wrote:
> > On 08/02/17 12:14, Konstantin Belousov wrote:
> >> +#define    major(x)    ((int)((dev_t)(x) >> 32))    /* major number */
> >> +#define    minor(x)    ((int)((x) & 0xffffffff))    /* minor number */
> >> +#define    makedev(x, y)    (((dev_t)(x) << 32) | (y))    /* create 
> >> dev_t */
> > 
> > One more comment on this issue:
> > 
> > I think makedev(x, y) should be declared like this, to avoid issues when 
> > "y" is negative:
> > 
> > #define    makedev(x, y)    (((dev_t)(x) << 32) | (unsigned int)(y))    
> > /* create dev_t */
> > 
> > ???
> > 
> > --HPS
> > 
> > 
> 
> And you'll probably want a final wrapping dev_t cast aswell. 128-bit 
> numbers are not yet there.
> 
> #define	makedev(x, y)    ((dev_t)(((dev_t)(x) << 32) | (unsigned 
> int)(y)))
>  > /* create dev_t */

I agree with the usefulness of the y cast to unsigned type, but I am not sure
what is the use of final dev_t cast.  By the usual arithmetic conversion 
rules, the final type of the '|' is the highest rank type of the operands.
Something unusual can only happen if int is wider than dev_t.

So I am going to commit the following update.

diff --git a/sys/sys/types.h b/sys/sys/types.h
index fce57e412ed..30a08724443 100644
--- a/sys/sys/types.h
+++ b/sys/sys/types.h
@@ -366,7 +366,7 @@ __bitcount64(__uint64_t _x)
 
 #define	major(x)	((int)((dev_t)(x) >> 32))	/* major number */
 #define	minor(x)	((int)((x) & 0xffffffff))	/* minor number */
-#define	makedev(x, y)	(((dev_t)(x) << 32) | (y))	/* create dev_t */
+#define	makedev(x, y)	(((dev_t)(x) << 32) | (unsigned)(y)) /* create dev_t */
 
 /*
  * These declarations belong elsewhere, but are repeated here and in



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170802135455.GG1700>