Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+15 -6
+15 -6
fs/nfsd/nfs4state.c
··· 1857 1857 target->cl_clientid.cl_id = source->cl_clientid.cl_id; 1858 1858 } 1859 1859 1860 - static int copy_cred(struct svc_cred *target, struct svc_cred *source) 1860 + int strdup_if_nonnull(char **target, char *source) 1861 1861 { 1862 - if (source->cr_principal) { 1863 - target->cr_principal = 1864 - kstrdup(source->cr_principal, GFP_KERNEL); 1865 - if (target->cr_principal == NULL) 1862 + if (source) { 1863 + *target = kstrdup(source, GFP_KERNEL); 1864 + if (!*target) 1866 1865 return -ENOMEM; 1867 1866 } else 1868 - target->cr_principal = NULL; 1867 + *target = NULL; 1868 + return 0; 1869 + } 1870 + 1871 + static 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 1878 target->cr_flavor = source->cr_flavor; 1870 1879 target->cr_uid = source->cr_uid; 1871 1880 target->cr_gid = source->cr_gid;