Commit cb5b047f authored by Hyunchul Lee's avatar Hyunchul Lee Committed by Namjae Jeon

ksmbd: replace PAYLOAD_HEAD with inline function

Replace PAYLOAD_HEAD with inline function.
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarHyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: default avatarNamjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent c2220322
...@@ -9,7 +9,10 @@ ...@@ -9,7 +9,10 @@
#include "glob.h" #include "glob.h"
#include "ndr.h" #include "ndr.h"
#define PAYLOAD_HEAD(d) ((d)->data + (d)->offset) static inline char *ndr_get_field(struct ndr *n)
{
return n->data + n->offset;
}
static int try_to_realloc_ndr_blob(struct ndr *n, size_t sz) static int try_to_realloc_ndr_blob(struct ndr *n, size_t sz)
{ {
...@@ -30,7 +33,7 @@ static void ndr_write_int16(struct ndr *n, __u16 value) ...@@ -30,7 +33,7 @@ static void ndr_write_int16(struct ndr *n, __u16 value)
if (n->length <= n->offset + sizeof(value)) if (n->length <= n->offset + sizeof(value))
try_to_realloc_ndr_blob(n, sizeof(value)); try_to_realloc_ndr_blob(n, sizeof(value));
*(__le16 *)PAYLOAD_HEAD(n) = cpu_to_le16(value); *(__le16 *)ndr_get_field(n) = cpu_to_le16(value);
n->offset += sizeof(value); n->offset += sizeof(value);
} }
...@@ -39,7 +42,7 @@ static void ndr_write_int32(struct ndr *n, __u32 value) ...@@ -39,7 +42,7 @@ static void ndr_write_int32(struct ndr *n, __u32 value)
if (n->length <= n->offset + sizeof(value)) if (n->length <= n->offset + sizeof(value))
try_to_realloc_ndr_blob(n, sizeof(value)); try_to_realloc_ndr_blob(n, sizeof(value));
*(__le32 *)PAYLOAD_HEAD(n) = cpu_to_le32(value); *(__le32 *)ndr_get_field(n) = cpu_to_le32(value);
n->offset += sizeof(value); n->offset += sizeof(value);
} }
...@@ -48,7 +51,7 @@ static void ndr_write_int64(struct ndr *n, __u64 value) ...@@ -48,7 +51,7 @@ static void ndr_write_int64(struct ndr *n, __u64 value)
if (n->length <= n->offset + sizeof(value)) if (n->length <= n->offset + sizeof(value))
try_to_realloc_ndr_blob(n, sizeof(value)); try_to_realloc_ndr_blob(n, sizeof(value));
*(__le64 *)PAYLOAD_HEAD(n) = cpu_to_le64(value); *(__le64 *)ndr_get_field(n) = cpu_to_le64(value);
n->offset += sizeof(value); n->offset += sizeof(value);
} }
...@@ -57,7 +60,7 @@ static int ndr_write_bytes(struct ndr *n, void *value, size_t sz) ...@@ -57,7 +60,7 @@ static int ndr_write_bytes(struct ndr *n, void *value, size_t sz)
if (n->length <= n->offset + sz) if (n->length <= n->offset + sz)
try_to_realloc_ndr_blob(n, sz); try_to_realloc_ndr_blob(n, sz);
memcpy(PAYLOAD_HEAD(n), value, sz); memcpy(ndr_get_field(n), value, sz);
n->offset += sz; n->offset += sz;
return 0; return 0;
} }
...@@ -67,7 +70,7 @@ static int ndr_write_string(struct ndr *n, void *value, size_t sz) ...@@ -67,7 +70,7 @@ static int ndr_write_string(struct ndr *n, void *value, size_t sz)
if (n->length <= n->offset + sz) if (n->length <= n->offset + sz)
try_to_realloc_ndr_blob(n, sz); try_to_realloc_ndr_blob(n, sz);
strncpy(PAYLOAD_HEAD(n), value, sz); strncpy(ndr_get_field(n), value, sz);
sz++; sz++;
n->offset += sz; n->offset += sz;
n->offset = ALIGN(n->offset, 2); n->offset = ALIGN(n->offset, 2);
...@@ -76,9 +79,9 @@ static int ndr_write_string(struct ndr *n, void *value, size_t sz) ...@@ -76,9 +79,9 @@ static int ndr_write_string(struct ndr *n, void *value, size_t sz)
static int ndr_read_string(struct ndr *n, void *value, size_t sz) static int ndr_read_string(struct ndr *n, void *value, size_t sz)
{ {
int len = strnlen(PAYLOAD_HEAD(n), sz); int len = strnlen(ndr_get_field(n), sz);
memcpy(value, PAYLOAD_HEAD(n), len); memcpy(value, ndr_get_field(n), len);
len++; len++;
n->offset += len; n->offset += len;
n->offset = ALIGN(n->offset, 2); n->offset = ALIGN(n->offset, 2);
...@@ -87,7 +90,7 @@ static int ndr_read_string(struct ndr *n, void *value, size_t sz) ...@@ -87,7 +90,7 @@ static int ndr_read_string(struct ndr *n, void *value, size_t sz)
static int ndr_read_bytes(struct ndr *n, void *value, size_t sz) static int ndr_read_bytes(struct ndr *n, void *value, size_t sz)
{ {
memcpy(value, PAYLOAD_HEAD(n), sz); memcpy(value, ndr_get_field(n), sz);
n->offset += sz; n->offset += sz;
return 0; return 0;
} }
...@@ -96,7 +99,7 @@ static __u16 ndr_read_int16(struct ndr *n) ...@@ -96,7 +99,7 @@ static __u16 ndr_read_int16(struct ndr *n)
{ {
__u16 ret; __u16 ret;
ret = le16_to_cpu(*(__le16 *)PAYLOAD_HEAD(n)); ret = le16_to_cpu(*(__le16 *)ndr_get_field(n));
n->offset += sizeof(__u16); n->offset += sizeof(__u16);
return ret; return ret;
} }
...@@ -105,7 +108,7 @@ static __u32 ndr_read_int32(struct ndr *n) ...@@ -105,7 +108,7 @@ static __u32 ndr_read_int32(struct ndr *n)
{ {
__u32 ret; __u32 ret;
ret = le32_to_cpu(*(__le32 *)PAYLOAD_HEAD(n)); ret = le32_to_cpu(*(__le32 *)ndr_get_field(n));
n->offset += sizeof(__u32); n->offset += sizeof(__u32);
return ret; return ret;
} }
...@@ -114,7 +117,7 @@ static __u64 ndr_read_int64(struct ndr *n) ...@@ -114,7 +117,7 @@ static __u64 ndr_read_int64(struct ndr *n)
{ {
__u64 ret; __u64 ret;
ret = le64_to_cpu(*(__le64 *)PAYLOAD_HEAD(n)); ret = le64_to_cpu(*(__le64 *)ndr_get_field(n));
n->offset += sizeof(__u64); n->offset += sizeof(__u64);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment