Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp746041pxb; Tue, 5 Apr 2022 21:29:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaeMsnM7wKHvY4vU8U5K4jXsHVXsq59xJU5syR13RQruR2k0SETCdsqpIYsS4Hcx4TmFsi X-Received: by 2002:a17:902:db0f:b0:156:9bf0:952d with SMTP id m15-20020a170902db0f00b001569bf0952dmr6734382plx.52.1649219395691; Tue, 05 Apr 2022 21:29:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649219395; cv=none; d=google.com; s=arc-20160816; b=aLKlokQm1ShtXKl1RoVA48ESyBy2313PMRx5OL/vGQOaeWtw0dxBje0sr2NhQGTzzf 122xtIcFFlfqHZVHnA19sX/xv3Zesu34VIZAxpFUwNkvsI1PqN5ptvisgnCgJHq230Dy cgvHlbDnazuDXHl3d5fIRhhU/jhBL16mOR6CTyettYwAZdthWMI4DvUUY19KA2mOlidl 6F1W+g/vPozwq8fYyl0yVRPo5/B6a+lgQbyUJ77qTQIwI+JZLcgU2O8GlrtxfXPG6RSU ZguS8VPzKEMBV1CaW5fjpYx7sA9OyQ+ocrA8wmFkigtFIIMUfGgAFuTcasoffecPbZwZ UkYA== 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=yn0g+sli56scUN4isIWdYkkKJFYlmboGTLjY0PzM8QydFARHd3y45/dTtg31Rabo7c BN7hlkSNCTfq48tM5OGFiTFlvPgGg6Zv+JHRaIKK0s8jKgzvUMlUYduDLtvK9FyTuRHA T7Nw+P6kUQ87c6VhZPHVOC8T34S06DBF1Ob1tsj8oXsGcQyFhPFYug2qCtYNM868LHlt o2e66YcUyXopAJNu/Ajynvg0ovcP6Bsc7Mtti8746u3Dne1FzUIwZXY9eJ7Bc65jjBpu mHEdwXta9Wfd6mtwnu1lDDRxZWmNQ/Dx0zuqJ0plmuG7aj9rt5QuyLov1UIGh2cLrOK0 6mCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i0fjCUAQ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id i71-20020a639d4a000000b003994c58fe83si5530011pgd.143.2022.04.05.21.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 21:29:55 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i0fjCUAQ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EFCAA181149; Tue, 5 Apr 2022 19:52:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350367AbiDEJ5p (ORCPT + 99 others); Tue, 5 Apr 2022 05:57:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238619AbiDEITO (ORCPT ); Tue, 5 Apr 2022 04:19:14 -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 A3E6B10FDD; Tue, 5 Apr 2022 01:09: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 7C893B81B18; Tue, 5 Apr 2022 08:09:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5801C385A1; Tue, 5 Apr 2022 08:09:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649146149; bh=HNGI4In+9emjSe41kyPORwvUlyYnDXuBY4KQw+sNLoI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i0fjCUAQciEQmHRjGlTyChHrqvQWS+7GpM/uJmq363cigXrRyMYaDMNRLiw0AY4Mx PvxZKOpCzPn1cTdC83Y+H5Aat5aEcinT4UzSeED4tOd86lw78YbbxwY5uPEAFY8TZc 6dy5nLdilkY5kOlf5LJszKQUdjXtMuiJMOxi5KhI= 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.17 0659/1126] RDMA/mlx5: Fix memory leak in error flow for subscribe event routine Date: Tue, 5 Apr 2022 09:23:26 +0200 Message-Id: <20220405070426.972565560@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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