From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AE82C4332F for ; Thu, 14 Apr 2022 14:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353245AbiDNOjY (ORCPT ); Thu, 14 Apr 2022 10:39:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344760AbiDNNoh (ORCPT ); Thu, 14 Apr 2022 09:44:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 924AE3703D; Thu, 14 Apr 2022 06:40:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D20BAB82987; Thu, 14 Apr 2022 13:40:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4553AC385A1; Thu, 14 Apr 2022 13:40:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649943601; bh=mbdUSHVlV53K0AX1fRMEBXTG9pM0zEjcteH8eqAPhpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SMeWaiQgqKeSa+ZExuMQ1ZxvIX7WD555l9EZ7PAd2CMYoc3qQMbqsDutU9RvD0d41 8sL6P88/ZKX/osQjfvnpKkx3Qtepix0D6XEZ0xIBlcjxyqOIWL2omuuGLsqpXzP5Bm 1ZT5WvDmRHwHZGwgBZl2XmHHOyPAEoScOUXUr1j4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yongzhi Liu , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.4 213/475] RDMA/mlx5: Fix memory leak in error flow for subscribe event routine Date: Thu, 14 Apr 2022 15:09:58 +0200 Message-Id: <20220414110901.086656242@linuxfoundation.org> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220414110855.141582785@linuxfoundation.org> References: <20220414110855.141582785@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: Yongzhi Liu [ Upstream commit 087f9c3f2309ed183f7e4b85ae57121d8663224d ] In case the second xa_insert() fails, the obj_event is not released. Fix the error unwind flow to free that memory to avoid a memory leak. Fixes: 759738537142 ("IB/mlx5: Enable subscription for device events over DEVX") Link: https://lore.kernel.org/r/1647018361-18266-1-git-send-email-lyz_cs@pku.edu.cn Signed-off-by: Yongzhi Liu Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/hw/mlx5/devx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c index 664e0f374ac0..747f42855b7b 100644 --- a/drivers/infiniband/hw/mlx5/devx.c +++ b/drivers/infiniband/hw/mlx5/devx.c @@ -1844,8 +1844,10 @@ subscribe_event_xa_alloc(struct mlx5_devx_event_table *devx_event_table, key_level2, obj_event, GFP_KERNEL); - if (err) + if (err) { + kfree(obj_event); return err; + } INIT_LIST_HEAD(&obj_event->obj_sub_list); } -- 2.34.1