Date: Tue, 10 Nov 2015 08:17:37 +1100 (EST) From: Bruce Evans <brde@optusnet.com.au> To: "Conrad E. Meyer" <cem@freebsd.org> 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 Message-ID: <20151110080516.M4088@besplex.bde.org> In-Reply-To: <201511091650.tA9Gog7d061645@repo.freebsd.org> References: <201511091650.tA9Gog7d061645@repo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20151110080516.M4088>