svn commit: r321920 - head/sys/sys
Konstantin Belousov
kostikbel at gmail.com
Wed Aug 2 13:55:02 UTC 2017
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
More information about the svn-src-all
mailing list