From patchwork Thu Mar 30 06:50:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 9653031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 73492602C8 for ; Thu, 30 Mar 2017 06:51:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6529427813 for ; Thu, 30 Mar 2017 06:51:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5821428571; Thu, 30 Mar 2017 06:51:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5DB727F90 for ; Thu, 30 Mar 2017 06:51:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932718AbdC3GvH (ORCPT ); Thu, 30 Mar 2017 02:51:07 -0400 Received: from mx2.suse.de ([195.135.220.15]:45816 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932231AbdC3GvG (ORCPT ); Thu, 30 Mar 2017 02:51:06 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 4F6DEAC5F; Thu, 30 Mar 2017 06:51:04 +0000 (UTC) From: NeilBrown To: "J. Bruce Fields" , Jason Yan Date: Thu, 30 Mar 2017 17:50:47 +1100 Cc: jlayton@poochiereds.net, linux-nfs@vger.kernel.org, miaoxie@huawei.com, zhaohongjiang@huawei.com Subject: Re: [PATCH] nfsd: make strdup_if_nonnull static In-Reply-To: <20170329215132.GC29934@fieldses.org> References: <1490259456-15858-1-git-send-email-yanaijie@huawei.com> <20170329215132.GC29934@fieldses.org> Message-ID: <874lyb5kc8.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Mar 29 2017, J. Bruce Fields wrote: > Thanks, applying for 4.12.--b. Ugh... does strdup_if_nonnull() actually help readability at all? kstrdup() already handles NULL fine, which is what the name seems to suggest is happening. I would think kstrdup_report_error() is a name that better reflects the function. Or just discard it: NeilBrown > > On Thu, Mar 23, 2017 at 04:57:36PM +0800, Jason Yan wrote: >> Fixes the following sparse warning: >> >> fs/nfsd/nfs4state.c:1915:5: warning: symbol 'strdup_if_nonnull' was not >> declared. Should it be static? >> >> Signed-off-by: Jason Yan >> --- >> fs/nfsd/nfs4state.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c >> index e9ef50a..59a9e30 100644 >> --- a/fs/nfsd/nfs4state.c >> +++ b/fs/nfsd/nfs4state.c >> @@ -1912,7 +1912,7 @@ static void copy_clid(struct nfs4_client *target, struct nfs4_client *source) >> target->cl_clientid.cl_id = source->cl_clientid.cl_id; >> } >> >> -int strdup_if_nonnull(char **target, char *source) >> +static int strdup_if_nonnull(char **target, char *source) >> { >> if (source) { >> *target = kstrdup(source, GFP_KERNEL); >> -- >> 2.5.0 > -- > To unsubscribe from this list: send the line "unsubscribe linux-nfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index e9ef50addddb..cf28d1056e70 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1912,28 +1912,14 @@ static void copy_clid(struct nfs4_client *target, struct nfs4_client *source) target->cl_clientid.cl_id = source->cl_clientid.cl_id; } -int strdup_if_nonnull(char **target, char *source) -{ - if (source) { - *target = kstrdup(source, GFP_KERNEL); - if (!*target) - return -ENOMEM; - } else - *target = NULL; - return 0; -} - static int copy_cred(struct svc_cred *target, struct svc_cred *source) { - int ret; + target->cr_principal = kstrdup(source->cr_principal, GFP_KERNEL); + target->cr_raw_principal = kstrdup(source->cr_raw_principal, GFP_KERNEL); + if ((source->cr_principal && ! target->cr_principal) || + (source->cr_raw_principal && ! target->cr_raw_principal)) + return -ENOMEM; - ret = strdup_if_nonnull(&target->cr_principal, source->cr_principal); - if (ret) - return ret; - ret = strdup_if_nonnull(&target->cr_raw_principal, - source->cr_raw_principal); - if (ret) - return ret; target->cr_flavor = source->cr_flavor; target->cr_uid = source->cr_uid; target->cr_gid = source->cr_gid;