Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2804900pxp; Mon, 14 Mar 2022 05:25:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQhHuNaXxFo2Uh5i7U7eSCoissyO2DLSKP1g1eHt9JQgy8EftkUhXK4WUa4B5rmis1l+4R X-Received: by 2002:aa7:cad3:0:b0:410:b188:a49a with SMTP id l19-20020aa7cad3000000b00410b188a49amr20432856edt.416.1647260759475; Mon, 14 Mar 2022 05:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647260759; cv=none; d=google.com; s=arc-20160816; b=Smm1LtRECyszR0yod0l9BAMfL+OPAqTOvKKbn/0sKMwqIgvlZZA2xD3IfqwAxrd71w xAfI1HziECqKB+3v53Kc+LMUX5j6ReamTnafy0dF84vLidwpwNW+e3f3tDr93a7IvexM wEcYGxajTT+kv2Y3zEC8OvL5NcHTW0jslcLDyi7pbmdLRaaUOlrxk6DLWYauOpy6I+z6 ptD6Sl6XdFeff5TugoHB9oQ0zFdp0+aHSPTqiJY0ZOeXwTXpvkpZZ2TJBI9/I9xRhWfg AqtwH0T6Q1Rm+cd1yCKKAmGbDrJSfYqfMyb+pSDq+gZUpBCkvNS3+suoq2Ieplo9zpIo //dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iANq7fz14fwMafBRVkj8cvHk/7L5YjX0PkBrCHsQekk=; b=ch1V6gwx4XluF9dhj60GkVTtUzgjIMDtCf3DIyqVG0DHrshzqcS9ezx0Z5lNUeUqcw PbKuvCgkG2X1aiYcbaQ0GrTQ1uXllEkN143HyrbpnbRAP27zFQ+qEdR0IO3HFNA2Slbq E2MgTGfrcTuQZYLM8Nj4MnUWh1QjlX9YqIGEDKwa10yAU3Vp5vkg9u/dATGBzS10z5YP RYdy/948xh/FLXGb6olg1NXkbyV+Qy+Z8YhxY2UI67BBjmAAn/Kyo9GOTbb6I6m5Uquf CrjEDP+evRP/5uEIqpZ1ELZ2hje1Om7epITUL3LzkbEdFMPMrwl8ytFk79kO+1M0UVQt jCLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dddfGeyK; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga37-20020a1709070c2500b006daab5ee77dsi9959180ejc.727.2022.03.14.05.25.33; Mon, 14 Mar 2022 05:25:59 -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=@kernel.org header.s=k20201202 header.b=dddfGeyK; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235442AbiCMTIc (ORCPT + 99 others); Sun, 13 Mar 2022 15:08:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233757AbiCMTI3 (ORCPT ); Sun, 13 Mar 2022 15:08:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DABC865D1B; Sun, 13 Mar 2022 12:07:01 -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 E3BBF6125C; Sun, 13 Mar 2022 19:07:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8E59C340E8; Sun, 13 Mar 2022 19:06:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647198420; bh=sdT+tHxbpYLBX3wIqLLmHW1cCkkTCSKzp6egI0tq5QM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dddfGeyKDX4YZCkNYRtOsdXo//j74r/YpjNSJGuciz2bb19+4Wniy7YCjDE6ApY7n s7lYbyem8qKoRgxfEHjI9pdevgTzSHPArrnuSbrzVbLSiVt6Nd5bPUVYl2Fo4+zmDc OLySDj90EPsuKqcvSEJ+9ZgPI9SmJUGrI0Wvh+DqgP6grWZ0ILkLO8EvyryCF/s15U CFTcMWDHbrNpSo71I3T8JUlyzwAjN464MfcoYXewQWsbF91WGQ66JXCrrhtCYBMK8d ObmjjaRw+TjUEthmDAfPqAKsRZosSo9WvEhvFqlaCsEjPhOGBs4mPiQRKVDbv2d/CQ A3fEcpCBD4/4Q== Date: Sun, 13 Mar 2022 21:06:56 +0200 From: Leon Romanovsky To: Yongzhi Liu Cc: jgg@ziepe.ca, yishaih@mellanox.com, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, fuyq@stu.pku.edu.cn Subject: Re: [PATCH] RDMA/mlx5: Fix memory leak Message-ID: References: <1647018361-18266-1-git-send-email-lyz_cs@pku.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1647018361-18266-1-git-send-email-lyz_cs@pku.edu.cn> X-Spam-Status: No, score=-8.6 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 On Fri, Mar 11, 2022 at 09:06:01AM -0800, Yongzhi Liu wrote: > [why] > xa_insert is failed, so caller of subscribe_event_xa_alloc > cannot call other function to free obj_event. Therefore, > Resource release is needed on the error handling path to > prevent memory leak. > > [how] > Fix this by adding kfree on the error handling path. > > Fixes: 7597385 ("IB/mlx5: Enable subscription for device events over DEVX") > > Signed-off-by: Yongzhi Liu > --- > drivers/infiniband/hw/mlx5/devx.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) The change itself is correct one, but commit message needs to be improved. Something like that: ------------------------------------------------------------------ [PATCH] RDMA/mlx5: Fix memory leak in error subscribe event routine In case second xa_insert() fails, the obj_event is not released. Fix the error unwind flow to free that memory to avoid memory leak. Fixes: 7597385 ("IB/mlx5: Enable subscription for device events over DEVX") Signed-off-by: Yongzhi Liu ------------------------------------------------------------------- > > diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c > index 08b7f6b..15c0884 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.7.4 >