Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp290016lqo; Tue, 7 May 2024 22:46:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVePFk5leaprPOU5kjikXvXA3Vf9hzD3SXl2xmNhTyVGnj8RblYBGyv517S2+JP0Z4Ihb0ZdrHwTbZfkRI1cLmRED5ytsW7q59EZKgR8w== X-Google-Smtp-Source: AGHT+IG4zemg5ABlUSbN29FDMYKWPKSjKKGeEPnIpt/FtURFFjmCklJgN7b2uCh9nKpsgDRrWVGz X-Received: by 2002:a17:906:abda:b0:a59:a431:a8d6 with SMTP id a640c23a62f3a-a59faa660b1mr133260566b.38.1715147162551; Tue, 07 May 2024 22:46:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715147162; cv=pass; d=google.com; s=arc-20160816; b=Rm+VJIexe6Z8OyT8jyBbM9ex9UVKdzkLniUbBurJVPjjct+//2BnJV35WaJq+3QFER b5Ftke6ejuKuH9GUl9flRZm627X4IdzLsg/gbLmg0PqBd6roC/8i1uSd5LbzcxUuJeYa O87JijoJpmUg/HFZDkpBJSV9YIGZTl880iyiB6W0UeHPQJXw0b5a8v6TNDuFmGW4WMPV QQ/nm8s9c6AP6YNYAY9Zh/ps7nx8XCV+a5ssSuqpdz1GRsxwzicaubSg3A4jQ917k+Ye yFZK7Vv/iJ4ORgI+5ALqSb9IXNAEtjIKPM1Ms+zDb+hXQJykA1/rRYzYXUO0EWB7Vby5 SSDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:subject:from:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=tWp+2HJ0ZBVj/8UDTxv5UJsC8X6e/fyQU24aWtEM2tI=; fh=Nm5LmvCRK7AbI8Lyvts+5FQusetV+z7mLYDBynm7t8s=; b=FjHpOGR2LisVsZ3VcRWQTBYJa/3X3JapzgYrs0M/92Zwzm4LErvvXmWo/ea/v1xs/2 6EXEovmEfQbebWUNWWZrm+Vlq1V5rSE2CsJpC3sRHen7VQBpSYvvCQGrDX5mZugD6LyV a67n8ngH2hRHldiWdoLQld1vwuTg99SWyWdBS9ocjhQqnEd5nsgl5a8q3P9jdxujF5co Q6q/4GCFsRLziU2YIsTaHStEG3Tfqi2q6KPuUEDB4gfQH2llOUnJ77AU116V8zgPTu5J FyTVbWab9IepSOttkCVHkqvmkLREZweedgEMR4UDghAy0AYvREUmwn8KtsVs/srMlUa8 AxsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EzaVhwjd; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-172710-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172710-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id go18-20020a1709070d9200b00a59aff28faasi4494593ejc.869.2024.05.07.22.46.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 22:46:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172710-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EzaVhwjd; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-172710-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172710-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E23481F2378F for ; Wed, 8 May 2024 05:46:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2697424B2F; Wed, 8 May 2024 05:44:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EzaVhwjd" Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (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 114D923772; Wed, 8 May 2024 05:44:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715147065; cv=none; b=DvLnlp+IFJwSiLeb3q0HREG5XkJIBx+6a7KbH23lQv83lwOl+dUYfEprnmAcODbs09+p8sRYEnMe/H8CaiAtSy9LKciQ3I2+VoHwaT7p9VdX+X+y9i1P4SOi8Ng5ml9WHp/Z1kzfjV+q39DP99qJb3+++15lpeHHNcF2dmrLFpU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715147065; c=relaxed/simple; bh=g0QKnentJGiost6G7V+VKDbo7VqtLa6zkLDH8d+Xvl4=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=a9NHp4sTTFrJhDjU4eEEHVoNJ8w1QA0IG1e/oU9iUxaOXB9WQzt8kbvV09rg59nz1fDWXlHI/e3WhwvOYqYXXhOOD37vaG/sAn74KQFPM+5CRNH/fYNAO+Ci9653Jm2mYEY9qqz6p7CAGQxV9aBMRtsPIpdK2c67p8jUu9AUp3I= 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=EzaVhwjd; arc=none smtp.client-ip=209.85.218.49 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 Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a59ce1e8609so83518366b.0; Tue, 07 May 2024 22:44:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715147062; x=1715751862; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=tWp+2HJ0ZBVj/8UDTxv5UJsC8X6e/fyQU24aWtEM2tI=; b=EzaVhwjdM9SXp1uqkYrThf6JSmTZloGBA20qYw+tujNQZWA0nJBpCX1SFzjMwfgqLG /6uDqRKdUxA9fsMz04udnxhSLF4gyIiUFO4Dg6PAV3O/VnI1jZ5qHXTSowDejFMn0WSA /QXxn2yG7KHDA9ydmFy6oQJGa6kaUobKXcLG8so8PxhKJIkHjZ00GSIjRJBFAgathnTE DqvS5prBbBo+fo0rP3h3A3ttAKX5a8VYB7B3GcLxprRD5JAsjwWPx3QeBBx6pPbdldMz 5bRXys8UhTw6FfzlvTw4qkO9aHQjsivMCsC8jozAsvDa1yBye6xwDD4wOb+NTpRBC0rO 36VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715147062; x=1715751862; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tWp+2HJ0ZBVj/8UDTxv5UJsC8X6e/fyQU24aWtEM2tI=; b=Yi4RzIF2rImULAUIC+Ca75GHQd3w3VDKvmnMITI8i8qaLqlwvPQsgL2lCuazei0+by i+CRmw95sxeViLWPx4YunZ7hS0wBT+WOmR+IYrNmaAy0pWBV9aS376Ooz90tCSXRXjX5 k4PZaN7ucxj6qsJxXnuKUXlx8OizAonmAKQFhMZhTqfFQfT0pmLYVwaKIISQ11vp6Sl9 ybgClmSlNqgHg4Rv1L43WXPMVoj6ugPDclTEVdfqbsvCWOCdDM7vFwXr7PeIS+964sW8 5g08fP5wAiI3PGdZYPGefERH6OP8LJbQVreR+xY111GIF3z0++43SoFJb263ysV8payk euLg== X-Forwarded-Encrypted: i=1; AJvYcCWNBhXktsFWMI9g4neMafxAayUoMA694GlwqmGCmDR9KDw+hgWSIvC+Oc97P3UtbU7eVfCbFk7izoh9OlxbZPChmIly3qNzi3qcvbRr X-Gm-Message-State: AOJu0YzfLi8uOkUsGTiH6BxaQnNaBeMA0Za3GjmEuJZO7aAILcau3eeD wAO1VHqrfLPbpwb0bL1cgxXxF8R8etLjmdlNP9NG6lVcpP9Cfo1R X-Received: by 2002:a17:906:4a8a:b0:a51:8672:66e4 with SMTP id a640c23a62f3a-a59e4cf82c9mr379969566b.22.1715147062065; Tue, 07 May 2024 22:44:22 -0700 (PDT) Received: from ?IPV6:2a01:c23:c5ec:1600:f15f:edb4:9cd5:3c38? (dynamic-2a01-0c23-c5ec-1600-f15f-edb4-9cd5-3c38.c23.pool.telefonica.de. [2a01:c23:c5ec:1600:f15f:edb4:9cd5:3c38]) by smtp.googlemail.com with ESMTPSA id j8-20020a50ed08000000b0056e718795f8sm7168133eds.36.2024.05.07.22.44.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 May 2024 22:44:21 -0700 (PDT) Message-ID: <6cedd632-d555-4c17-81cb-984af73f2c08@gmail.com> Date: Wed, 8 May 2024 07:44:22 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Heiner Kallweit Subject: Re: [PATCH net-next 2/2] net: phy: phy_link_topology: Lazy-initialize the link topology To: Maxime Chevallier , davem@davemloft.net Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Vladimir Oltean , =?UTF-8?Q?K=C3=B6ry_Maincent?= , Jesse Brandeburg , =?UTF-8?Q?Marek_Beh=C3=BAn?= , Piergiorgio Beruto , Oleksij Rempel , =?UTF-8?Q?Nicol=C3=B2_Veronese?= , Simon Horman , mwojtas@chromium.org, Nathan Chancellor , Antoine Tenart References: <20240507102822.2023826-1-maxime.chevallier@bootlin.com> <20240507102822.2023826-3-maxime.chevallier@bootlin.com> Content-Language: en-US Autocrypt: addr=hkallweit1@gmail.com; keydata= xsFNBF/0ZFUBEAC0eZyktSE7ZNO1SFXL6cQ4i4g6Ah3mOUIXSB4pCY5kQ6OLKHh0FlOD5/5/ sY7IoIouzOjyFdFPnz4Bl3927ClT567hUJJ+SNaFEiJ9vadI6vZm2gcY4ExdIevYHWe1msJF MVE4yNwdS+UsPeCF/6CQQTzHc+n7DomE7fjJD5J1hOJjqz2XWe71fTvYXzxCFLwXXbBiqDC9 dNqOe5odPsa4TsWZ09T33g5n2nzTJs4Zw8fCy8rLqix/raVsqr8fw5qM66MVtdmEljFaJ9N8 /W56qGCp+H8Igk/F7CjlbWXiOlKHA25mPTmbVp7VlFsvsm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XghEyQMTH2UhLgeam8yglyO+A6RXCh+s6ak Wje7Vo1wGK4eYxp6pwMPJXLMsI0ii/2k3YPEJPv+yJf90MbYyQSbkTwZhrsokjQEaIfjrIk3 rQRjTve/J62WIO28IbY/mENuGgWehRlTAbhC4BLTZ5uYS0YMQCR7v9UGMWdNWXFyrOB6PjSu Trn9MsPoUc8qI72mVpxEXQDLlrd2ijEWm7Nrf52YMD7hL6rXXuis7R6zY8WnnBhW0uCfhajx q+KuARXC0sDLztcjaS3ayXonpoCPZep2Bd5xqE4Ln8/COCslP7E92W1uf1EcdXXIrx1acg21 H/0Z53okMykVs3a8tECPHIxnre2UxKdTbCEkjkR4V6JyplTS47oWMw3zyI7zkaadfzVFBxk2 lo/Tny+FX1Azea3Ce7oOnRUEZtWSsUidtIjmL8YUQFZYm+JUIgfRmSpMFq8JP4VH43GXpB/S OCrl+/xujzvoUBFV/cHKjEQYBxo+MaiQa1U54ykM2W4DnHb1UiEf5xDkFd4= In-Reply-To: <20240507102822.2023826-3-maxime.chevallier@bootlin.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 07.05.2024 12:28, Maxime Chevallier wrote: > Having the net_device's init path for the link_topology depend on > IS_REACHABLE(PHYLIB)-protected helpers triggers errors when modules are being > built with phylib as a module as-well, as they expect netdev->link_topo > to be initialized. > > Move the link_topo initialization at the first PHY insertion, which will > both improve the memory usage, and make the behaviour more predicatble > and robust. > > Signed-off-by: Maxime Chevallier > Fixes: 6916e461e793 ("net: phy: Introduce ethernet link topology representation") > Closes: https://lore.kernel.org/netdev/2e11b89d-100f-49e7-9c9a-834cc0b82f97@gmail.com/ > Closes: https://lore.kernel.org/netdev/20240409201553.GA4124869@dev-arch.thelio-3990X/ > --- > drivers/net/phy/phy_link_topology.c | 31 ++++++--------------- > include/linux/netdevice.h | 2 ++ > include/linux/phy_link_topology.h | 23 ++++++++-------- > include/linux/phy_link_topology_core.h | 23 +++------------- > net/core/dev.c | 38 ++++++++++++++++++++++---- > 5 files changed, 58 insertions(+), 59 deletions(-) > > diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link_topology.c > index 0e36bd7c15dc..b1aba9313e73 100644 > --- a/drivers/net/phy/phy_link_topology.c > +++ b/drivers/net/phy/phy_link_topology.c > @@ -12,29 +12,6 @@ > #include > #include > > -struct phy_link_topology *phy_link_topo_create(struct net_device *dev) > -{ > - struct phy_link_topology *topo; > - > - topo = kzalloc(sizeof(*topo), GFP_KERNEL); > - if (!topo) > - return ERR_PTR(-ENOMEM); > - > - xa_init_flags(&topo->phys, XA_FLAGS_ALLOC1); > - topo->next_phy_index = 1; > - > - return topo; > -} > - > -void phy_link_topo_destroy(struct phy_link_topology *topo) > -{ > - if (!topo) > - return; > - > - xa_destroy(&topo->phys); > - kfree(topo); > -} > - > int phy_link_topo_add_phy(struct net_device *dev, > struct phy_device *phy, > enum phy_upstream upt, void *upstream) > @@ -43,6 +20,14 @@ int phy_link_topo_add_phy(struct net_device *dev, > struct phy_device_node *pdn; > int ret; > > + if (!topo) { > + ret = netdev_alloc_phy_link_topology(dev); This function is implemented in net core, but used only here. So move the implementation here? > + if (ret) > + return ret; > + > + topo = dev->link_topo; > + } > + > pdn = kzalloc(sizeof(*pdn), GFP_KERNEL); > if (!pdn) > return -ENOMEM; > diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h > index cf261fb89d73..25a0a77cfadc 100644 > --- a/include/linux/netdevice.h > +++ b/include/linux/netdevice.h > @@ -4569,6 +4569,8 @@ void __hw_addr_unsync_dev(struct netdev_hw_addr_list *list, > const unsigned char *)); > void __hw_addr_init(struct netdev_hw_addr_list *list); > > +int netdev_alloc_phy_link_topology(struct net_device *dev); > + > /* Functions used for device addresses handling */ > void dev_addr_mod(struct net_device *dev, unsigned int offset, > const void *addr, size_t len); > diff --git a/include/linux/phy_link_topology.h b/include/linux/phy_link_topology.h > index 166a01710aa2..3501f9a9e932 100644 > --- a/include/linux/phy_link_topology.h > +++ b/include/linux/phy_link_topology.h > @@ -32,10 +32,12 @@ struct phy_device_node { > struct phy_device *phy; > }; > > -struct phy_link_topology { > - struct xarray phys; > - u32 next_phy_index; > -}; > +#if IS_ENABLED(CONFIG_PHYLIB) > +int phy_link_topo_add_phy(struct net_device *dev, > + struct phy_device *phy, > + enum phy_upstream upt, void *upstream); > + > +void phy_link_topo_del_phy(struct net_device *dev, struct phy_device *phy); > > static inline struct phy_device > *phy_link_topo_get_phy(struct net_device *dev, u32 phyindex) > @@ -53,13 +55,6 @@ static inline struct phy_device > return NULL; > } > > -#if IS_REACHABLE(CONFIG_PHYLIB) > -int phy_link_topo_add_phy(struct net_device *dev, > - struct phy_device *phy, > - enum phy_upstream upt, void *upstream); > - > -void phy_link_topo_del_phy(struct net_device *dev, struct phy_device *phy); > - > #else > static inline int phy_link_topo_add_phy(struct net_device *dev, > struct phy_device *phy, > @@ -72,6 +67,12 @@ static inline void phy_link_topo_del_phy(struct net_device *dev, > struct phy_device *phy) > { > } > + > +static inline struct phy_device * > +phy_link_topo_get_phy(struct net_device *dev, u32 phyindex) > +{ > + return NULL; > +} > #endif > > #endif /* __PHY_LINK_TOPOLOGY_H */ > diff --git a/include/linux/phy_link_topology_core.h b/include/linux/phy_link_topology_core.h > index 0a6479055745..f9c0520806fb 100644 > --- a/include/linux/phy_link_topology_core.h > +++ b/include/linux/phy_link_topology_core.h > @@ -2,24 +2,9 @@ > #ifndef __PHY_LINK_TOPOLOGY_CORE_H > #define __PHY_LINK_TOPOLOGY_CORE_H > > -struct phy_link_topology; > - > -#if IS_REACHABLE(CONFIG_PHYLIB) > - > -struct phy_link_topology *phy_link_topo_create(struct net_device *dev); > -void phy_link_topo_destroy(struct phy_link_topology *topo); > - > -#else > - > -static inline struct phy_link_topology *phy_link_topo_create(struct net_device *dev) > -{ > - return NULL; > -} > - > -static inline void phy_link_topo_destroy(struct phy_link_topology *topo) > -{ > -} > - > -#endif > +struct phy_link_topology { > + struct xarray phys; > + u32 next_phy_index; > +}; > This is all which is left in this header. As this header is public anyway, better move this definition to phy_link_topology.h? > #endif /* __PHY_LINK_TOPOLOGY_CORE_H */ > diff --git a/net/core/dev.c b/net/core/dev.c > index d2ce91a334c1..1b4ffc273a04 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -10256,6 +10256,35 @@ static void netdev_do_free_pcpu_stats(struct net_device *dev) > } > } > > +int netdev_alloc_phy_link_topology(struct net_device *dev) > +{ > + struct phy_link_topology *topo; > + > + topo = kzalloc(sizeof(*topo), GFP_KERNEL); > + if (!topo) > + return -ENOMEM; > + > + xa_init_flags(&topo->phys, XA_FLAGS_ALLOC1); > + topo->next_phy_index = 1; > + > + dev->link_topo = topo; > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(netdev_alloc_phy_link_topology); > + > +static void netdev_free_phy_link_topology(struct net_device *dev) > +{ > + struct phy_link_topology *topo = dev->link_topo; > + > + if (!topo) > + return; > + > + xa_destroy(&topo->phys); > + kfree(topo); > + dev->link_topo = NULL; Give the compiler a chance to remove this function if CONFIG_PHYLIB isn't enabled. if (IS_ENABLED(CONFIG_PHYLIB) && topo) { xa_destroy(&topo->phys); kfree(topo); dev->link_topo = NULL; } > +} > + > /** > * register_netdevice() - register a network device > * @dev: device to register > @@ -10998,11 +11027,6 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, > #ifdef CONFIG_NET_SCHED > hash_init(dev->qdisc_hash); > #endif > - dev->link_topo = phy_link_topo_create(dev); > - if (IS_ERR(dev->link_topo)) { > - dev->link_topo = NULL; > - goto free_all; > - } > > dev->priv_flags = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM; > setup(dev); > @@ -11092,7 +11116,9 @@ void free_netdev(struct net_device *dev) > free_percpu(dev->xdp_bulkq); > dev->xdp_bulkq = NULL; > > - phy_link_topo_destroy(dev->link_topo); > +#if IS_ENABLED(CONFIG_PHYLIB) > + netdev_free_phy_link_topology(dev); > +#endif > Then the conditional compiling can be removed here. > /* Compatibility with error handling in drivers */ > if (dev->reg_state == NETREG_UNINITIALIZED ||