From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DE763368B7 for ; Wed, 6 May 2026 12:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778071419; cv=none; b=WnkTPyfJUXZFOsg1NI77+CEQAHOk19GN83ZglUMjwSPNZPcuolO8SOlquWRxsrfRUFYQvnrjAsQ+u9nRmBJZfXdZWmi1kCWNPVb4Kji67D1U2ML30TTKKOolC/kYZs2Bnpm7HwW2kL3VV3ImdcBjcHg3BvZj8KBQi5ewj1DWtcw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778071419; c=relaxed/simple; bh=mGOYEqfn586cSv4mV7+ZkGjx2bX/Zy9gk3rZ2ZmOLzY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=c598FWZCSAwLUiMwhH28bA/6JzRQdqi3xhMnxHW4tf0xA0F90a00Usl/kh/BOi0E/z3y3hwHCZu/jKV/xajI0QSojWwxPlB5aoVTLXZJxp2DEEw3ie4LklsmeoWPWEspkhian8P7yN5LGHETGe37XHqxLigiPhhTINpY+Gpd0P4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pzuRiT4O; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pzuRiT4O" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2ba6485d219so10137745ad.3 for ; Wed, 06 May 2026 05:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778071418; x=1778676218; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XjgFoHcWtK3L/DYpi08j6irqA8vaezo7mFY7YSCvdu8=; b=pzuRiT4OWOqH/tHakt9I6dQEE8+DO+ZjYPdO5y5sL/Gd/00CncmnwXFJewKXFQnenR iRicSfEPIvDvkDEVxo7vOh4sYQGi8ml1NRran4ieRhC6cBImG7obK3RIPc0t0kBI7pMu eC/g669SHYoGKMtUmmgVh6y16MEKN/hMAtI0Be44ahheEPo3Xqfr2QRUS86cxHuPKKK8 8CRoZmecq3AQb/Km/y5o9unKiOFau+KKnU9oQU+Bo/SvoMJYUnA36xUnicFIzSBHa0EG niBwc+Zx7WA23Fw7Lt7qmjt8X6iKOiJSoAaSVfeF7jkNvmU4BC0ZmU/lkuZMclcXpxM3 vFYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778071418; x=1778676218; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=XjgFoHcWtK3L/DYpi08j6irqA8vaezo7mFY7YSCvdu8=; b=d6i1LIp/zYyRj7p22tik/GxB1ip6I4NOrvJPPzcP71V3NmpF/muNYIqGUblGGcAqIq Zw31ev4tcORGRnUFcoraLZHEv2Lok18/nurgMH++wbPGpFKgf9vv1eCCgfyCJCuF6lbj FeeYRWvfWp/z8GHs/TAANJSXas2/HMg0BGpNDiY1CoDHURwof3dgj30rSE4sOCo4aNfN GhICoJlunG5x9mdTv2DM0gpDlRT/iuRmBF9/NsKtkw3nyEzi6WMp4JGm+pEoPiHhvoFc N1NfnE1iesHgQCEY31mIupdy02GUCkD2zM4jUyrjTPATjATV3TO4lI7KjEL9xfRTwBGE 3KrQ== X-Forwarded-Encrypted: i=1; AFNElJ/sP/M/2IaTvqfYqG5o/ntlIRnAuU2JWBRYg+zKGvQC7w61L9a7u3QsdoslhgJxy5+ZarrACGoIMyaCphw=@vger.kernel.org X-Gm-Message-State: AOJu0YwewGj7p/LAc54mJSehRNfiOd3sKnAbSacZ2Pk/hh0PUSREZ9tO 4LhIyzwlBYlyoKudHEE3Eqan0EAsfuAdiYstGh8BlsthFuTEG+c3eSg= X-Gm-Gg: AeBDieu+f4ioV6JS842ObOEtPM+Kkz8VwEz+2IhQtYHsMDZzmm6qaCcPfMnnqJxOC/p RCwZCHFBTO96Pt+vQznJWFBqPtbW40h6cGEpjGKkLyfC/TOeu9MqQgYC19fOy6CQE1QcAHRO+98 OLZVCZMoAqHDCkqYYCnmSDcV+qDNslWe17uETDlbNHrD/QDBpAC/lcf7BSzEMyOOxNErxE++k8c gJgaCC02Lhdl3Aoc92ukrXxD+ZFlypXr8lMFmQjEugHwV+kzzDON0+VilUg6HmxWMxAQJAF3BB2 V2hzyrunuHNpsFulWLS7UlWR9GcTsxPWElFcj38WSGr39/7Qk+OxwCDU3me/CvizmKKVtCJfXMV kelmaXtF3BeAOcTjL/UgpjcJyai6RVMA2bBCAJcw8KOYpsb7rWhSbfPJi4hI1KX4wCMl+SHt3Pw 9vJcrQC4TY4QewCnpuIGXfdU4M4fSWPo3ywBM5YwhTTx4PpxH3CmCaMLV3LYtU5At6SAfPBzNlT XYWrHloyw== X-Received: by 2002:a17:903:90e:b0:2b0:b016:773f with SMTP id d9443c01a7336-2ba7908443cmr33626045ad.11.1778071418029; Wed, 06 May 2026 05:43:38 -0700 (PDT) Received: from localhost.localdomain ([1.226.165.54]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ba7c9e16f2sm25584615ad.45.2026.05.06.05.43.35 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 06 May 2026 05:43:37 -0700 (PDT) From: Myeonghun Pak To: Horatiu Vultur , UNGLinuxDriver@microchip.com, Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Ijae Kim Cc: Myeonghun Pak , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] net: lan966x: avoid unregistering netdev on register failure Date: Wed, 6 May 2026 21:43:11 +0900 Message-ID: <20260506124331.31945-1-mhun512@gmail.com> X-Mailer: git-send-email 2.47.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 lan966x_probe_port() stores the newly allocated net_device in the port before calling register_netdev(). If register_netdev() fails, the probe error path calls lan966x_cleanup_ports(), which sees port->dev and calls unregister_netdev() for a device that was never registered. Destroy the phylink instance created for this port and clear port->dev before returning the registration error. The common cleanup path now skips ports without port->dev before reaching the registered netdev cleanup, so it only handles ports that reached the registered-netdev lifetime. This also avoids treating an uninitialized FDMA netdev and the failed port as a NULL == NULL match in the common cleanup path. Fixes: d28d6d2e37d1 ("net: lan966x: add port module support") Co-developed-by: Ijae Kim Signed-off-by: Ijae Kim Signed-off-by: Myeonghun Pak --- Changes in v3: - Make lan966x_cleanup_ports() skip ports without port->dev, so the common cleanup path does not run registered-netdev, XDP, FDMA, or phylink cleanup for a port whose netdev registration failed. - Keep the register_netdev() failure path responsible for destroying the newly created phylink and clearing port->dev before returning. Changes in v2: - Require port->dev to be non-NULL before calling the FDMA netdev cleanup path, avoiding a NULL == NULL match when register_netdev() fails before FDMA NAPI has been initialized. drivers/net/ethernet/microchip/lan966x/lan966x_main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c index 47752d3fde..1179a6e127 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c @@ -749,11 +749,10 @@ static void lan966x_cleanup_ports(struct lan966x *lan966x) for (p = 0; p < lan966x->num_phys_ports; p++) { port = lan966x->ports[p]; - if (!port) + if (!port || !port->dev) continue; - if (port->dev) - unregister_netdev(port->dev); + unregister_netdev(port->dev); lan966x_xdp_port_deinit(port); if (lan966x->fdma && lan966x->fdma_ndev == port->dev) @@ -873,6 +872,9 @@ static int lan966x_probe_port(struct lan966x *lan966x, u32 p, err = register_netdev(dev); if (err) { dev_err(lan966x->dev, "register_netdev failed\n"); + phylink_destroy(phylink); + port->phylink = NULL; + port->dev = NULL; return err; }