From patchwork Thu Feb 1 12:47:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhipeng Lu X-Patchwork-Id: 195303 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp123175dyb; Thu, 1 Feb 2024 04:48:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmbmxjg+IcCE/aToXSax/ilwnLmHhnmFWu2CTdgkiOBZIJMx1kMEDnA3eKjXPKkipD4sY5 X-Received: by 2002:aa7:d394:0:b0:55e:d728:eaa6 with SMTP id x20-20020aa7d394000000b0055ed728eaa6mr6759730edq.19.1706791707402; Thu, 01 Feb 2024 04:48:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706791707; cv=pass; d=google.com; s=arc-20160816; b=TUAOVNcqRqX+BnmV6rLf1pGImqsIC752FqKQBAJmjnv+d/YY9QGKfd7uUwBOYsxayw vTYCkwsPo7Ywn0BgzS3s7AO46fCvyl7SvEAhTykTGGohbDTq0bHy4EMPdErsIecQi8T9 vZSJsYS+j2YjskPjQq36D+3EyLv88D6/lWGbVfuoWm++3ekAJzjMwaNIWs37J2I4doLI b/clpb35yeOcVoXzoTrGa16pzOP48qdqHF0VBLP6qPpE/DMhE7CVv32/n84mT5PyVnvA d6oQbtG5SHMjq5s/UYnRvW1XpUXV0VZHKrFNOXbLRXZTjMidQx5REIx3P1w9cQtj+azh FUJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=5p12d+WWwhgAMIJ6zbpJu9YzxHxR9E0Mig5qR0UJrV8=; fh=zgLt8OebT6xHYMAdoSBvYDHZKqvA6WxaMLfNPLrXb/A=; b=J/fwU4tahChmPtYj8DErpBYNaOqTvdH/fbdpDb7RGpt90qQIMzQ78Gy8qgVQhrJ8AC WczN8QXiRrmPZw8PEU13ewwaGh0Rs4eNueSb8U4sQCeOyg88EWknG5zMXhxae7u9481M PTbABmX6z6fifJLR0l/TMbP+sbkczclnvtqLiMVI4Hk+L3FczQwHJK6xt/YUSJ6uJ1VS OFxVzvStBmmfvukbaQ/7GLmI3vQn9jC8ZT+tWl9Md9HAb+fJi0fStCG15nXmCvNMLsw/ cge7kwJpaggQu5NXu4Vi5D0LiSYKlV3nKuceEPnfGid4sBkj0i1tFX5smlWczoJLa7h9 MtKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-48156-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48156-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVSdj8JA0iSI0TZl0X0ADlAZiYc+B/ftDMzw8jQKwyqw1mbZNETc254YLfp2ukg77uM+zSNT2vaP9GjbJT7BYwI+Um73w== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u26-20020aa7db9a000000b0055c9c70f91esi6606626edt.182.2024.02.01.04.48.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 04:48:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48156-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-48156-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48156-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 098781F27EC6 for ; Thu, 1 Feb 2024 12:48:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 065B253395; Thu, 1 Feb 2024 12:47:49 +0000 (UTC) Received: from zg8tndyumtaxlji0oc4xnzya.icoremail.net (zg8tndyumtaxlji0oc4xnzya.icoremail.net [46.101.248.176]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E891653363; Thu, 1 Feb 2024 12:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.101.248.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706791667; cv=none; b=gNfdw6XBTUXSui+tZs4vzNCUcXeXp17bQ5uIcsg8bNYkWCIbFPUMh+NT5ITBtYIiCZOBqDuWE2YMPDddZuelxq/OaoorxSJf+HQGKk0V5pQYL9ZqmP8R64aKOJzEr7P2loCz7y6vDzXhIDuCcxoi7BRG61jEgCqOEEhK2kov8yk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706791667; c=relaxed/simple; bh=WK8ow8z0KhSe3WrYq5ZZUDwAfiid7skMNsxiDeRPrsw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Y70l80SzWVeGLI+60EeMej89VudRdyfKXq11d01yX4Oz/762K0BLjPMha/QsTud77fxxeVW/UGtzsk/Ge9dpxQdAprVyhjhlTMykNj5oaN8GcEa7xUMR9uGioJp11StVOc/oQncm32NctJCwq5H+YWfRYbjcIk8tpU4+oY5yvVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn; spf=pass smtp.mailfrom=zju.edu.cn; arc=none smtp.client-ip=46.101.248.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zju.edu.cn Received: from luzhipeng.223.5.5.5 (unknown [183.128.135.43]) by mail-app2 (Coremail) with SMTP id by_KCgDHCanWkrtl4sUxAQ--.60206S2; Thu, 01 Feb 2024 20:47:19 +0800 (CST) From: Zhipeng Lu To: alexious@zju.edu.cn Cc: Sunil Goutham , Geetha sowjanya , Subbaraya Sundeep , hariprasad , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesse Brandeburg , Richard Cochran , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] octeontx2-pf: Fix a memleak otx2_sq_init Date: Thu, 1 Feb 2024 20:47:13 +0800 Message-Id: <20240201124714.3053525-1-alexious@zju.edu.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: by_KCgDHCanWkrtl4sUxAQ--.60206S2 X-Coremail-Antispam: 1UD129KBjvJXoWxJr13Kw17KF1rJF45Gr18Grg_yoW8Gr4fpa 1FkryxJF90yr13XwnrXF1rZwn8Kan7ta4xKFy7CwnagwnYvwn5A3sYyFWSgr1fGrZ7uas0 yFWqyFWrCFn5Xw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9E14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2 Y2ka0xkIwI1lc7CjxVAaw2AFwI0_Jw0_GFylc2xSY4AK67AK6ryUMxAIw28IcxkI7VAKI4 8JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xv wVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjx v20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20E Y4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267 AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbbo7tUUUUU== X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789700821287709771 X-GMAIL-MSGID: 1789700821287709771 When qmem_alloc and pfvf->hw_ops->sq_aq_init fails, sq->sg should be freed to prevent memleak. Fixes: c9c12d339d93 ("octeontx2-pf: Add support for PTP clock") Signed-off-by: Zhipeng Lu --- .../ethernet/marvell/octeontx2/nic/otx2_common.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c index 7ca6941ea0b9..02d0b707aea5 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c @@ -951,8 +951,11 @@ int otx2_sq_init(struct otx2_nic *pfvf, u16 qidx, u16 sqb_aura) if (pfvf->ptp && qidx < pfvf->hw.tx_queues) { err = qmem_alloc(pfvf->dev, &sq->timestamps, qset->sqe_cnt, sizeof(*sq->timestamps)); - if (err) + if (err) { + kfree(sq->sg); + sq->sg = NULL; return err; + } } sq->head = 0; @@ -968,7 +971,14 @@ int otx2_sq_init(struct otx2_nic *pfvf, u16 qidx, u16 sqb_aura) sq->stats.bytes = 0; sq->stats.pkts = 0; - return pfvf->hw_ops->sq_aq_init(pfvf, qidx, sqb_aura); + err = pfvf->hw_ops->sq_aq_init(pfvf, qidx, sqb_aura); + if (err) { + kfree(sq->sg); + sq->sg = NULL; + return err; + } + + return 0; }