From patchwork Mon May 11 15:07:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 200787 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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,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 0DCCCC54E8D for ; Mon, 11 May 2020 15:09:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD55820643 for ; Mon, 11 May 2020 15:09:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="lGEfjqd/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729766AbgEKPJW (ORCPT ); Mon, 11 May 2020 11:09:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1730298AbgEKPI3 (ORCPT ); Mon, 11 May 2020 11:08:29 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33352C061A0C for ; Mon, 11 May 2020 08:08:28 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id 50so10880891wrc.11 for ; Mon, 11 May 2020 08:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TLMq2XwRgUC25FFpg44rE1jATuYcYABivRm1tKC5XTM=; b=lGEfjqd/Aqo91nNbYHQC/XXhvPNRro/VrpfSU0EKrgUiO5UJ0lZXxyaNjy0vwymwSb uxwP22CTUu7BkW2bIoeK3qhHOwvoFsYhIhZngMUlHLW4GZlrj2EaI2Od7rJuyEum2hPJ mOOddMd5+KhA4BsHVTsFc1TO02ZsDR/PDJsjrmcYeCSNntHIyaYLDAKJYR4kDyHYUkdo fa8cnqPq4/GDF/sZDgDOT2ZTLehxieagSqPBErq+zM756mvMYXQKGiraMxfd2vT4/Pq4 A/Z1mAM/jRHFEXGLC9eB34BPWmePWBU9/Ou4b7W0qT+98gs2/rruU5IXXYcZJR3Y5Amy Dh+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TLMq2XwRgUC25FFpg44rE1jATuYcYABivRm1tKC5XTM=; b=GLxwizuksejC6/2hSNgJtcQkX7yo45s/eyTs9hznIB9z9ylDrwhMj45NlaMeEEX0LB Sc3L1LMWTwtqyKqRtVjz1loYgxLMbGXSRu4dOZ3YifXp0snKaG/FMOD1JR02QnnYLU3I mSrzm0BImRxwheft9daE+Uxm/pZoA7xfWyJI7joOUHubRLyMBzqvdLGbPdmbsNml4QGJ R2lYs+TrFHjBUGhwALTJLXBKO+w55oJI0mNIVpocoq3itx2kA1uu076l5xGJdaORi9ce T0W62uJmDhEj1eCyMajJk4qAWf2m5oqAkKyrKXi5pkdMZ7kQwfkAxJ3LS3m1/phe56r3 MKDw== X-Gm-Message-State: AGi0Pua9ucZVJxRStiwWYX3cEVYHa4si4sAbsTZtcfEAZp4ojFg76XRk C8a02a6S43a6gSu95UtCg1djHw== X-Google-Smtp-Source: APiQypLrstV08k3pPp3S+tVHPnE3B6GnlgxYC6jtUQXLXJtg4uaQOjgd0DZV0NaM/PAy80Q8A9SMbg== X-Received: by 2002:a5d:4801:: with SMTP id l1mr18746418wrq.235.1589209706975; Mon, 11 May 2020 08:08:26 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id 94sm3514792wrf.74.2020.05.11.08.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2020 08:08:26 -0700 (PDT) From: Bartosz Golaszewski To: Rob Herring , "David S . Miller" , Matthias Brugger , John Crispin , Sean Wang , Mark Lee , Jakub Kicinski , Arnd Bergmann , Fabien Parent , Heiner Kallweit , Edwin Peer Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Stephane Le Provost , Pedro Tsai , Andrew Perepech , Bartosz Golaszewski Subject: [PATCH v2 05/14] net: core: provide priv_to_netdev() Date: Mon, 11 May 2020 17:07:50 +0200 Message-Id: <20200511150759.18766-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200511150759.18766-1-brgl@bgdev.pl> References: <20200511150759.18766-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Bartosz Golaszewski Appropriate amount of extra memory for private data is allocated at the end of struct net_device. We have a helper - netdev_priv() - that returns its address but we don't have the reverse: a function which given the address of the private data, returns the address of struct net_device. This has caused many drivers to store the pointer to net_device in the private data structure, which basically means storing the pointer to a structure in this very structure. This patch proposes to add priv_to_netdev() - a helper which converts the address of the private data to the address of the associated net_device. Signed-off-by: Bartosz Golaszewski --- include/linux/netdevice.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 130a668049ab..933c6808a87f 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2249,6 +2249,18 @@ static inline void *netdev_priv(const struct net_device *dev) return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN); } +/** + * priv_to_netdev - get the net_device from private data + * @priv: net_device private data + * + * Get the address of network device associated with this private data. + */ +static inline struct net_device *priv_to_netdev(void *priv) +{ + priv = (char *)priv - ALIGN(sizeof(struct net_device), NETDEV_ALIGN); + return (struct net_device *)priv; +} + /* Set the sysfs physical device reference for the network logical device * if set prior to registration will cause a symlink during initialization. */