Commit 50043859 authored by J. Bruce Fields's avatar J. Bruce Fields

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: default avatarJ. Bruce Fields <bfields@redhat.com>
parent 6496500c
...@@ -1857,15 +1857,24 @@ static void copy_clid(struct nfs4_client *target, struct nfs4_client *source) ...@@ -1857,15 +1857,24 @@ static void copy_clid(struct nfs4_client *target, struct nfs4_client *source)
target->cl_clientid.cl_id = source->cl_clientid.cl_id; target->cl_clientid.cl_id = source->cl_clientid.cl_id;
} }
static int copy_cred(struct svc_cred *target, struct svc_cred *source) int strdup_if_nonnull(char **target, char *source)
{ {
if (source->cr_principal) { if (source) {
target->cr_principal = *target = kstrdup(source, GFP_KERNEL);
kstrdup(source->cr_principal, GFP_KERNEL); if (!*target)
if (target->cr_principal == NULL)
return -ENOMEM; return -ENOMEM;
} else } else
target->cr_principal = NULL; *target = NULL;
return 0;
}
static int copy_cred(struct svc_cred *target, struct svc_cred *source)
{
int ret;
ret = strdup_if_nonnull(&target->cr_principal, source->cr_principal);
if (ret)
return ret;
target->cr_flavor = source->cr_flavor; target->cr_flavor = source->cr_flavor;
target->cr_uid = source->cr_uid; target->cr_uid = source->cr_uid;
target->cr_gid = source->cr_gid; target->cr_gid = source->cr_gid;
......
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