aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/ceph/decode.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/ceph/decode.h')
-rw-r--r--include/linux/ceph/decode.h30
1 files changed, 26 insertions, 4 deletions
diff --git a/include/linux/ceph/decode.h b/include/linux/ceph/decode.h
index 360d9d08ca9e..379f71508995 100644
--- a/include/linux/ceph/decode.h
+++ b/include/linux/ceph/decode.h
@@ -8,6 +8,23 @@
8 8
9#include <linux/ceph/types.h> 9#include <linux/ceph/types.h>
10 10
11/* This seemed to be the easiest place to define these */
12
13#define U8_MAX ((u8)(~0U))
14#define U16_MAX ((u16)(~0U))
15#define U32_MAX ((u32)(~0U))
16#define U64_MAX ((u64)(~0ULL))
17
18#define S8_MAX ((s8)(U8_MAX >> 1))
19#define S16_MAX ((s16)(U16_MAX >> 1))
20#define S32_MAX ((s32)(U32_MAX >> 1))
21#define S64_MAX ((s64)(U64_MAX >> 1LL))
22
23#define S8_MIN ((s8)(-S8_MAX - 1))
24#define S16_MIN ((s16)(-S16_MAX - 1))
25#define S32_MIN ((s32)(-S32_MAX - 1))
26#define S64_MIN ((s64)(-S64_MAX - 1LL))
27
11/* 28/*
12 * in all cases, 29 * in all cases,
13 * void **p pointer to position pointer 30 * void **p pointer to position pointer
@@ -137,14 +154,19 @@ bad:
137static inline void ceph_decode_timespec(struct timespec *ts, 154static inline void ceph_decode_timespec(struct timespec *ts,
138 const struct ceph_timespec *tv) 155 const struct ceph_timespec *tv)
139{ 156{
140 ts->tv_sec = le32_to_cpu(tv->tv_sec); 157 ts->tv_sec = (__kernel_time_t)le32_to_cpu(tv->tv_sec);
141 ts->tv_nsec = le32_to_cpu(tv->tv_nsec); 158 ts->tv_nsec = (long)le32_to_cpu(tv->tv_nsec);
142} 159}
143static inline void ceph_encode_timespec(struct ceph_timespec *tv, 160static inline void ceph_encode_timespec(struct ceph_timespec *tv,
144 const struct timespec *ts) 161 const struct timespec *ts)
145{ 162{
146 tv->tv_sec = cpu_to_le32(ts->tv_sec); 163 BUG_ON(ts->tv_sec < 0);
147 tv->tv_nsec = cpu_to_le32(ts->tv_nsec); 164 BUG_ON(ts->tv_sec > (__kernel_time_t)U32_MAX);
165 BUG_ON(ts->tv_nsec < 0);
166 BUG_ON(ts->tv_nsec > (long)U32_MAX);
167
168 tv->tv_sec = cpu_to_le32((u32)ts->tv_sec);
169 tv->tv_nsec = cpu_to_le32((u32)ts->tv_nsec);
148} 170}
149 171
150/* 172/*