diff options
Diffstat (limited to 'include/linux/ceph/decode.h')
| -rw-r--r-- | include/linux/ceph/decode.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/include/linux/ceph/decode.h b/include/linux/ceph/decode.h index 220ae21e819b..d8615dee5808 100644 --- a/include/linux/ceph/decode.h +++ b/include/linux/ceph/decode.h | |||
| @@ -46,9 +46,14 @@ static inline void ceph_decode_copy(void **p, void *pv, size_t n) | |||
| 46 | /* | 46 | /* |
| 47 | * bounds check input. | 47 | * bounds check input. |
| 48 | */ | 48 | */ |
| 49 | static inline int ceph_has_room(void **p, void *end, size_t n) | ||
| 50 | { | ||
| 51 | return end >= *p && n <= end - *p; | ||
| 52 | } | ||
| 53 | |||
| 49 | #define ceph_decode_need(p, end, n, bad) \ | 54 | #define ceph_decode_need(p, end, n, bad) \ |
| 50 | do { \ | 55 | do { \ |
| 51 | if (unlikely(*(p) + (n) > (end))) \ | 56 | if (!likely(ceph_has_room(p, end, n))) \ |
| 52 | goto bad; \ | 57 | goto bad; \ |
| 53 | } while (0) | 58 | } while (0) |
| 54 | 59 | ||
| @@ -167,7 +172,7 @@ static inline void ceph_encode_string(void **p, void *end, | |||
| 167 | 172 | ||
| 168 | #define ceph_encode_need(p, end, n, bad) \ | 173 | #define ceph_encode_need(p, end, n, bad) \ |
| 169 | do { \ | 174 | do { \ |
| 170 | if (unlikely(*(p) + (n) > (end))) \ | 175 | if (!likely(ceph_has_room(p, end, n))) \ |
| 171 | goto bad; \ | 176 | goto bad; \ |
| 172 | } while (0) | 177 | } while (0) |
| 173 | 178 | ||
