Skip to content

Commit

Permalink
nfsd: helper for dup of possibly NULL string
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
J. Bruce Fields committed Nov 24, 2015
1 parent 6496500 commit 5004385
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions fs/nfsd/nfs4state.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

static int copy_cred(struct svc_cred *target, struct svc_cred *source)
int strdup_if_nonnull(char **target, char *source)
{
if (source->cr_principal) {
target->cr_principal =
kstrdup(source->cr_principal, GFP_KERNEL);
if (target->cr_principal == NULL)
if (source) {
*target = kstrdup(source, GFP_KERNEL);
if (!*target)
return -ENOMEM;
} 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_uid = source->cr_uid;
target->cr_gid = source->cr_gid;
Expand Down

0 comments on commit 5004385

Please sign in to comment.