From patchwork Thu Feb 27 21:17:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 11410801 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BD661580 for ; Thu, 27 Feb 2020 21:47:14 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3237824690 for ; Thu, 27 Feb 2020 21:47:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3237824690 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lustre-devel-bounces@lists.lustre.org Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 1C84E34B3E2; Thu, 27 Feb 2020 13:37:20 -0800 (PST) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from smtp3.ccs.ornl.gov (smtp3.ccs.ornl.gov [160.91.203.39]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 00D81348942 for ; Thu, 27 Feb 2020 13:21:10 -0800 (PST) Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp3.ccs.ornl.gov (Postfix) with ESMTP id C724591C4; Thu, 27 Feb 2020 16:18:19 -0500 (EST) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id C550247C; Thu, 27 Feb 2020 16:18:19 -0500 (EST) From: James Simmons To: Andreas Dilger , Oleg Drokin , NeilBrown Date: Thu, 27 Feb 2020 16:17:02 -0500 Message-Id: <1582838290-17243-555-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> References: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> Subject: [lustre-devel] [PATCH 554/622] lnet: change ksocknal_create_peer() to return pointer X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lustre Development List MIME-Version: 1.0 Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" From: Mr NeilBrown ksocknal_create_peer() currently returns an error status, and if that is 0, a pointer is stored in a by-reference argument. The preferred pattern in the kernel is to return the pointer, or the error code encoded with ERR_PTR(). WC-bug-id: https://jira.whamcloud.com/browse/LU-12678 Lustre-commit: 049683bc0fc0 ("LU-12678 lnet: change ksocknal_create_peer() to return pointer") Signed-off-by: Mr NeilBrown Reviewed-on: https://review.whamcloud.com/36833 Reviewed-by: Chris Horn Reviewed-by: James Simmons Reviewed-by: Amir Shehata Reviewed-by: Oleg Drokin Signed-off-by: James Simmons --- net/lnet/klnds/socklnd/socklnd.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/net/lnet/klnds/socklnd/socklnd.c b/net/lnet/klnds/socklnd/socklnd.c index 79068f3..3e69d9c 100644 --- a/net/lnet/klnds/socklnd/socklnd.c +++ b/net/lnet/klnds/socklnd/socklnd.c @@ -98,9 +98,8 @@ kfree(route); } -static int -ksocknal_create_peer(struct ksock_peer_ni **peerp, struct lnet_ni *ni, - struct lnet_process_id id) +static struct ksock_peer_ni * +ksocknal_create_peer(struct lnet_ni *ni, struct lnet_process_id id) { int cpt = lnet_cpt_of_nid(id.nid, ni); struct ksock_net *net = ni->ni_data; @@ -112,7 +111,7 @@ peer_ni = kzalloc_cpt(sizeof(*peer_ni), GFP_NOFS, cpt); if (!peer_ni) - return -ENOMEM; + return ERR_PTR(-ENOMEM); peer_ni->ksnp_ni = ni; peer_ni->ksnp_id = id; @@ -136,15 +135,14 @@ kfree(peer_ni); CERROR("Can't create peer_ni: network shutdown\n"); - return -ESHUTDOWN; + return ERR_PTR(-ESHUTDOWN); } net->ksnn_npeers++; spin_unlock_bh(&net->ksnn_lock); - *peerp = peer_ni; - return 0; + return peer_ni; } void @@ -447,16 +445,15 @@ struct ksock_peer_ni * struct ksock_peer_ni *peer2; struct ksock_route *route; struct ksock_route *route2; - int rc; if (id.nid == LNET_NID_ANY || id.pid == LNET_PID_ANY) return -EINVAL; /* Have a brand new peer_ni ready... */ - rc = ksocknal_create_peer(&peer_ni, ni, id); - if (rc) - return rc; + peer_ni = ksocknal_create_peer(ni, id); + if (IS_ERR(peer_ni)) + return PTR_ERR(peer_ni); route = ksocknal_create_route(ipaddr, port); if (!route) { @@ -1114,9 +1111,11 @@ struct ksock_peer_ni * ksocknal_peer_addref(peer_ni); write_lock_bh(global_lock); } else { - rc = ksocknal_create_peer(&peer_ni, ni, peerid); - if (rc) + peer_ni = ksocknal_create_peer(ni, peerid); + if (IS_ERR(peer_ni)) { + rc = PTR_ERR(peer_ni); goto failed_1; + } write_lock_bh(global_lock);