Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1900217pxb; Thu, 16 Sep 2021 19:35:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzkKD7vLsC/bWO4F35WNn8493eatgjjx5Q6GeOVNJD2jNB2o/scjhLTIrRIZ9spN4NRk4N X-Received: by 2002:a92:c56b:: with SMTP id b11mr5908498ilj.225.1631846100398; Thu, 16 Sep 2021 19:35:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631846100; cv=none; d=google.com; s=arc-20160816; b=IUwlnYxbqWwneUX8/g31wav24BgxQaPldvvFNpilvdAld9rp/wazpllgZzAnQ/HVe9 Q/SqKpn3qhoR8ehCemYBYyM9aiMVmSk7BKLxIXAMHbXfOMq3gTsH0+1PpE3C1r4l1vvK Um+//bsdCV/UqSTvjUn7X6MLn0Ayzq+DW0s4s5lhzchLYBrfklwaW1FwzGjsyUl8scGr kNRDEN5LryEzAeqadrBvr8SIIq05sLa9bPBDROjG9yfQWRJBYcKYwWfGjDqh0lLZ5mpt LkhcCOXAJnz2B7n1bXv8575qcZUXVdHMQkMvf6JjlXSSRJAI5SDm/6Ir2znbEM2AbcEJ hi4A== 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=xUoFCqOrjXDj4zyM+7ev+B3nepdu5pzNmlkhCQz4puo=; b=r6kOmNlwinSEjrhN2pUc2RcjQBlFADBONr51efgQnLl4/vm9sRTVEa2NsMPauWpXIn nCqQq+kPMMwsWtpXVcpFPHgnxa1e/rsSc35ub817niVPCoDG4B1cnXTgZS82HBGImDP7 nv89wdMK417J5c5XKnVCAd1us39uzeXpRsQvwqTHr8wKU6vT3lLvQhfL0jAoNMK+AnF5 4cIR1I2LIHRjv79mijkS0b0iBvKwhEdMAEHTGMJW9Zsp2o3PSk4YNkb2tqLMQiUk9823 wb4IF//cnrdLbLsFX9Xp9Rq/RQmLDODI5rNtoH4X1QO7VMAx0l8aUWN9szGiDtfPVkgW c7GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1LFmlgT3; 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 z9si4844552ile.172.2021.09.16.19.34.49; Thu, 16 Sep 2021 19:35:00 -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=1LFmlgT3; 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 S1351850AbhIPRTu (ORCPT + 99 others); Thu, 16 Sep 2021 13:19:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:39748 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350661AbhIPRLy (ORCPT ); Thu, 16 Sep 2021 13:11:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 87497619E8; Thu, 16 Sep 2021 16:38:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631810282; bh=DRQhfn7N1YUU+lNFrA1dYMbzRU+euNsQlv058abfMY4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1LFmlgT3c9ab/1UxprPE/9iHDeluNj2+i7D59++Rh5IvU9z8LCY97Z418ROETTtnF SJ2uWYshdBvfYQT9t6VvUl+Ole6MNIDPlrDMZKBj687NYnlqBk4afX33ExV8Q+qU90 kd5HS+jMGbVweK5ezksFYHcvdWWfpD6R9g3nv1Xw= 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.14 083/432] RDMA/iwcm: Release resources if iw_cm module initialization fails Date: Thu, 16 Sep 2021 17:57:12 +0200 Message-Id: <20210916155813.596889788@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155810.813340753@linuxfoundation.org> References: <20210916155810.813340753@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 42261152b489..2b47073c61a6 100644 --- a/drivers/infiniband/core/iwcm.c +++ b/drivers/infiniband/core/iwcm.c @@ -1186,29 +1186,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