From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from szelinsky.de (szelinsky.de [85.214.127.56]) (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 29DB23E2764; Wed, 24 Jun 2026 20:40:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.214.127.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782333631; cv=none; b=H6aWGfh9ftznYxlZmoWF4ts/mbB4Vq+WW4+XaJ+Qz7bQMqlBW6K+qef3ZKcouMvzNpMIDOhrz9qGs+OYyBzJ+aRxAAqLECyRWte4xakpjIaCI+AI6FADfuv3B1TKwLUBhJ26Qie48YDiQ2+qJR32j6AaSBB/HdvYsS056PTA8Bc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782333631; c=relaxed/simple; bh=YLbMAwskt7L0WxpL5RKlc+2Uku1Pkzex9CfmRPGF/6M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=lPCtS46GdwQEoTUvf3pCPW/+yBLhxBFu16NUDbAkkItMUOuEv5p+dYIFJ+mUDJjOnQmLPM69i3PQeko3hZRQY1ggB564tBDJeZz//p54mZrvwx4Ex/dCnXKGzWyTW8MmcXb0528AIuRD6FxgSAkNfgIS4dZUYakFUbdw0CY3yIA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=szelinsky.de; spf=pass smtp.mailfrom=szelinsky.de; dkim=temperror (0-bit key) header.d=szelinsky.de header.i=@szelinsky.de header.b=jvL4gJfJ; arc=none smtp.client-ip=85.214.127.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=szelinsky.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=szelinsky.de Authentication-Results: smtp.subspace.kernel.org; dkim=temperror (0-bit key) header.d=szelinsky.de header.i=@szelinsky.de header.b="jvL4gJfJ" Received: from localhost (localhost [127.0.0.1]) by szelinsky.de (Postfix) with ESMTP id 8258AE830EC; Wed, 24 Jun 2026 22:40:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szelinsky.de; s=mail; t=1782333621; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Rggi+aPv19PS773gU4BgfR3PVwD8NpJEYnikVMMug58=; b=jvL4gJfJQgniwv8ngBrLO2TMYfS656/7H/McdZ9i92byj6mfSGlS4CtDazKlm6/liPiFQX 3pqgl0nyAduR9vqLxi/b9FQoYmzRof7bodSYAEDkfFdoYZbfolZfJD78/SrxIAsF5+q6xs T/QYw+RLeyyo9EE0D3quN91eVYHgyxUijxfnxkefKKK+7CRl16AA8obsHpXlv9Q/hzh8Ep CPSAJbfyAaKkX07LIrj05LD+nSWjkbeegDuGAvO/f2r0PeoMpXHCXotswqDvwvBnlN43x5 gMrug1k9i6Q93CCAegeHygSFvB6BxjmekuQwNdvUq3WTpqDiuZrPse6YFsAfXQ== X-Virus-Scanned: Debian amavis at szelinsky.de Received: from szelinsky.de ([127.0.0.1]) by localhost (szelinsky.de [127.0.0.1]) (amavis, port 10025) with ESMTP id 2aR3pwkZrhjJ; Wed, 24 Jun 2026 22:40:21 +0200 (CEST) Received: from p14sgen5.lanhh (dslb-088-070-183-212.088.070.pools.vodafone-ip.de [88.70.183.212]) by szelinsky.de (Postfix) with ESMTPSA; Wed, 24 Jun 2026 22:40:20 +0200 (CEST) From: Carlo Szelinsky To: Oleksij Rempel , Kory Maincent , Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Simon Horman , Corey Leavitt , Heiner Kallweit , Russell King , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Carlo Szelinsky Subject: [PATCH net v2] net: pse-pd: scope pse_control regulator handle to kref lifetime Date: Wed, 24 Jun 2026 22:40:16 +0200 Message-ID: <20260624204017.2752934-1-github@szelinsky.de> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Corey Leavitt __pse_control_release() drops psec->ps via devm_regulator_put(), which only succeeds if the devres entry added by the matching devm_regulator_get_exclusive() is still present on pcdev->dev at the time the pse_control's kref hits zero. That assumption does not hold when the controller is unbound while a pse_control still has consumers: pcdev->dev's devres list is released LIFO, so every per-attach regulator-GET devres runs (and regulator_put()s the underlying regulator) before pse_controller_unregister() itself is invoked. Any later pse_control_put() from that unbind path then reads psec->ps as a dangling pointer inside devm_regulator_put() and WARNs at drivers/regulator/devres.c:232 (devres_release() fails to find the already-released match). The pse_control's consumer handle is logically scoped to the pse_control's refcount, not to pcdev->dev's devres lifetime. Switch to the plain regulator_get_exclusive() / regulator_put() pair so the regulator put in __pse_control_release() no longer depends on the controller's devres still being present. No change to the regulator-framework-visible refcount or lifetime of the underlying regulator: a single get paired with a single put. The existing devm_regulator_register() for the per-PI rails is unchanged (those ARE correctly scoped to the controller's lifetime). This addresses only the regulator handle. The same unbind-while-held scenario also leaves __pse_control_release() reading psec->pcdev->pi[] and psec->pcdev->owner after pse_controller_unregister() has freed pcdev->pi, because the controller does not drain its outstanding pse_control references on unregister. That wider pse_control vs pcdev lifetime problem pre-dates this change and is addressed by the PSE controller notifier series, which drains phydev->psec on PSE_UNREGISTERED before pcdev->pi is freed. Link: https://lore.kernel.org/netdev/20260620112440.1734404-1-github@szelinsky.de/ Fixes: d83e13761d5b ("net: pse-pd: Use regulator framework within PSE framework") Signed-off-by: Corey Leavitt Acked-by: Kory Maincent Signed-off-by: Carlo Szelinsky --- This is patch 1 of the "decouple controller lookup from MDIO probe" series, reposted on its own for net as Jakub suggested. The rest of the series targets net-next and is deferred until it reopens. Changes in v2: - Reword the commit message to scope the fix to the regulator handle. As Simon's review pointed out, the same unbind-while-held path also reads pcdev->pi[] and pcdev->owner after pse_release_pis(); that wider pse_control vs pcdev lifetime issue is fixed by the notifier series, not here. No code change. Link: https://lore.kernel.org/netdev/20260624151251.1137250-1-horms@kernel.org/ v1: https://lore.kernel.org/netdev/20260622192839.2508733-1-github@szelinsky.de/ --- drivers/net/pse-pd/pse_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index 69dbdbde9d71..a5e6d7b26b9f 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -1367,7 +1367,7 @@ static void __pse_control_release(struct kref *kref) if (psec->pcdev->pi[psec->id].admin_state_enabled) regulator_disable(psec->ps); - devm_regulator_put(psec->ps); + regulator_put(psec->ps); module_put(psec->pcdev->owner); @@ -1436,8 +1436,8 @@ pse_control_get_internal(struct pse_controller_dev *pcdev, unsigned int index, goto free_psec; pcdev->pi[index].admin_state_enabled = ret; - psec->ps = devm_regulator_get_exclusive(pcdev->dev, - rdev_get_name(pcdev->pi[index].rdev)); + psec->ps = regulator_get_exclusive(pcdev->dev, + rdev_get_name(pcdev->pi[index].rdev)); if (IS_ERR(psec->ps)) { ret = PTR_ERR(psec->ps); goto put_module; base-commit: d87363b0edfc7504ff2b144fe4cdd8154f90f42e -- 2.43.0