Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1759239pxb; Thu, 16 Sep 2021 15:05:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxn31jidiUprnVDcw3mXfVQ1PU3ExLmO88tueHda/yFVdVBB9+5Am0Cw0AdqjASEEgPACMY X-Received: by 2002:a17:906:584:: with SMTP id 4mr8625604ejn.56.1631829919354; Thu, 16 Sep 2021 15:05:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631829919; cv=none; d=google.com; s=arc-20160816; b=l6Wmuk1QETNTGLjG4ghr3Jn+CrzfYoozj6p0D5Zqc9UJAwct+59BWm5T6NZrc4aVSn JcD68apmJx74RkCB+G1M5s0N7tcKOQb9p07Q14ZKpJpkhHLWdE5xXobn8efXK69QYHKw vLGF1lQzsb1F7oIw5MD56fu65PhY/7aDzNqBePmDKJ43kBbHGZI79jTR+icq30G9baNN /7kNNoD6muR0Iyz0LEdlQLYh9sit7yhwjsSez4fVCz1ESRuc66i5X/7js6EIfN+P11Te 877UK1qJFQS6ZjQCZe6rVUTYPIM8JCWRKVI94aG0GJkmed5g/Tajra5czT1UaKhQpXp4 7/xg== 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=AFDHm0x5fCIfO9sNUnMjNHBC5QfLbAry/86mc5SrbNI=; b=QTPsM+OFKZ64K1nYn8/qKDFT8qhi/mQc/4+Ejjs9Rbn1A02taJoRbrVUADsbL8lGcy jG5NhA0maxp+NKrIevlH2KKMBrZqlIOuqWsQuqxkD69YaZUGnbIHIoYszmr2QONuxE+A n7C5pBRsvQVh0BXEax+vCNi/9mNwqAOtpwkXGIUFK73WLsFGhyHbqFCFfDI3MT7e86gQ pybvPH6qT4ZwXvVAYUH5NUuyzIDYxRBqyh2L30IFwrFqgBiOh47O6MSD0g6N41m+4CPC ikCQRFmBnETmEQQu7qIGJgsTwJJBy3ZakLBFJzvQBIl/u22Ou29y+9bu4OqzCAqaPEuo /zTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="uPT1O23/"; 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 l1si4495689edt.613.2021.09.16.15.04.33; Thu, 16 Sep 2021 15:05:19 -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="uPT1O23/"; 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 S243449AbhIPQmt (ORCPT + 99 others); Thu, 16 Sep 2021 12:42:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:50778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242155AbhIPQgs (ORCPT ); Thu, 16 Sep 2021 12:36:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 48CE0619BB; Thu, 16 Sep 2021 16:21:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631809309; bh=QY6MBd25QKZiu36ewlOr0ps4BMJR4Qlho/OjIvbK2xw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uPT1O23/ET317Djo9+lCdATzV9zGyZyz9EzWN06ur1gP8kwSqA+gSBPB87q3Rpfs1 +kB0zAE8ukgMZcotydCrbFABSlI9YwmigDkDlNy09pyV4mC13Nz9XxMqNdTPGkHqiP Bo8t1kFa8Rw48vnmsdozYdjmCM17UVt8wlB0Lt+E= 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 5.13 075/380] RDMA/iwcm: Release resources if iw_cm module initialization fails Date: Thu, 16 Sep 2021 17:57:12 +0200 Message-Id: <20210916155806.559276644@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155803.966362085@linuxfoundation.org> References: <20210916155803.966362085@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 da8adadf4755..75b6da00065a 100644 --- a/drivers/infiniband/core/iwcm.c +++ b/drivers/infiniband/core/iwcm.c @@ -1187,29 +1187,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