From patchwork Wed Sep 1 22:50:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 505453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE2B3C4320A for ; Wed, 1 Sep 2021 22:51:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D40D96109E for ; Wed, 1 Sep 2021 22:51:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236906AbhIAWwe (ORCPT ); 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_=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> 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: jk+3qOdtAEXLgWCrqGPlMhnJb0X1yoxbl0aXqUDOJI2QT4F4CZf4S5Bq9vdQK7y2Be3XPmkySx1kYAncb6R/dxO74iyEOYVL4U3JCKNw41Sz2p0gQW5IvoxvkUOqHxRFO90JE6Wy69NV8DtzZmdRPjXjWh4YPrk7xwWAEdPkUyupxEyUiYA+1rTg8Y8WhThCu2deqmc+5k9pjlrI9CYnZVoUf4NTNXO9iLUzMEiGDvaX/fE5x2JENUTo9KQJ7Q7377PZscfe0kzB9P6QY8LYhRfNyMdfT2oWr7+mYXA1kmx42ZNkMJU7Bi/dvJF77oerxFdz4HpavWeXKgODrMrJZTUpFXfHOkjNLSqonZO4yyUNfRdDeJAhn2LIgBl/mhLpFeWwX3+LuIAHk4wZVMqYK39CFo25jxXKDNtyMqrpa7OXkNvqUdAwgriOghlN+RkNFDd0UK9C1NhIqS+qLcatlc4890lc6NtOnEHR/Ki07sVaT5T4JLSu7V3ZMkuW+ZEn4PJByT2Wlk+GTleUjTuCHZoagPrOPOuOH/H2TE2Ydjv1MzoZM+fESHDXuZpPQAlVernloEQ0GixJDqsY30+nYiZPnr0JHkc7mjVjflNx71MK+z43/0/eoGnZqyaJzsg9TmHoaGmzhYC+d2Jxt/cbQf5Xf13RlT1wHGR2EkSDuZK3HJsrik4Z/xMxYomQWxpIk3ZNo8IZOgEBNV/Z5KUUXkuNsimbB0gZrITtKMZzKwCAYo9BX+sbQWjfLnqRlo1dtXNE1WBsx0f97m4Y7yduiRl0HSAuGM08CpEDIagOC73XIJlQRmlzg0FoxGTti9oRM526NQfPKb/XGZhaEd9XlyPfHS5Iy+y0sN04+dUIQ0HFZ/wQq7XtkxFxyzB7CUkZPWpJyeu5HnIGJClF5rSrq3sEi5SWpVoLJCRbuwV5Dv/Iv3YNIceR5/Yu8PJNR6UNaK9cxhpLgv+5qdZx7I675MwvDXvbNSyVxuIpvNuWeVl2kWNUFSkyx7LrUfFPuIuJHzV3GeLM6is/y/ImtRtnTnQ2yHk0pyZFHc6FLzv3Z/Zu8DUG+ZfW5fJATFLjtnzDQPJ17oHXkBGyeSqjCsI7tjVwfb0K5fHoy52lcC6xOdU3FPXfUzfNyNSQLsjb2HFA6nVwet0JxxjJE+Qkj+rvGt+k4LYGjcUpLA3KQja3Ew6ldoccAraFXz3Rfty2HTzl9gVkRtCcIilAldUGU2l07OG4bqiIG9ur6HiJFAjYhrPrPLitNu9hlFpqIAw9o/qXBiYXVw6m6/2lOGVcgoLBOveEUPMuKiMwOXniD4feo6OCOWIdPsgxXznP98DT/hVC X-OriginatorOrg: nxp.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: netdev@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 Reviewed-by: Russell King (Oracle) Reviewed-by: Florian Fainelli --- 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;