lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sun, 20 Jan 2008 21:56:47 +0900
From:	Tejun Heo <htejun@...il.com>
To:	Rusty Russell <rusty@...tcorp.com.au>
CC:	Linus Torvalds <torvalds@...ux-foundation.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	linux-kernel@...r.kernel.org, Jeff Garzik <jeff@...zik.org>
Subject: Re: [PATCH 0/6] RFC: Typesafe callbacks

Rusty Russell wrote:
> Hi all,
> 
>    Converting to and from void * for callback functions loses type safety: 
> everywhere else we expect the compiler to catch incorrect pointer types 
> handed to functions.
> 
>    It's pretty simple to create typesafe callback functions using typeof, and 
> with a little gcc trickery we can allow both old-style and typesafe callbacks 
> to avoid churn on commonly-used routines.

I wasn't too convinced with only irq handler conversion but with other
things converted, I'm liking it very much.  I really like the timer
conversion as casting between void * and unsigned long is annoying.
Possible improvements.

* Passing NULL as data to callback which takes non-void pointer
  triggers warning.  I think this should be allowed.  Something like
  the following?

* Allowing non-pointer integral types which fit into pointer would be
  nice.  It's often convenient to pass integers to simple callbacks.

The following macro kinda-sorta achieves the above two but it doesn't
consider promotion of integer types and thus is too strict.  There
gotta be some way.

#define kthread_create(threadfn, data, namefmt...) ({		\
	int (*_threadfn)(typeof(data));				\
	void *_data;						\
	_threadfn = __builtin_choose_expr(!__builtin_types_compatible_p(typeof(data), typeof(NULL)), \
			(threadfn), (void *)(threadfn));	\
	_data = __builtin_choose_expr(sizeof(data) <= sizeof(void *), \
			(void *)(unsigned long)data, (void *)data); \
	__kthread_create((void *)_threadfn, _data, namefmt);	\
})

Thanks.

-- 
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ