From patchwork Mon Jun 24 10:29:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13709299 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1B84EC2BD05 for ; Mon, 24 Jun 2024 10:29:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=nyY2ZZiHme00HbBe8pGYRA6yVdo7lRrAai+PoMjkalc=; b=Hw7xIg5TXAH7IHUSybkNAZ8cl6 95gnxK0CAYXd86YUo4zCHstPJWOZ77g2GJj1VJze5Bn3mr8B7c+dRm+UCp4upKOic7PB1PsECV5vJ ZZNqquI99CDu3NUNa5gV+927jMBa90iVn93uycHTVYgz/UVxYMayjDfgk2ngm4RvS+sGZyOq5DAyz q5xxocVrVD/pkCQ6F1sYR0ijoKgJIzIealacx9hlMzfivd2efIx4N8VNTkczYYVk3kAlrN6ca+ZX2 oWH34KeNI7ZyYZRQuiK0C2GljHVcQ/h2nSK0SFMvilixx/qmkVRfcopLQayC1CeeQpUl3I5Zj2sdp v5lYEdiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLgx3-0000000GQJo-2mxX; Mon, 24 Jun 2024 10:29:33 +0000 Received: from mail-ej1-f53.google.com ([209.85.218.53]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLgwx-0000000GQGL-3quz for linux-arm-kernel@lists.infradead.org; Mon, 24 Jun 2024 10:29:29 +0000 Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a6fe617966fso170145966b.1 for ; Mon, 24 Jun 2024 03:29:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719224966; x=1719829766; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nyY2ZZiHme00HbBe8pGYRA6yVdo7lRrAai+PoMjkalc=; b=VmoaVYLKPs4uIAqdiFIFVw5VJLqIQHRg7nvTYMnpA3upqFCQ327g7Uq9XuvCo6ZjJ9 +lqZfvmRpIbxLRXqjEjYQDpziblpav/TkT+BWaSZS9NMSi1FlAu4nUOzS+LUdTn4oeYd yLnszpRI31TmiHCnDBn2/LZMzEFu3W2+ejUha/Mf7iQJUJOnxJz4bil/no9PO9zzkwUO jqkuXbovWxOEM+nTz3mGmrJe2yQaX0wW/kDt6XDekGCYOqAq7XXK+u10f+tjiTnzdsDE yTf3V0gq+CSgbR51lJAIiWmXqOO8mDbvwwXdYCYKln1Z+aXqCBc+ajAPLyYrUsggDT49 HJrw== X-Forwarded-Encrypted: i=1; AJvYcCVRMO1ZLWPl3VadhpnBMqeIg2cXKOG5vTHHRg4njaJQJLpVt0jB/wcK8bFUDOsaD5zT2NHXH7nXswTghDO0fR4tRD+FehoBmv22yiVDtDJu96WKW58= X-Gm-Message-State: AOJu0YyOhwGMUI3pjfGuUgJmXPgpkLuERf4H/pqu+upRJbkMvC+IRryL /zYKBwb3n+NsS1YN+sOrbokUaEygkx9kP4TIqVA3rz6PH0Rl+8Sq X-Google-Smtp-Source: AGHT+IFvaj7d8f/TKbBcTbx/Me9SR9bDVUuO5uBmoAvYJ1+v2T9aT/ellVN4L4y09upWMQDrgA+JeQ== X-Received: by 2002:a17:907:cb85:b0:a72:46f3:ffc8 with SMTP id a640c23a62f3a-a7246f40067mr281037066b.29.1719224965698; Mon, 24 Jun 2024 03:29:25 -0700 (PDT) Received: from localhost (fwdproxy-lla-001.fbsv.net. [2a03:2880:30ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a71ddbd3479sm240836966b.189.2024.06.24.03.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 03:29:25 -0700 (PDT) From: Breno Leitao To: Sunil Goutham , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: horms@kernel.org, linux-arm-kernel@lists.infradead.org (moderated list:ARM/CAVIUM THUNDER NETWORK DRIVER), netdev@vger.kernel.org (open list:NETWORKING DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next] net: thunderx: Unembed netdev structure Date: Mon, 24 Jun 2024 03:29:18 -0700 Message-ID: <20240624102919.4016797-1-leitao@debian.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240624_032927_979438_AC0F04E5 X-CRM114-Status: GOOD ( 14.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Embedding net_device into structures prohibits the usage of flexible arrays in the net_device structure. For more details, see the discussion at [1]. Un-embed the net_devices from struct lmac by converting them into pointers, and allocating them dynamically. Use the leverage alloc_netdev() to allocate the net_device object at bgx_lmac_enable(). The free of the device occurs at bgx_lmac_disable(). Do not free_netdevice() if bgx_lmac_enable() fails after lmac->netdev is allocated, since bgx_lmac_disable() is called if bgx_lmac_enable() fails, and lmac->netdev will be freed there (similarly to lmac->dmacs). Link: https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/ [1] Signed-off-by: Breno Leitao --- PS: Unfortunately due to lack of hardware, this patch is compiled-test only. .../net/ethernet/cavium/thunder/thunder_bgx.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c index a317feb8decb..d097d606577b 100644 --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c @@ -54,7 +54,7 @@ struct lmac { bool link_up; int lmacid; /* ID within BGX */ int lmacid_bd; /* ID on board */ - struct net_device netdev; + struct net_device *netdev; struct phy_device *phydev; unsigned int last_duplex; unsigned int last_link; @@ -590,7 +590,7 @@ static void bgx_sgmii_change_link_state(struct lmac *lmac) static void bgx_lmac_handler(struct net_device *netdev) { - struct lmac *lmac = container_of(netdev, struct lmac, netdev); + struct lmac *lmac = netdev_priv(netdev); struct phy_device *phydev; int link_changed = 0; @@ -1052,12 +1052,18 @@ static int phy_interface_mode(u8 lmac_type) static int bgx_lmac_enable(struct bgx *bgx, u8 lmacid) { - struct lmac *lmac; + struct lmac *lmac, **priv; u64 cfg; lmac = &bgx->lmac[lmacid]; lmac->bgx = bgx; + lmac->netdev = alloc_netdev_dummy(sizeof(struct lmac *)); + if (!lmac->netdev) + return -ENOMEM; + priv = netdev_priv(lmac->netdev); + *priv = lmac; + if ((lmac->lmac_type == BGX_MODE_SGMII) || (lmac->lmac_type == BGX_MODE_QSGMII) || (lmac->lmac_type == BGX_MODE_RGMII)) { @@ -1116,7 +1122,7 @@ static int bgx_lmac_enable(struct bgx *bgx, u8 lmacid) } lmac->phydev->dev_flags = 0; - if (phy_connect_direct(&lmac->netdev, lmac->phydev, + if (phy_connect_direct(lmac->netdev, lmac->phydev, bgx_lmac_handler, phy_interface_mode(lmac->lmac_type))) return -ENODEV; @@ -1183,6 +1189,7 @@ static void bgx_lmac_disable(struct bgx *bgx, u8 lmacid) (lmac->lmac_type != BGX_MODE_10G_KR) && lmac->phydev) phy_disconnect(lmac->phydev); + free_netdev(lmac->netdev); lmac->phydev = NULL; } @@ -1414,7 +1421,7 @@ static acpi_status bgx_acpi_register_phy(acpi_handle handle, acpi_get_mac_address(dev, adev, bgx->lmac[bgx->acpi_lmac_idx].mac); - SET_NETDEV_DEV(&bgx->lmac[bgx->acpi_lmac_idx].netdev, dev); + SET_NETDEV_DEV(bgx->lmac[bgx->acpi_lmac_idx].netdev, dev); bgx->lmac[bgx->acpi_lmac_idx].lmacid = bgx->acpi_lmac_idx; bgx->acpi_lmac_idx++; /* move to next LMAC */ @@ -1483,7 +1490,7 @@ static int bgx_init_of_phy(struct bgx *bgx) of_get_mac_address(node, bgx->lmac[lmac].mac); - SET_NETDEV_DEV(&bgx->lmac[lmac].netdev, &bgx->pdev->dev); + SET_NETDEV_DEV(bgx->lmac[lmac].netdev, &bgx->pdev->dev); bgx->lmac[lmac].lmacid = lmac; phy_np = of_parse_phandle(node, "phy-handle", 0);