Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2387608ioo; Sat, 28 May 2022 12:04:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYuOIJSTaY/AM9NjDesT2vijjdRWcboZGqf22BTJPn8869XAAL7voKUr2uNxnK1Kp5sw9O X-Received: by 2002:a17:903:2c7:b0:158:2f26:6016 with SMTP id s7-20020a17090302c700b001582f266016mr49032356plk.154.1653764659042; Sat, 28 May 2022 12:04:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653764659; cv=none; d=google.com; s=arc-20160816; b=UR3ByAmXIAfJT89KlHB3h5Dl1q1zHWzKAzcu6bS4PtAN/CAPdHcZ2VtN4usUnB3dgR I/es6VDzNiBqW/gnWvTYEC+nYgwyJnrfi8q7hfuZdMrLj043aquQM5QyvUupSGtPd4rg CCJak4Pc6zIw8T8qBZZR3nPGmnzUJO1n9bRksgkr28xlo23l2YFJweQAOZsTSzddfhR4 +YBfy0ZXA01P6A/8SPBFKGDGrAnSjaFnjs2QBJ6RfXQHEc/k3uESNOk8eO4b50cTP+Fz CURgUeE6R8xiiAo2A/y89SSLozyhLJ0ZWbalhyxXAaSRAHA1lD8/BtT/mXeKShu4kIhf GM/g== 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:date:cc:to:from:subject :message-id:dkim-signature; bh=u7bQhPKpC/2vv3TSdrZRb3hAgeC4UybLeZufoqxQdtY=; b=XYr83X6EYHc8THz3PonfXE8PM8E58KZvPBR4vBFkMraiyaK2HA3ZL5xcLSOMQ1q0H6 wLVMtSH4sevq6JXa+yk2R7/iSUvRfPl2sVRotpqQ2yrxNSI7RhN7Ve3obQJKDW2HHdGT 9GtmmCcKH7EsfVHPRRVGHwuRwdm2W/L223CB9Dagk0mN987Y/9ETUilWqfmZWjLEs7cU RPandNe6FbNHdHvb+oViG3Mq4bLuVJXfOHVC64C1fQtvMrLlaud9MbNVtk/ALIbqfjxO 3HX4ZwPqKLn4bjtf1tEiXNi8+SPhFD9B/55Az0TBu9nUSRi22CBcRIKVvIzTUMcZW4vn JjnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UEXWgvAn; 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=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id lw5-20020a17090b180500b001e2818ea430si7022581pjb.86.2022.05.28.12.04.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 12:04:19 -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=@redhat.com header.s=mimecast20190719 header.b=UEXWgvAn; 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=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 29DB53DA42; Sat, 28 May 2022 11:45:23 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232541AbiEZLOb (ORCPT + 99 others); Thu, 26 May 2022 07:14:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233141AbiEZLO0 (ORCPT ); Thu, 26 May 2022 07:14:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 478A2CFE15 for ; Thu, 26 May 2022 04:14:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653563664; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u7bQhPKpC/2vv3TSdrZRb3hAgeC4UybLeZufoqxQdtY=; b=UEXWgvAnOtaA7NzSm+S/LYkgDr3iFOtUi+tI6SUaXSvteRhsGP2tV/yLIJ2mm7Ik/Ky4B6 BrXojNCeWUPqC6WjNYrha2xp5Z9cvdYnyuLH1zU0AMgf5j+Ps+d+CAgAxkzyrebTvTOLPL 3bPj2+LcWu8CrsBOherIeor6v4jjbzA= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-435-Q1-qyA04MbWw1Q4pvuHiig-1; Thu, 26 May 2022 07:14:23 -0400 X-MC-Unique: Q1-qyA04MbWw1Q4pvuHiig-1 Received: by mail-wm1-f71.google.com with SMTP id o3-20020a05600c510300b0039743540ac7so760910wms.5 for ; Thu, 26 May 2022 04:14:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=u7bQhPKpC/2vv3TSdrZRb3hAgeC4UybLeZufoqxQdtY=; b=VAlLZFfnqbPodcjY/KUPC2VmmYOCJHGMZN/qz1Qy2BWXsEONuOOOBZfZCRZKq847VB 7rNrtMZa/vTqX/jfodknGDMQSqrDGtrk3lgJKK+hQ1RW5+91oNAedLIf23giu1QGDPxj It06nm76tUTlB4VlAIHLzdK13cxFrm3/06yuAqY3HNzpiYTD5ZqWB1kmBTbmoLZPOQJa W0eJ8/yjX8rSfmqCf5tB4BbnuR5nin7gmHchwcLzzPIdGwfeaVyTzl57h56RRdf4gjKd 4ig4X+nesjhIB+k0Yt1WvuBqlzgOfTCtvMmgJdb7WGL+gLcQyTNQHF3zmpYZbUeNGS0D KrBg== X-Gm-Message-State: AOAM531hB6gkvopGLvQTNj+cbDKmPCCt8MUoW0Jq+2mqJPVc9QHd/Ji7 Nwlo8/7gLil1BPsUVPt4WPZq17fiP6k8EuG414t0LmxGosC8znpcSpaeVF/5SvQFIpMnMYqjAq2 kRYK++PticyX23sxyuBQ4zoZl X-Received: by 2002:a5d:64cc:0:b0:20f:e6d6:72e1 with SMTP id f12-20020a5d64cc000000b0020fe6d672e1mr14022752wri.384.1653563661994; Thu, 26 May 2022 04:14:21 -0700 (PDT) X-Received: by 2002:a5d:64cc:0:b0:20f:e6d6:72e1 with SMTP id f12-20020a5d64cc000000b0020fe6d672e1mr14022727wri.384.1653563661736; Thu, 26 May 2022 04:14:21 -0700 (PDT) Received: from gerbillo.redhat.com (146-241-112-184.dyn.eolo.it. [146.241.112.184]) by smtp.gmail.com with ESMTPSA id h131-20020a1c2189000000b00394708a3d7dsm4730095wmh.15.2022.05.26.04.14.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 04:14:21 -0700 (PDT) Message-ID: <5a7cb5c7c0bf2f9f9540616a2a0e70d36a166a9f.camel@redhat.com> Subject: Re: [PATCH] net/mlx5: Fix memory leak in mlx5_sf_dev_add() From: Paolo Abeni To: Jianglei Nie , saeedm@nvidia.com, leon@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, parav@nvidia.com, vuhuong@nvidia.com, shayd@nvidia.com Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 26 May 2022 13:14:20 +0200 In-Reply-To: <20220526084411.480472-1-niejianglei2021@163.com> References: <20220526084411.480472-1-niejianglei2021@163.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 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=unavailable 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 Thu, 2022-05-26 at 16:44 +0800, Jianglei Nie wrote: > The variable id is allocated by mlx5_adev_idx_alloc(). When some error > happens, the id should be freed by mlx5_adev_idx_free().But when > auxiliary_device_add() and xa_insert() fail, the id is not freed,which > will lead to a potential memory leak. > > We can fix it by calling mlx5_sf_dev_add() when auxiliary_device_add() > and xa_insert() fail. > > Signed-off-by: Jianglei Nie > --- > drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c > index 7da012ff0d41..9f222061a1c0 100644 > --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c > +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c > @@ -125,13 +125,16 @@ static void mlx5_sf_dev_add(struct mlx5_core_dev *dev, u16 sf_index, u16 fn_id, > > err = auxiliary_device_add(&sf_dev->adev); > if (err) { > + mlx5_adev_idx_free(id); > put_device(&sf_dev->adev.dev); This looks not correct. put_device() -> mlx5_sf_dev_release() -> should already take care of that. > goto add_err; > } > > err = xa_insert(&table->devices, sf_index, sf_dev, GFP_KERNEL); > - if (err) > + if (err) { > + mlx5_adev_idx_free(id); > goto xa_err; > + } > return; > > xa_err: