Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1064467pxb; Wed, 1 Sep 2021 16:38:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoqefYciIbnEZlt63tXBkfeEmcAJ4Macs/ILpXnlm2bzS/VwLP+AMBx6G4ud0JwekLfqwq X-Received: by 2002:a6b:5a1a:: with SMTP id o26mr320141iob.40.1630539524139; Wed, 01 Sep 2021 16:38:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1630539524; cv=pass; d=google.com; s=arc-20160816; b=u/Eo7WmPHBnTZLXBUBEp63ofRCIipvsLuXd3uusx9p+Bc3VTW6+90GcHnz7Zhvol/1 m92uQy8ncMoykx/Pl7c1GyEUIycg68L0ab47PkoIq9TQjOHhjSMdQY7LD9ltwnPpgaqy 881RiPH0JSXl74gAMdOX+teVsS5srMV520/4aSxGvWdn5LbtnNnGUNhesVDLY5VSZ9Ml /QbQu5fSRaireRqEQvAub8Eku+68WZYIpmkC28GLgCM/vl3gfB0IhJQv4d9DsQIH/3WE l4AzxfgA7HFdlusIk0qxhOYVfg70gVhvGi9LS5WpnssCzxFbjc9MF4nceF6epZgRQZny c5iA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rQPJ05F5JebNF2FJ90pWZCThDfbAb9Db0DUCkr+NfEE=; b=P3/5B9TxoX9f+V5k+D3tRCMGjHfOKEdUbewUSkaOneyf1K7eg8DREgSOH7dVF63Syf lbuxSA7mM7CPPeLbEXCb9nS/QhYUf7rhzmQ0X6pB1XQkd0oZH2GweR6HqcXArWp9F2QC kFQQRAY0RWhVVeQqP+ZpBuyrzoxl0ZDgQvhQQ3JKJCVLvXbhQJjxCqbaeyXAmCUu7VaS FHktVmyOu54yil7Kh7DB2xz8q9DL2Cf5UB/Kgbj9XJRmH1VOqx1vmsDbKXPNBh97ooMw gPr4dbPyLKTBUDppObSbQ+JHth6GPRIaPFclevla/gDCAl3dqI6BUK+F2QKyXFJBxkYQ JEcg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=MgsGqnQ7; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x13si290061ilu.41.2021.09.01.16.38.32; Wed, 01 Sep 2021 16:38:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=MgsGqnQ7; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344561AbhIAWwe (ORCPT + 99 others); Wed, 1 Sep 2021 18:52:34 -0400 Received: from mail-eopbgr00087.outbound.protection.outlook.com ([40.107.0.87]:32899 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S243383AbhIAWwM (ORCPT ); Wed, 1 Sep 2021 18:52:12 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QWKL7dsEvX6Zp0M10hrOz8tMNWtDcZL+Bdgemh+j+X6vSUFVEOnYtuWxs9Y8r40UIU/35qt8w275z52JkeIao0tZyAkqmCX5ClQ8onqdIdPZDE2DM8p2AN1ssVmQ9s0vkaMLiop01VcDiveYoNHQ9Mdha1E94kTvOMhixfsM4280RHokqGSJCFlq3e1eIMqKDostGSzEq1P7ZiAep8QLrtGW3r/RobzOqx7JnrdN6CLLYga/CCnVIrapqFdfwp6MCDvxQM0bH5DZDALENK8/62kJmDNJGUhSQDuJxiM/rXUS/r5UobVulXrmAx+6/eYO0G9qwBQKH14iMku+CyDeIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=rQPJ05F5JebNF2FJ90pWZCThDfbAb9Db0DUCkr+NfEE=; b=YjxF78oXhVjot6uo/ApV/SySkrPHDFNvREE2BcyUNYANm8+3Sn3o6k+Np1+aCG9cL6zeg0EnPNICjb038s9HD8ZSmLFiRUWltfg8a04BbEdn/jeI+eoecS6Zp+XwK/OyZuZ1xJJPU9VPjD0p5xpXoPn2H9UwTlbR2flRw0peyfMPm6CjUz8a3TP+HcJotLxEzV9bBIjSIbfXP0prHhK0+xQ7uOpS7tma640+1oHivdRHJ5Dn7j3gAUkPBv4am6pyzJm1j+e6jYPH0gxYMPqJxZXTz775WJRpaZmhnHLjVzm1XDh2xKIOJRf8YEOMq8H2rIcUs6QyPHnYuj/siAYS+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rQPJ05F5JebNF2FJ90pWZCThDfbAb9Db0DUCkr+NfEE=; b=MgsGqnQ7fYjWbkc1UMDVUHuUe4zdB6glvhdL5ifXKfF9cptjN5yK87lYLa6IC0rR/Fw0OMl9yBlR1ueWcYPoVBmRqUVYg98wN66pApetREcQJWhw5YVC+ochoSngdvVboy5JgVwkh+cxBNuaoCe6+QxS+Fl2JpzAkYRGOqLEj5U= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6015.eurprd04.prod.outlook.com (2603:10a6:803:d8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Wed, 1 Sep 2021 22:51:08 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0%2]) with mapi id 15.20.4457.026; Wed, 1 Sep 2021 22:51:08 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Jakub Kicinski , Vivien Didelot , Florian Fainelli , Vladimir Oltean , linux-kernel@vger.kernel.org, Linus Walleij , =?UTF-8?q?Alvin=20=C5=A0ipraga?= , ACPI Devel Maling List , kernel-team , Len Brown Subject: [RFC PATCH net-next 2/3] net: dsa: destroy the phylink instance on any error in dsa_slave_phy_setup Date: Thu, 2 Sep 2021 01:50:52 +0300 Message-Id: <20210901225053.1205571-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210901225053.1205571-1-vladimir.oltean@nxp.com> References: <20210901225053.1205571-1-vladimir.oltean@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: AM3PR04CA0130.eurprd04.prod.outlook.com (2603:10a6:207::14) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.78.148.104) by AM3PR04CA0130.eurprd04.prod.outlook.com (2603:10a6:207::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Wed, 1 Sep 2021 22:51:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a11dfae5-39f6-409a-532d-08d96d9afcc7 X-MS-TrafficTypeDiagnostic: VI1PR04MB6015: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ya59+eQTQFNz35vpDQOiEIf69UH6vtcvoqd+F2xM2wlfsijjpQ+CuTw5iK5LHuFXP6smEwSZgNh7xTquZMdAPKicHfEWCrKuK/voTLfm3Cc0YobNDBmc9tt7FqLTKYmaBSbju9YiqZae2z14qr0mEuLCsykEpsrMk3JOp69MB8QYSrjVbqwu7H69c+jYB+QkN4DWNUE0MmZAOitUErz9eYG2k37j+9VPNChF05tGEqXaWiENVfAHSc3YSuLkU1AhH1dlv7hjpMokJHBLG2N8GEvS9aKvnArF157A2lRopP5Bazss+RzX+GhPGW9rV0SmD2Y932aKMJSExggLo6N5Dt+R9IwLDMwETBhdwATlIMQ22hUNfSIxDYjdKdfqvH0ocbB+0Wm/x90qvi5+8KVW/GGk97KzVK4ytTFMUvLwkuMN5EJcBBceLMKpvbmIs8tatw4C8ha5Sir2EMgtR44o5DvrgrIiIn0u3PuIlGHS2EZImsUb+ERokP9r2/j0JlDj+ugccBirOQYfFjfvJwuuBBp1M9a8BUz/3xcsFWSyqHEEuszBR6k+0Y91wUcYcZJuWitpnuI2uqqsJrrcz8f3gsQ0ftP5VI1R0GRtNdvvwT/YTDxbRplVSCOlqEORiPcINEMvQ47rplhyCcf5X/1inlJ5qN3RRAijuSijrxTqSkorV1rLRP7rsADsmD84huwbHYwnaI5AhS+YtpW6w98jMw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5136.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(136003)(396003)(39860400002)(376002)(346002)(66556008)(66476007)(83380400001)(186003)(8936002)(66946007)(26005)(6506007)(52116002)(316002)(36756003)(478600001)(5660300002)(6916009)(2906002)(7416002)(4326008)(6666004)(956004)(86362001)(2616005)(6486002)(6512007)(44832011)(1076003)(38100700002)(54906003)(8676002)(38350700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?jk+3qOdtAEXLgWCrqGPlMhnJb0X1yoxbl0aXqUDOJI2QT4F4CZf4S5Bq9vdQ?= =?us-ascii?Q?K7y2Be3XPmkySx1kYAncb6R/dxO74iyEOYVL4U3JCKNw41Sz2p0gQW5Ivoxv?= =?us-ascii?Q?kUOqHxRFO90JE6Wy69NV8DtzZmdRPjXjWh4YPrk7xwWAEdPkUyupxEyUiYA+?= =?us-ascii?Q?1rTg8Y8WhThCu2deqmc+5k9pjlrI9CYnZVoUf4NTNXO9iLUzMEiGDvaX/fE5?= =?us-ascii?Q?x2JENUTo9KQJ7Q7377PZscfe0kzB9P6QY8LYhRfNyMdfT2oWr7+mYXA1kmx4?= =?us-ascii?Q?2ZNkMJU7Bi/dvJF77oerxFdz4HpavWeXKgODrMrJZTUpFXfHOkjNLSqonZO4?= =?us-ascii?Q?yyUNfRdDeJAhn2LIgBl/mhLpFeWwX3+LuIAHk4wZVMqYK39CFo25jxXKDNty?= =?us-ascii?Q?Mqrpa7OXkNvqUdAwgriOghlN+RkNFDd0UK9C1NhIqS+qLcatlc4890lc6NtO?= =?us-ascii?Q?nEHR/Ki07sVaT5T4JLS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p.com X-MS-Exchange-CrossTenant-Network-Message-Id: a11dfae5-39f6-409a-532d-08d96d9afcc7 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2021 22:51:08.4637 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Fx4m0dAXCAAVqG6t/qRr/uQUkCwjU3BpgqBUmIsEchETGsteqQ1yeRFGTZHkdMZ0NDmP2lU4Rbn8wEAk1LeGjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6015 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org DSA supports connecting to a phy-handle, and has a fallback to a non-OF based method of connecting to an internal PHY on the switch's own MDIO bus, if no phy-handle and no fixed-link nodes were present. The -ENODEV error code from the first attempt (phylink_of_phy_connect) is what triggers the second attempt (phylink_connect_phy). However, when the first attempt returns a different error code than -ENODEV, this results in an unbalance of calls to phylink_create and phylink_destroy by the time we exit the function. The phylink instance has leaked. There are many other error codes that can be returned by phylink_of_phy_connect. For example, phylink_validate returns -EINVAL. So this is a practical issue too. Fixes: aab9c4067d23 ("net: dsa: Plug in PHYLINK support") Signed-off-by: Vladimir Oltean --- I know, I will send this bug fix to "net" too, this is provided just for testing purposes, and for the completeness of the patch set. net/dsa/slave.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/net/dsa/slave.c b/net/dsa/slave.c index a7a114b9cb77..8a395290267c 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -1856,13 +1856,11 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev) * use the switch internal MDIO bus instead */ ret = dsa_slave_phy_connect(slave_dev, dp->index, phy_flags); - if (ret) { - netdev_err(slave_dev, - "failed to connect to port %d: %d\n", - dp->index, ret); - phylink_destroy(dp->pl); - return ret; - } + } + if (ret) { + netdev_err(slave_dev, "failed to connect to PHY: %pe\n", + ERR_PTR(ret)); + phylink_destroy(dp->pl); } return ret; -- 2.25.1