From owner-svn-src-head@freebsd.org Thu Aug 3 03:53:20 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AED64DC6FDC; Thu, 3 Aug 2017 03:53:20 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail110.syd.optusnet.com.au (mail110.syd.optusnet.com.au [211.29.132.97]) by mx1.freebsd.org (Postfix) with ESMTP id 4421A650AA; Thu, 3 Aug 2017 03:53:19 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from [192.168.0.102] (c110-21-101-228.carlnfd1.nsw.optusnet.com.au [110.21.101.228]) by mail110.syd.optusnet.com.au (Postfix) with ESMTPS id 2CEFD107834; Thu, 3 Aug 2017 13:21:57 +1000 (AEST) Date: Thu, 3 Aug 2017 13:21:56 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Konstantin Belousov cc: Hans Petter Selasky , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r321920 - head/sys/sys In-Reply-To: <20170802135455.GG1700@kib.kiev.ua> Message-ID: <20170803122015.Q1093@besplex.bde.org> References: <201708021014.v72AEHEk061037@repo.freebsd.org> <37abc595-c80e-a8da-04a8-815f42c634de@selasky.org> <20170802135455.GG1700@kib.kiev.ua> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.2 cv=KeqiiUQD c=1 sm=1 tr=0 a=PalzARQSbocsUSjMRkwAPg==:117 a=PalzARQSbocsUSjMRkwAPg==:17 a=kj9zAlcOel0A:10 a=DIZZVqnLoRRTIwBj3f8A:9 a=JUE4OAOBgtXzTOa8:21 a=zo0XxFwiP1CiXz7P:21 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Aug 2017 03:53:20 -0000 On Wed, 2 Aug 2017, Konstantin Belousov wrote: > 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 */ I think this has a lot of style bugs: - long line constructed by blind expansion - verbose spelling of 'unsigned' in the expansion to make the long line longer - banal comment to make the long line. The comment on this line is not quite as banal as the ones on the preceding 2 line -- those do less than echo the code. >> 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 */ You mean 128-bit ints. > 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 it happens with 128 ints (or 65-bit ints) if dev_t remains 64 bits. > So I am going to commit the following update. Almost OK. The necessary casts and parentheses are already ugly enough. This is the implementation, so it can assume that int is 32 bits and dev_t is 64 bits and not have the complexity to support the general case. Ints are probably assumed to be 32 bits in a few thousand similar definitions and a few million lines of code just in FreeBSD sources. > 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 You fixed the long line by not spelling 'unsigned' verbosely and not aligning the comments uniformly. It would be better to remove the comments. makedev() actually has a man page (a FreeBSD addition makedev(3)). This could have been better, and is now out of date. The largest error is that major() is still documented to return a value between 0 and 255. This reduction prevented makedev() being the inverse of major()+minor() on arbitrary args. The man page doesn't claim that it is, and barely gives a hint that makedev() can be used to synthesize a dev_t from (x, y) provided 0 <= x <= 255. Bruce