Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp704706pxb; Tue, 5 Apr 2022 19:33:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEpFh6Pn1tGmNl+SmkRVK+FIJf3kD1d5Ncd2U61YuHXcKH2LGvhu9AR9+sLFCo0OgmleAm X-Received: by 2002:a17:90b:17c5:b0:1c6:3639:7daf with SMTP id me5-20020a17090b17c500b001c636397dafmr7418447pjb.105.1649212392994; Tue, 05 Apr 2022 19:33:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649212392; cv=none; d=google.com; s=arc-20160816; b=j/YgziU9bGiFUIYaVI7KL3pX2lrSHLPeCoxj0L7QtI7t87xtI/ccy1TlG8mrUaEiWs o8xvt4n4g9M9ltquvc7lu/FkG+NBcsSsVloNNTDPr0ELKLviiZzm3e0Hm/7y08Bu/ock iAhkJ4rOVHjw0+5vua+IT9lANepXftLu/JNWlnNfczlonaTkwSnI1Q2WbHIuaZ8zCqxc ofKa3X4zyPShoTl9gPJJAMP/xIiUJWUUGV0d7JfDJXHSGeNRt1AcUmyAkbeFBg8LbRxF 7GZ/bxhVBH8npggFCS1NXKPTXrLeS3Y1BamUv4kl2hTo77rpcN5eRjFLIZfqDRmtOyZa cgig== 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=mSjp+rR3bOB1o8eYiFx1i9AzxffjehLrVzE6oayqUkg=; b=xH4NeDKVUK8GUW+1PfhZ+OdZbK06wLMappBCOfx5LY2aMHPmqzjvPOhFhENoJs87gw Nkdf8UIB8AK1D3C7OonWvsMeiDIwX+Fk93poETeVrYB7QUSLFZgOwwURIEgDJz/y73My BG347CWq55Z/pBijbMEnapIsuvGu3zvxeONDR4aEe2AQ2/0/w5AtFgHNNDp+36u5tt7a DBDRxxtmmc7nUh/XM2rI0HwjtXYHQItV/+JmEbIxCB9634RxKhteCVDaEP9GLbQ09dGI qzb32puT1ys25jToU0V8WV0el7YS4ULF/XfZwTxj/ILd5GrOSZRVB2uquYDooaC9Ct0J qwvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LT42qelr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m16-20020a170902bb9000b00153bffd0af8si13501215pls.491.2022.04.05.19.32.58; Tue, 05 Apr 2022 19:33:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LT42qelr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1379951AbiDEMx3 (ORCPT + 99 others); Tue, 5 Apr 2022 08:53:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245722AbiDEJMM (ORCPT ); Tue, 5 Apr 2022 05:12:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 482FF31204; Tue, 5 Apr 2022 02:00:14 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 296A061003; Tue, 5 Apr 2022 09:00:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 332F3C385A1; Tue, 5 Apr 2022 09:00:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149213; bh=HNGI4In+9emjSe41kyPORwvUlyYnDXuBY4KQw+sNLoI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LT42qelrjC0bi0+Ahjs6/2Q2aAV1lMgwRhHp7Xw+Y2D/l/o7Q+tk6LyU2nVamNH35 uHvH1TolJ9OBzeRl7mCR7mTCCacHbKk+Gb3feUpDWL9WkQcElOhYWcaOFRBGuRA+8S WNRrKalDXcGseJTzBHfvHehFVczPFQpTDoFIsB6Q= 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.16 0598/1017] RDMA/mlx5: Fix memory leak in error flow for subscribe event routine Date: Tue, 5 Apr 2022 09:25:11 +0200 Message-Id: <20220405070412.028510774@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 08b7f6bc56c3..15c0884d1f49 100644 --- a/drivers/infiniband/hw/mlx5/devx.c +++ b/drivers/infiniband/hw/mlx5/devx.c @@ -1886,8 +1886,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