SUNRPC: Move simple_get_bytes and simple_get_netobj into private header

Remove duplicated helper functions to parse opaque XDR objects
and place inside new file net/sunrpc/auth_gss/auth_gss_internal.h.
In the new file carry the license and copyright from the source file
net/sunrpc/auth_gss/auth_gss.c. Finally, update the comment inside
include/linux/sunrpc/xdr.h since lockd is not the only user of
struct xdr_netobj.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>

authored by Dave Wysochanski and committed by Trond Myklebust ba6dfce4 d29b468d

+46 -60
+1 -2
include/linux/sunrpc/xdr.h
··· 25 25 #define XDR_QUADLEN(l) (((l) + 3) >> 2) 26 26 27 27 /* 28 - * Generic opaque `network object.' At the kernel level, this type 29 - * is used only by lockd. 28 + * Generic opaque `network object.' 30 29 */ 31 30 #define XDR_MAX_NETOBJ 1024 32 31 struct xdr_netobj {
+1 -29
net/sunrpc/auth_gss/auth_gss.c
··· 29 29 #include <linux/uaccess.h> 30 30 #include <linux/hashtable.h> 31 31 32 + #include "auth_gss_internal.h" 32 33 #include "../netns.h" 33 34 34 35 #include <trace/events/rpcgss.h> ··· 124 123 set_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 125 124 smp_mb__before_atomic(); 126 125 clear_bit(RPCAUTH_CRED_NEW, &cred->cr_flags); 127 - } 128 - 129 - static const void * 130 - simple_get_bytes(const void *p, const void *end, void *res, size_t len) 131 - { 132 - const void *q = (const void *)((const char *)p + len); 133 - if (unlikely(q > end || q < p)) 134 - return ERR_PTR(-EFAULT); 135 - memcpy(res, p, len); 136 - return q; 137 - } 138 - 139 - static inline const void * 140 - simple_get_netobj(const void *p, const void *end, struct xdr_netobj *dest) 141 - { 142 - const void *q; 143 - unsigned int len; 144 - 145 - p = simple_get_bytes(p, end, &len, sizeof(len)); 146 - if (IS_ERR(p)) 147 - return p; 148 - q = (const void *)((const char *)p + len); 149 - if (unlikely(q > end || q < p)) 150 - return ERR_PTR(-EFAULT); 151 - dest->data = kmemdup(p, len, GFP_NOFS); 152 - if (unlikely(dest->data == NULL)) 153 - return ERR_PTR(-ENOMEM); 154 - dest->len = len; 155 - return q; 156 126 } 157 127 158 128 static struct gss_cl_ctx *
+42
net/sunrpc/auth_gss/auth_gss_internal.h
··· 1 + // SPDX-License-Identifier: BSD-3-Clause 2 + /* 3 + * linux/net/sunrpc/auth_gss/auth_gss_internal.h 4 + * 5 + * Internal definitions for RPCSEC_GSS client authentication 6 + * 7 + * Copyright (c) 2000 The Regents of the University of Michigan. 8 + * All rights reserved. 9 + * 10 + */ 11 + #include <linux/err.h> 12 + #include <linux/string.h> 13 + #include <linux/sunrpc/xdr.h> 14 + 15 + static inline const void * 16 + simple_get_bytes(const void *p, const void *end, void *res, size_t len) 17 + { 18 + const void *q = (const void *)((const char *)p + len); 19 + if (unlikely(q > end || q < p)) 20 + return ERR_PTR(-EFAULT); 21 + memcpy(res, p, len); 22 + return q; 23 + } 24 + 25 + static inline const void * 26 + simple_get_netobj(const void *p, const void *end, struct xdr_netobj *dest) 27 + { 28 + const void *q; 29 + unsigned int len; 30 + 31 + p = simple_get_bytes(p, end, &len, sizeof(len)); 32 + if (IS_ERR(p)) 33 + return p; 34 + q = (const void *)((const char *)p + len); 35 + if (unlikely(q > end || q < p)) 36 + return ERR_PTR(-EFAULT); 37 + dest->data = kmemdup(p, len, GFP_NOFS); 38 + if (unlikely(dest->data == NULL)) 39 + return ERR_PTR(-ENOMEM); 40 + dest->len = len; 41 + return q; 42 + }
+2 -29
net/sunrpc/auth_gss/gss_krb5_mech.c
··· 21 21 #include <linux/sunrpc/xdr.h> 22 22 #include <linux/sunrpc/gss_krb5_enctypes.h> 23 23 24 + #include "auth_gss_internal.h" 25 + 24 26 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) 25 27 # define RPCDBG_FACILITY RPCDBG_AUTH 26 28 #endif ··· 143 141 if (supported_gss_krb5_enctypes[i].etype == etype) 144 142 return &supported_gss_krb5_enctypes[i]; 145 143 return NULL; 146 - } 147 - 148 - static const void * 149 - simple_get_bytes(const void *p, const void *end, void *res, int len) 150 - { 151 - const void *q = (const void *)((const char *)p + len); 152 - if (unlikely(q > end || q < p)) 153 - return ERR_PTR(-EFAULT); 154 - memcpy(res, p, len); 155 - return q; 156 - } 157 - 158 - static const void * 159 - simple_get_netobj(const void *p, const void *end, struct xdr_netobj *res) 160 - { 161 - const void *q; 162 - unsigned int len; 163 - 164 - p = simple_get_bytes(p, end, &len, sizeof(len)); 165 - if (IS_ERR(p)) 166 - return p; 167 - q = (const void *)((const char *)p + len); 168 - if (unlikely(q > end || q < p)) 169 - return ERR_PTR(-EFAULT); 170 - res->data = kmemdup(p, len, GFP_NOFS); 171 - if (unlikely(res->data == NULL)) 172 - return ERR_PTR(-ENOMEM); 173 - res->len = len; 174 - return q; 175 144 } 176 145 177 146 static inline const void *