xref: /dflybsd-src/sys/dev/drm/include/linux/err.h (revision a05eeebfe8ec06e5625c15c535aed68dbf568bd6)
1e3ba7d9fSFrançois Tigeot /*-
2e3ba7d9fSFrançois Tigeot  * Copyright (c) 2010 Isilon Systems, Inc.
3e3ba7d9fSFrançois Tigeot  * Copyright (c) 2010 iX Systems, Inc.
4e3ba7d9fSFrançois Tigeot  * Copyright (c) 2010 Panasas, Inc.
5*a05eeebfSFrançois Tigeot  * Copyright (c) 2016 François Tigeot
6e3ba7d9fSFrançois Tigeot  * All rights reserved.
7e3ba7d9fSFrançois Tigeot  *
8e3ba7d9fSFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
9e3ba7d9fSFrançois Tigeot  * modification, are permitted provided that the following conditions
10e3ba7d9fSFrançois Tigeot  * are met:
11e3ba7d9fSFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
12e3ba7d9fSFrançois Tigeot  *    notice unmodified, this list of conditions, and the following
13e3ba7d9fSFrançois Tigeot  *    disclaimer.
14e3ba7d9fSFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
15e3ba7d9fSFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
16e3ba7d9fSFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
17e3ba7d9fSFrançois Tigeot  *
18e3ba7d9fSFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19e3ba7d9fSFrançois Tigeot  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20e3ba7d9fSFrançois Tigeot  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21e3ba7d9fSFrançois Tigeot  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22e3ba7d9fSFrançois Tigeot  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23e3ba7d9fSFrançois Tigeot  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24e3ba7d9fSFrançois Tigeot  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25e3ba7d9fSFrançois Tigeot  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26e3ba7d9fSFrançois Tigeot  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27e3ba7d9fSFrançois Tigeot  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28e3ba7d9fSFrançois Tigeot  */
29e3ba7d9fSFrançois Tigeot 
30e3ba7d9fSFrançois Tigeot #ifndef	_LINUX_ERR_H_
31e3ba7d9fSFrançois Tigeot #define	_LINUX_ERR_H_
32e3ba7d9fSFrançois Tigeot 
33e3ba7d9fSFrançois Tigeot #define MAX_ERRNO	4095
34e3ba7d9fSFrançois Tigeot 
35e3ba7d9fSFrançois Tigeot #define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO)
36e3ba7d9fSFrançois Tigeot 
37e3ba7d9fSFrançois Tigeot static inline void *
ERR_PTR(long error)38e3ba7d9fSFrançois Tigeot ERR_PTR(long error)
39e3ba7d9fSFrançois Tigeot {
40e3ba7d9fSFrançois Tigeot 	return (void *)error;
41e3ba7d9fSFrançois Tigeot }
42e3ba7d9fSFrançois Tigeot 
43e3ba7d9fSFrançois Tigeot static inline long
PTR_ERR(const void * ptr)44e3ba7d9fSFrançois Tigeot PTR_ERR(const void *ptr)
45e3ba7d9fSFrançois Tigeot {
46e3ba7d9fSFrançois Tigeot 	return (long)ptr;
47e3ba7d9fSFrançois Tigeot }
48e3ba7d9fSFrançois Tigeot 
49e3ba7d9fSFrançois Tigeot static inline long
IS_ERR(const void * ptr)50e3ba7d9fSFrançois Tigeot IS_ERR(const void *ptr)
51e3ba7d9fSFrançois Tigeot {
52e3ba7d9fSFrançois Tigeot 	return IS_ERR_VALUE((unsigned long)ptr);
53e3ba7d9fSFrançois Tigeot }
54e3ba7d9fSFrançois Tigeot 
55f7ed5b6aSFrançois Tigeot static inline long
IS_ERR_OR_NULL(const void * ptr)56f7ed5b6aSFrançois Tigeot IS_ERR_OR_NULL(const void *ptr)
57f7ed5b6aSFrançois Tigeot {
58f7ed5b6aSFrançois Tigeot 	return !ptr || IS_ERR_VALUE((unsigned long)ptr);
59f7ed5b6aSFrançois Tigeot }
60f7ed5b6aSFrançois Tigeot 
61e3ba7d9fSFrançois Tigeot static inline void *
ERR_CAST(void * ptr)62e3ba7d9fSFrançois Tigeot ERR_CAST(void *ptr)
63e3ba7d9fSFrançois Tigeot {
64e3ba7d9fSFrançois Tigeot 	return (void *)ptr;
65e3ba7d9fSFrançois Tigeot }
66e3ba7d9fSFrançois Tigeot 
PTR_ERR_OR_ZERO(const void * ptr)67*a05eeebfSFrançois Tigeot static inline int PTR_ERR_OR_ZERO( const void *ptr)
68*a05eeebfSFrançois Tigeot {
69*a05eeebfSFrançois Tigeot 	if (IS_ERR(ptr))
70*a05eeebfSFrançois Tigeot 		return PTR_ERR(ptr);
71*a05eeebfSFrançois Tigeot 
72*a05eeebfSFrançois Tigeot 	return 0;
73*a05eeebfSFrançois Tigeot }
74*a05eeebfSFrançois Tigeot 
75e3ba7d9fSFrançois Tigeot #endif	/* _LINUX_ERR_H_ */
76