On Fri, Jul 27, 2012 at 09:16:48AM +0000, Gleb Smirnoff wrote:
> Author: glebius
> Date: Fri Jul 27 09:16:48 2012
> New Revision: 238828
> URL: http://svn.freebsd.org/changeset/base/238828
> 
> Log:
>   Add assertion for refcount overflow.
>   
>   Submitted by:       Andrey Zonov <andrey zonov.org>
>   Reviewed by:        kib
It was discussed rather then reviewed.

I suggest that the assert may be expressed as a check after the increment,
which verifies that counter is != 0. This allows to avoid namespace
pollution due to limits.h.

> 
> Modified:
>   head/sys/sys/refcount.h
> 
> Modified: head/sys/sys/refcount.h
> ==============================================================================
> --- head/sys/sys/refcount.h   Fri Jul 27 08:28:44 2012        (r238827)
> +++ head/sys/sys/refcount.h   Fri Jul 27 09:16:48 2012        (r238828)
> @@ -32,6 +32,7 @@
>  #ifndef __SYS_REFCOUNT_H__
>  #define __SYS_REFCOUNT_H__
>  
> +#include <sys/limits.h>
>  #include <machine/atomic.h>
>  
>  #ifdef _KERNEL
> @@ -51,6 +52,7 @@ static __inline void
>  refcount_acquire(volatile u_int *count)
>  {
>  
> +     KASSERT(*count < UINT_MAX, ("refcount %p overflowed", count));
>       atomic_add_acq_int(count, 1);   
>  }
>  

Attachment: pgpJxVKV88a0I.pgp
Description: PGP signature

Reply via email to