Revert "can-calc-bit-timing: import helper macros from kernel"

This reverts commit 95f62518d1.
pull/25/head
Toon Stegen 2016-06-28 16:44:36 +02:00
parent 8c5cd245f6
commit e6acbb1428
1 changed files with 22 additions and 54 deletions

View File

@ -28,70 +28,38 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/can/netlink.h> #include <linux/can/netlink.h>
/* imported from kernel */ /* seems not to be defined in errno.h */
#ifndef ENOTSUPP
#define ENOTSUPP 524 /* Operation is not supported */
#endif
/** /* useful defines */
* abs - return absolute value of an argument #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
* @x: the value. If it is unsigned type, it is converted to signed type first.
* char is treated as if it was signed (regardless of whether it really is)
* but the macro's return type is preserved as char.
*
* Return: an absolute value of x.
*/
#define abs(x) __abs_choose_expr(x, long long, \
__abs_choose_expr(x, long, \
__abs_choose_expr(x, int, \
__abs_choose_expr(x, short, \
__abs_choose_expr(x, char, \
__builtin_choose_expr( \
__builtin_types_compatible_p(typeof(x), char), \
(char)({ signed char __x = (x); __x<0?-__x:__x; }), \
((void)0)))))))
#define __abs_choose_expr(x, type, other) __builtin_choose_expr( \ #define do_div(a,b) a = (a) / (b)
__builtin_types_compatible_p(typeof(x), signed type) || \
__builtin_types_compatible_p(typeof(x), unsigned type), \
({ signed type __x = (x); __x < 0 ? -__x : __x; }), other)
/* #define abs(x) ({ \
* min()/max()/clamp() macros that also do long __x = (x); \
* strict type-checking.. See the (__x < 0) ? -__x : __x; \
* "unnecessary" pointer comparison. })
*/
#define min(x, y) ({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
#define max(x, y) ({ \
typeof(x) _max1 = (x); \
typeof(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })
/** /**
* clamp - return a value clamped to a given range with strict typechecking * clamp - return a value clamped to a given range with strict typechecking
* @val: current value * @val: current value
* @lo: lowest allowable value * @min: minimum allowable value
* @hi: highest allowable value * @max: maximum allowable value
* *
* This macro does strict typechecking of lo/hi to make sure they are of the * This macro does strict typechecking of min/max to make sure they are of the
* same type as val. See the unnecessary pointer comparisons. * same type as val. See the unnecessary pointer comparisons.
*/ */
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi) #define clamp(val, min, max) ({ \
typeof(val) __val = (val); \
# define do_div(n,base) ({ \ typeof(min) __min = (min); \
uint32_t __base = (base); \ typeof(max) __max = (max); \
uint32_t __rem; \ (void) (&__val == &__min); \
__rem = ((uint64_t)(n)) % __base; \ (void) (&__val == &__max); \
(n) = ((uint64_t)(n)) / __base; \ __val = __val < __min ? __min: __val; \
__rem; \ __val > __max ? __max: __val; })
})
/* */
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
/* we don't want to see these prints */ /* we don't want to see these prints */
#define netdev_err(dev, format, arg...) do { } while (0) #define netdev_err(dev, format, arg...) do { } while (0)