Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2565116lkm; Mon, 20 Sep 2021 18:51:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmG7qqR9gW8s0O7AgNs6C0Wmxr9uORJlRtPBViUV/fUHu+rt4d638K6Dy7x8AxDZa37HoI X-Received: by 2002:a05:6e02:154e:: with SMTP id j14mr6243280ilu.303.1632188944842; Mon, 20 Sep 2021 18:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188944; cv=none; d=google.com; s=arc-20160816; b=tuyrTpv56586bb5EDCCNERn4092ipy72JlrH0YKoNsgPUw16sN6BSJuPlKzWdfBGad 6bxPh1O0Jfeh4DDKggU1lC7hA+0+cPxYPyl3XYTNCXntpb91dADlEtesPtoNmshIaNsH W6bFeJRlC0mt07NSEL2duYgr5pnrkeHddWYq0kv/57VqpjQotZ6983FXK9+N7K//tyn9 UHlkvg/AzXDgwS67xOsA0QPpb50t2in9ytnsP7s6IQaeAw/CNq8qv7UnT/ewBhTakZ0m 2Tjrk7qf4XzYb2b4anuGawmNgbkTm4K2eBgmQ4h5dsqhg4rZJqJqQy+cCp6YgbR3uA6V eEyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7R/0+E9XH7ZaYv4u+1FHe5cWRRhYf60STTBk+EDUIKY=; b=APKEasgTeS6GIgUDpsYsMB2pRUtqLy6I0TeyJiuQgJfD6elMtah/fB09nc1ePze8oe twBDggIVKlEjiGoG4KSRAzsEUeapmK/YUm8dXMxe9fsKAqOBYcHOn7PmBuDYPgAclXMU yO57fwGySELB4w5QncNj+Jl4DZ+urEJUJVs53WnabrhWh1rk36pVIJRpIVEsCIf/x3Pu pxVRNeSm+9yGn3P+t8gTpmo8SbZucrmlFQ5N2bqWxHafaqOsbksr0TKAz2TBCE8jeNSO sPrEfJQ16hbYr+n4DM6IGObPDzYDZwsBNfpMhJ4vK0nlzXm4R1VFyHXvjSeu2wQVpbpD 5ZKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fuFlAe2y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j11si14473402ilu.130.2021.09.20.18.48.52; Mon, 20 Sep 2021 18:49:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fuFlAe2y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349456AbhITRrn (ORCPT + 99 others); Mon, 20 Sep 2021 13:47:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:48616 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353535AbhITRpK (ORCPT ); Mon, 20 Sep 2021 13:45:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 51DEC617E5; Mon, 20 Sep 2021 17:10:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157802; bh=6tvwoOAlcjIycR11o2SvqXIqdGko0qu5Oi80GOJY9Os=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fuFlAe2y0Gy3QmFBaDWCxZ6Z/pG3z3M1PIiYDp/ZnikSd7OfO5PI/HJ2Of6FedbD/ iMiKJK8jS87bVOKNDvwUqphZy5Nmo9N/TweSf6zoKCdrLH6Qj+8gom2T5B5XjNYQWd Z8hoE/PSq0uOJibaQKxne57nvhS+awM/V/oMle5g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 4.19 158/293] RDMA/iwcm: Release resources if iw_cm module initialization fails Date: Mon, 20 Sep 2021 18:42:00 +0200 Message-Id: <20210920163938.701165533@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leon Romanovsky [ Upstream commit e677b72a0647249370f2635862bf0241c86f66ad ] The failure during iw_cm module initialization partially left the system with unreleased memory and other resources. Rewrite the module init/exit routines in such way that netlink commands will be opened only after successful initialization. Fixes: b493d91d333e ("iwcm: common code for port mapper") Link: https://lore.kernel.org/r/b01239f99cb1a3e6d2b0694c242d89e6410bcd93.1627048781.git.leonro@nvidia.com Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/iwcm.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c index 99dd8452724d..57aec656ab7f 100644 --- a/drivers/infiniband/core/iwcm.c +++ b/drivers/infiniband/core/iwcm.c @@ -1173,29 +1173,34 @@ static int __init iw_cm_init(void) ret = iwpm_init(RDMA_NL_IWCM); if (ret) - pr_err("iw_cm: couldn't init iwpm\n"); - else - rdma_nl_register(RDMA_NL_IWCM, iwcm_nl_cb_table); + return ret; + iwcm_wq = alloc_ordered_workqueue("iw_cm_wq", 0); if (!iwcm_wq) - return -ENOMEM; + goto err_alloc; iwcm_ctl_table_hdr = register_net_sysctl(&init_net, "net/iw_cm", iwcm_ctl_table); if (!iwcm_ctl_table_hdr) { pr_err("iw_cm: couldn't register sysctl paths\n"); - destroy_workqueue(iwcm_wq); - return -ENOMEM; + goto err_sysctl; } + rdma_nl_register(RDMA_NL_IWCM, iwcm_nl_cb_table); return 0; + +err_sysctl: + destroy_workqueue(iwcm_wq); +err_alloc: + iwpm_exit(RDMA_NL_IWCM); + return -ENOMEM; } static void __exit iw_cm_cleanup(void) { + rdma_nl_unregister(RDMA_NL_IWCM); unregister_net_sysctl_table(iwcm_ctl_table_hdr); destroy_workqueue(iwcm_wq); - rdma_nl_unregister(RDMA_NL_IWCM); iwpm_exit(RDMA_NL_IWCM); } -- 2.30.2