Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp143814rdb; Thu, 1 Feb 2024 04:50:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfdVmP66x69IOHQftMzckwzvh4Y3cZWm/XQrpt3Hb1RS0rT26Rx2hBdkq91miS5DZi334w X-Received: by 2002:a17:902:8f87:b0:1d8:ee41:a825 with SMTP id z7-20020a1709028f8700b001d8ee41a825mr4118409plo.37.1706791816119; Thu, 01 Feb 2024 04:50:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706791816; cv=pass; d=google.com; s=arc-20160816; b=B5/glW0VhkEqNs/oRvpNghkpIxelexmJMaRbo6tPbEeWWKx1V/2xojwUeS4VnoWOcf NpdckRUpWwGzEPSrgvRVTEIHVny/UuebwMijlbyx3qkS9EwKKOnllL2tjAa2GL2Gw9TF 0hSxwu+InDbyesqDnsi2jOFZBOwJZAKkcU4Li2sD7NAyCOjYWKLPdVQSsHbDOcQSvw1d J0hQZK4H901GG3/jQeIOlNlkTJpJS8xSwiaKhUrP/nJscyFevgh0R6WZhyWv9TwkD0ar pKlnXD0j8lywu9ps71gksVAr94gg4SccHtvxlIJ/J7PSy4EPaUsTJfn7T+ux4YfxsgMx sW+w== 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=bFD0hCjgmOX7as9myCokrwQ4uyjRL1ptOYOywZxf6nI=; b=qIVQtrvRTKdTDQbnZeEFf36eaSeC5DSnExh8sj2QdxvxzvCZpcfMttVCZjjGXb20qO mHR8UsiZU9pm2EpUWy7XH03rR0p7k0r8zW1M2BFgKcmYAUExhLJasizcVBfGN/4cRtJh 76HsZyOf2vu440kGZr6er6zLNudXfWwM+3GQQjEBYMSaD2L+FTIrd26dmgXmQDR7+8uV d+p1ggvAyHy35ihSXW9A1QaC71DusYydATe7903wYoPUiQu9YCZmV7VTT1XTwy8DwRBA 73MTuTPCH0ogNP07z9bY9dfm5pe+/edmnM5Qi3MoXa9yXF0H2UnO8iXSgfnabwqYuqz+ KvcA==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48156-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCU4yqZOxHoBoiBb8CEsoS/0pFAncWUovFEpLZjTRPHc6uPYfe29mqR932QBW/Vk/xitL9ZzpSsctBMU32XFg1RQL2wwZbuvs73ld0daiw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x1-20020a170902ec8100b001d8f093e563si7435143plg.390.2024.02.01.04.50.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 04:50:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48156-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48156-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id F3CED28CA94 for ; Thu, 1 Feb 2024 12:48:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF0EB5337C; Thu, 1 Feb 2024 12:47:47 +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 Content-Transfer-Encoding: 8bit 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/ 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; } -- 2.34.1