From patchwork Tue Sep 3 11:48:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gui-Dong Han X-Patchwork-Id: 13788589 X-Patchwork-Delegate: kuba@kernel.org Received: from AUS01-SY4-obe.outbound.protection.outlook.com (mail-sy4aus01olkn2089.outbound.protection.outlook.com [40.92.62.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7322A1B985C; Tue, 3 Sep 2024 11:57:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.62.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725364632; cv=fail; b=YPwp+eFM1i4ThPzccgFzREceniEI1A8zGwK5PBdXAH8krKZw0FYUaRlyJpqfeWoFgmMk9QtyvkTeCxV6YKV0Cp966HxrsbQ8mr7idDWMJm2cmVq5Y5ABPU/wZF/sF/eTXFRQS/UI4XQe7TY2j45x/3r7hi7Szylp4jtZss0y7Cc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725364632; c=relaxed/simple; bh=J7x1vNt677krId5ZDxG083B5ezJV6CTh06Rsi4xMl20=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=oZapEa/8NwTMuIjzx5CoYRWqJS763EsHxTu7vCbjo7Qyt+XwsmOuqtRCL6P3/K0A4eYAjz3L7YV/aIsIbcVJou5njqTaO6IjEWDY524fU1mZc2I2TDuMEZQBheuVtvq+uB/YiaGuYG+reOgiizX2grTQz0toiWzHx6EObUPXEfA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=nlNiOrjK; arc=fail smtp.client-ip=40.92.62.89 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="nlNiOrjK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XZQErrTsHB4V+cWYOIiEtej8J9G6lwjYI2dw/97OAgy/nV8FHmjAkdBI/gbbc3xhmZ/L93EsGw//0VJcW9izu+LVEcF5SDa8IBNuk4gktqpEzUKly/2xAk4z8f1jl+xz9yPe+4h8cp8hdFnm306QVLzu1ofAEUaXMunmFEt5q98yHsPp1+omXSMfzZO90rDrXbTKPYT6+rucxPifzjfHVXPJrWQj/c/yl5+q83jBlSkO1ja1bWjPG9wNxffiBj6tobKTTZY5Rpm1fNEg/XRLFSvCdq8lgQ9LCNahHe3KRNQ7fQD55jV0LeWp0dPFAzCwKTqdkR8MhZA+azzxqpP6YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=55vnlN5xTrxV4ec8h3zVzd6wB8MtlheSr2q7pHwhyic=; b=jxnkGxtksBqSc5cI1METQPx3wmoUBnYkOJ8wiaXXUkPX3425UaM24GIxlU5EC3pwDjZWK/RtCOLbmVauTDwSMDHQKr0yZwb4kgPodtF0J65J5JVwA6tL/fRzkXLhlt8aum/ghoTjMacwzpCvA7wXXbEg4zEJm9yj7ZRACg/w22sl6vQ8B0ZSOB2DQWZRyktF+Dxk5cbZNn3ge2RE69o9/9alY8MZCtcwILFrpqj+J9h5Qmy+PrPbDFpUiYw1Qb57v+9DCTylNhI93IzIYT+wMjF8MBPJ85armcNxXF7Rl3ZnAsb/XRBBAcl0prcqXiaDSa3ssg9F4S5HAtOhf846uA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=55vnlN5xTrxV4ec8h3zVzd6wB8MtlheSr2q7pHwhyic=; b=nlNiOrjK6CNSIdpjhRxCZ2pjluw+BCE5Zf4xJA7exDx9jDHehYVFZ1a5p4Q7XX9Z2b6w67rlhLn9Z46kc2zjkUA6NLG3BUmdhhZenoOb68UqB8aemDLmwFerSzXKxT0DUnX3Rwl7NocrFAkk+fjRIFmMFF9CXZUWC+oqIlFvnWKXgffOv3GsUTmECtKUp3MBvT3mg+2pfxCjUHGPqya3RrfWxIVjJS+1c9/jqdr+RJAKBVvVxFarllO4zeh/wsgMKM7CaQe4DS5MqqOg80K3AhSZiZBtxCumDXE9NPyeCV42M16uAVAnbheUJcF0gx6hRyX1pesHPxFz4C9IGuFlcQ== Received: from SY8P300MB0460.AUSP300.PROD.OUTLOOK.COM (2603:10c6:10:297::10) by MEUP300MB0256.AUSP300.PROD.OUTLOOK.COM (2603:10c6:220:216::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Tue, 3 Sep 2024 11:57:05 +0000 Received: from SY8P300MB0460.AUSP300.PROD.OUTLOOK.COM ([fe80::14bc:d68f:122:f4f2]) by SY8P300MB0460.AUSP300.PROD.OUTLOOK.COM ([fe80::14bc:d68f:122:f4f2%4]) with mapi id 15.20.7918.024; Tue, 3 Sep 2024 11:57:05 +0000 From: Gui-Dong Han To: anthony.l.nguyen@intel.com, przemyslaw.kitszel@intel.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com, Gui-Dong Han , stable@vger.kernel.org Subject: [PATCH v2] ice: Fix improper handling of refcount in ice_dpll_init_rclk_pins() Date: Tue, 3 Sep 2024 11:48:43 +0000 Message-ID: X-Mailer: git-send-email 2.25.1 X-TMN: [3o1xJglmxZKxykxBQbm2mlpWo1X+pehM] X-ClientProxiedBy: SI2PR01CA0021.apcprd01.prod.exchangelabs.com (2603:1096:4:192::19) To SY8P300MB0460.AUSP300.PROD.OUTLOOK.COM (2603:10c6:10:297::10) X-Microsoft-Original-Message-ID: <20240903114843.7578-1-hanguidong02@outlook.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SY8P300MB0460:EE_|MEUP300MB0256:EE_ X-MS-Office365-Filtering-Correlation-Id: e291c51d-748a-44d8-325f-08dccc0f87a5 X-Microsoft-Antispam: BCL:0;ARA:14566002|461199028|15080799006|19110799003|8060799006|5072599009|440099028|3412199025|1710799026; X-Microsoft-Antispam-Message-Info: 1zPOhxWlQwZEbYK1TP1JSitQ3AaInWXdun/GGa2AL5OSwGP02BYWaN5VFsXmYdBoeOc6aAwqUOEvk2nwTX0Zs2w2uKc0fsx7AM+882VleF6bjeuCuMBYOJhmlb6iQDkwtQfAR3N6z5Y+SOrwucQET4ePGRnzjrOboSWiIlOKRO/jflqcD2F4yCTRiUaeLsI6LAMOfFVK92wyHHIVhYJMZnnahBvIu+zmcqYPEkebFBQtO5ea4hrv5fFxL057Evozm9d9c6JemU+npfUiZU4OznVjF5+JqUGWtVW2254RSJHt49sDNugmXUuGjE2NhprpKxwMuMlNC2ZkcI4ph4CcAef+8ytw27Uc4oVGxsliur3oGEtwu6nVhXCt9qmN4eNxFH2foUNU2T3+/aLvFEdOdi8W78m/IUyvUVh9I/+GiI/fqtbmEd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u5InEl3CshbgEpDD57FIp6HLqsiDWzFqF71YTAry9Cpyq6EgwMH9zjPRwz2X19U7PO/kMlmghVuAvqJsx3F/1DsRFODYrCMoGNcsMRgQTM4ypRK0L8P5IpO74cJ1TprKIvYIpTOW9zxvB7ULjJPc7I3eWKOO8uiXy4KCUBO4X0Gz+RnyP76ea56Vahw/hBfEP49Y0oofa5QwsbgxxPX1ZepdtCIWE4mrQM0H4QY/6rpqDBt7xQCt8YVwB4PtDCFbZ1yftep5v3x22iDeGYBpwJrEqrkpK2M8S2mGl3EOR1HjZEdYa3z0164VD/XhI3dDrcicipm4HqLzK205s3IdfzUvImEDDaUuGl2EA9Q1VQyWMKu7ob0S2b6ZrtSq+n6PajMGncAotA9Sl1xsImatn6U8wUNqWdDWQ7tBdguILL/nNs00SKxN7AF4K2VL6qY//36In/+XhJDpsLBOjjsI585pfzHBGALh6vcFSHIQSfFPkrXlacrabkHH71qFCO1onHKtrxAtyFlXYuU0F7b+TSVhOxZlUUFNAZ70D9rrI8qgUmfhR9VO/69WIqQ X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e291c51d-748a-44d8-325f-08dccc0f87a5 X-MS-Exchange-CrossTenant-AuthSource: SY8P300MB0460.AUSP300.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Sep 2024 11:57:05.4175 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MEUP300MB0256 X-Patchwork-Delegate: kuba@kernel.org This patch addresses a reference count handling issue in the ice_dpll_init_rclk_pins() function. The function calls ice_dpll_get_pins(), which increments the reference count of the relevant resources. However, if the condition WARN_ON((!vsi || !vsi->netdev)) is met, the function currently returns an error without properly releasing the resources acquired by ice_dpll_get_pins(), leading to a reference count leak. To resolve this, the check has been moved to the top of the function. This ensures that the function verifies the state before any resources are acquired, avoiding the need for additional resource management in the error path. This bug was identified by an experimental static analysis tool developed by our team. The tool specializes in analyzing reference count operations and detecting potential issues where resources are not properly managed. In this case, the tool flagged the missing release operation as a potential problem, which led to the development of this patch. Fixes: d7999f5ea64b ("ice: implement dpll interface to control cgu") Cc: stable@vger.kernel.org Signed-off-by: Gui-Dong Han Reviewed-by: Simon Horman Tested-by: Pucha Himasekhar Reddy (A Contingent worker at Intel) --- v2: * In this patch v2, the check for vsi and vsi->netdev has been moved to the top of the function to simplify error handling and avoid the need for resource unwinding. Thanks to Simon Horman for suggesting this improvement. --- drivers/net/ethernet/intel/ice/ice_dpll.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.c b/drivers/net/ethernet/intel/ice/ice_dpll.c index e92be6f130a3..b403d55303b8 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.c +++ b/drivers/net/ethernet/intel/ice/ice_dpll.c @@ -1626,6 +1626,8 @@ ice_dpll_init_rclk_pins(struct ice_pf *pf, struct ice_dpll_pin *pin, struct dpll_pin *parent; int ret, i; + if (WARN_ON((!vsi || !vsi->netdev))) + return -EINVAL; ret = ice_dpll_get_pins(pf, pin, start_idx, ICE_DPLL_RCLK_NUM_PER_PF, pf->dplls.clock_id); if (ret) @@ -1641,8 +1643,6 @@ ice_dpll_init_rclk_pins(struct ice_pf *pf, struct ice_dpll_pin *pin, if (ret) goto unregister_pins; } - if (WARN_ON((!vsi || !vsi->netdev))) - return -EINVAL; dpll_netdev_pin_set(vsi->netdev, pf->dplls.rclk.pin); return 0;