aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ. Bruce Fields <bfields@redhat.com>2015-11-20 15:58:37 -0500
committerJ. Bruce Fields <bfields@redhat.com>2015-11-24 12:39:17 -0500
commit50043859325b377e728676d31aad7affaf91b2ce (patch)
tree1aaf138f9d318000bf158b28fb0e4cd039b5857c
parent6496500cf15f29ac8afc565e2e4b6f92a1324860 (diff)
nfsd: helper for dup of possibly NULL string
Technically the initialization in the NULL case isn't even needed as the only caller already has target zeroed out, but it seems safer to keep copy_cred generic. Signed-off-by: J. Bruce Fields <bfields@redhat.com>
-rw-r--r--fs/nfsd/nfs4state.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 9f6beb8e9918..641604a221bc 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -1857,15 +1857,24 @@ static void copy_clid(struct nfs4_client *target, struct nfs4_client *source)
1857 target->cl_clientid.cl_id = source->cl_clientid.cl_id; 1857 target->cl_clientid.cl_id = source->cl_clientid.cl_id;
1858} 1858}
1859 1859
1860static int copy_cred(struct svc_cred *target, struct svc_cred *source) 1860int strdup_if_nonnull(char **target, char *source)
1861{ 1861{
1862 if (source->cr_principal) { 1862 if (source) {
1863 target->cr_principal = 1863 *target = kstrdup(source, GFP_KERNEL);
1864 kstrdup(source->cr_principal, GFP_KERNEL); 1864 if (!*target)
1865 if (target->cr_principal == NULL)
1866 return -ENOMEM; 1865 return -ENOMEM;
1867 } else 1866 } else
1868 target->cr_principal = NULL; 1867 *target = NULL;
1868 return 0;
1869}
1870
1871static int copy_cred(struct svc_cred *target, struct svc_cred *source)
1872{
1873 int ret;
1874
1875 ret = strdup_if_nonnull(&target->cr_principal, source->cr_principal);
1876 if (ret)
1877 return ret;
1869 target->cr_flavor = source->cr_flavor; 1878 target->cr_flavor = source->cr_flavor;
1870 target->cr_uid = source->cr_uid; 1879 target->cr_uid = source->cr_uid;
1871 target->cr_gid = source->cr_gid; 1880 target->cr_gid = source->cr_gid;