From owner-svn-src-all@freebsd.org Mon Nov 9 21:17:47 2015 Return-Path: Delivered-To: svn-src-all@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 BADBBA2A0AE; Mon, 9 Nov 2015 21:17:47 +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 826B212E3; Mon, 9 Nov 2015 21:17:47 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from c211-30-166-197.carlnfd1.nsw.optusnet.com.au (c211-30-166-197.carlnfd1.nsw.optusnet.com.au [211.30.166.197]) by mail110.syd.optusnet.com.au (Postfix) with ESMTPS id CFEF378225A; Tue, 10 Nov 2015 08:17:38 +1100 (AEDT) Date: Tue, 10 Nov 2015 08:17:37 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: "Conrad E. Meyer" cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r290613 - head/sys/compat/linuxkpi/common/include/linux In-Reply-To: <201511091650.tA9Gog7d061645@repo.freebsd.org> Message-ID: <20151110080516.M4088@besplex.bde.org> References: <201511091650.tA9Gog7d061645@repo.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=R6/+YolX c=1 sm=1 tr=0 a=KA6XNC2GZCFrdESI5ZmdjQ==:117 a=PO7r1zJSAAAA:8 a=JzwRw_2MAAAA:8 a=kj9zAlcOel0A:10 a=IL1IYBiebmrG-NjXDhIA:9 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Nov 2015 21:17:47 -0000 On Mon, 9 Nov 2015, Conrad E. Meyer wrote: > Log: > linuxkpi/sysfs.h: Cast arg2 through intptr_t to avoid GCC warning > > The code compiles fine under Clang, but GCC on PPC is less permissive about > integer and pointer sizes. (An intmax_t is clearly *large enough* to hold a > pointer value.) > > Another follow-up to r290475. This shouldn't compile either. > Modified: head/sys/compat/linuxkpi/common/include/linux/sysfs.h > ============================================================================== > --- head/sys/compat/linuxkpi/common/include/linux/sysfs.h Mon Nov 9 15:59:42 2015 (r290612) > +++ head/sys/compat/linuxkpi/common/include/linux/sysfs.h Mon Nov 9 16:50:42 2015 (r290613) > @@ -80,7 +80,7 @@ sysctl_handle_attr(SYSCTL_HANDLER_ARGS) > ssize_t len; > > kobj = arg1; > - attr = (struct attribute *)arg2; > + attr = (struct attribute *)(intptr_t)arg2; This can have any result (except undefined behviour) since the pointer type is not void *. No warning is required but a good compiler would give 1. > if (kobj->ktype == NULL || kobj->ktype->sysfs_ops == NULL) > return (ENODEV); > buf = (char *)get_zeroed_page(GFP_KERNEL); This shouldn't compile either. The pointer type is not void *, and the integer type is neither intptr_t nor uintptr_t except accidentally on some arches (it is unsigned long), while uintptr_t is unsigned on i386 and unsigned long on amd64. No warning is required, but a good compiler would give 1 and a half. This works on x86 of course, and the code isn't required to work on anything else, but the compiler doesn't know this so should warn about logical type mismatches. Bruce