From patchwork Mon Jul 10 03:19:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 786009 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3x5Vpc1dz6z9s03 for ; Mon, 10 Jul 2017 13:20:40 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=zx2c4.com header.i=@zx2c4.com header.b="dqrOsUne"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753177AbdGJDUJ (ORCPT ); Sun, 9 Jul 2017 23:20:09 -0400 Received: from frisell.zx2c4.com ([192.95.5.64]:54247 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753076AbdGJDUI (ORCPT ); Sun, 9 Jul 2017 23:20:08 -0400 Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 724109c4; Mon, 10 Jul 2017 03:15:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=mail; bh=Bov2 +KGteEV7F8Mt3FL8vm0khPs=; b=dqrOsUne4wDE3vH3VNdvupRRWY/ElYCp5/TU I6exqvDTHnVRwHF6rePpGrQWQQm7nS5V8O3WvU1PmuVWNmcpsK8I5Gn0WqSjrKxm UkylwJMhmf2O99ayKYEhsYMjD8IKufFfSqzHK4XKzYfkXusbgADnH6paXDwg+8DK JIKBCgT2MrdO/+JtIcRN8SyNvMTEjFAG152ryMKnJU3TmwSQphBSMAhqjKfMthjV bb+UZ7QiKPhLHxrVRGiqDlnC1tTmtVrn2AWQCIGJFVHez/ArcKrY1TMdxMAAWUYJ AbKl2mitlz8eIeAfz1YGfc4hD3QzpbrH8FTG6Q6tyqUk385fgg== Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 3041758f (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Mon, 10 Jul 2017 03:15:34 +0000 (UTC) From: "Jason A. Donenfeld" To: davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Jason A. Donenfeld" Subject: [PATCH 1/2] netdevice: add netdev_pub helper function Date: Mon, 10 Jul 2017 05:19:58 +0200 Message-Id: <20170710031959.7496-1-Jason@zx2c4.com> In-Reply-To: <20150612.142058.1085284048217032168.davem@davemloft.net> References: <20150612.142058.1085284048217032168.davem@davemloft.net> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Being able to utilize this makes code a lot simpler and cleaner. It's easier in many cases for drivers to pass around their private data structure, while occationally needing to dip into net_device, rather than the other way around, which results in tons of calls to netdev_priv in the top of every single function, which makes everything confusing and less clear. Additionally, this enables a "correct" way of doing such a thing, instead of having drivers attempt to reinvent the wheel and screw it up. Signed-off-by: Jason A. Donenfeld --- include/linux/netdevice.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 779b23595596..83d58504e5c4 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2030,26 +2030,37 @@ void dev_net_set(struct net_device *dev, struct net *net) } /** * netdev_priv - access network device private data * @dev: network device * * Get network device private data */ static inline void *netdev_priv(const struct net_device *dev) { return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN); } +/** + * netdev_pub - access network device from private pointer + * @priv: private data pointer of network device + * + * Get network device from a network device private data pointer + */ +static inline struct net_device *netdev_pub(void *priv) +{ + return (struct net_device *)((char *)priv - ALIGN(sizeof(struct net_device), NETDEV_ALIGN)); +} + /* Set the sysfs physical device reference for the network logical device * if set prior to registration will cause a symlink during initialization. */ #define SET_NETDEV_DEV(net, pdev) ((net)->dev.parent = (pdev)) /* Set the sysfs device type for the network logical device to allow * fine-grained identification of different network device types. For * example Ethernet, Wireless LAN, Bluetooth, WiMAX etc. */ #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype)) /* Default NAPI poll() weight * Device drivers are strongly advised to not use bigger value