Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1670024pxb; Thu, 16 Sep 2021 12:31:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLeNfiW/6R1p7Nz/4MoBWXhCrCw+GWWDiDWYTN//uLSUdSF86oH14XGkEv3evnGjsC56FV X-Received: by 2002:a50:d805:: with SMTP id o5mr7739043edj.104.1631820703905; Thu, 16 Sep 2021 12:31:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631820703; cv=none; d=google.com; s=arc-20160816; b=vrzG0pOoiUrqo+1xbaH068z2fYyVYGJJGmqsVFaBBIYofbzLuHvagjrmONsR/LedR8 Kh6rGQ0+XVLGEWmxKvPAIeqh5Xx0TueIxfiw/kPmvqR395FMZsyW5/YZtBpc2uZcEly6 88GkIftQlAING/NtdcYGvsxEc6YzBZpS8jqcHzw7F7ZfeQZRf1UC1KRdOGC/rElLPOH6 cYEpV4lAjQysCsq69NPLUU5Q1r3ZnTZperLCgr8iHtetltCuHAmv3tNTV2JLdzjwyHj8 Puo/MKsN6z4XmaFWemH2/Qy7gCHQxp4sSFMBlaG2zbnMe22j6UArcxlwBakrNdYXNosc 6CIw== 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=X7Ul3CI3XnvTaFwpwz3ZFj4ok0X2IWP0n9gOJ2EFXMTZSqX5KjSRETSZ4Yi1v/zWv6 BB/WDZoq3FdsRNXnR0GNQFELOdhsCZeOlJupzABbJGZU7CIoaFVD9GpY/DYVTLANGg7t 4FDJm+G3c4arEQKKGWK2XW3q6piCQuqS74A02Aq8Y5ilWSJ4gUWdyUGtR0Uxsm6KO0x9 1pbZkv75fNCA0qg/tki/pdt7cFNpOJp8QVuh7PD5YohED2Rm9Kc4gXbUF/ZBLvundsFx GJ/duFPPLhuZdfUEpYqArlq7tHFLAt1bUp0aHfauZUpXVGd1VazGkU88cc+XKoPO0LMY aAow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=begjlYQo; 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 y21si4708480edl.278.2021.09.16.12.31.20; Thu, 16 Sep 2021 12:31:43 -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=begjlYQo; 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 S238044AbhIPQLI (ORCPT + 99 others); Thu, 16 Sep 2021 12:11:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:46666 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233137AbhIPQHU (ORCPT ); Thu, 16 Sep 2021 12:07:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 90E4961251; Thu, 16 Sep 2021 16:05:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808360; bh=QY6MBd25QKZiu36ewlOr0ps4BMJR4Qlho/OjIvbK2xw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=begjlYQoR+5i0D31R1nskgEjP3d6/OhvDpxvRDXPVKjbKOcbadJsq0y4BlmFCsU4Z rKMME8nt+4/xdl/1WJBrrLr/En46yGHOIKIlfGkQPJ+DnNfIMjaNxfa53m9kfrsJpO 91sqZDw+QeowyY0iqQtjQVD1jCLxUKcg8MFl5pdg= 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.10 061/306] RDMA/iwcm: Release resources if iw_cm module initialization fails Date: Thu, 16 Sep 2021 17:56:46 +0200 Message-Id: <20210916155756.027920734@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@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