From patchwork Wed Oct 18 12:06:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrik Flykt X-Patchwork-Id: 10014497 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 22F2860215 for ; Wed, 18 Oct 2017 12:06:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21E5328B27 for ; Wed, 18 Oct 2017 12:06:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16A3928B28; Wed, 18 Oct 2017 12:06:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BED328B10 for ; Wed, 18 Oct 2017 12:06:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933946AbdJRMGU (ORCPT ); Wed, 18 Oct 2017 08:06:20 -0400 Received: from mga02.intel.com ([134.134.136.20]:43071 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933908AbdJRMGS (ORCPT ); Wed, 18 Oct 2017 08:06:18 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Oct 2017 05:06:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,396,1503385200"; d="scan'208";a="1026441370" Received: from pflykt-mobl1.fi.intel.com (HELO pflykt-mobl1.ger.corp.intel.com) ([10.237.66.139]) by orsmga003.jf.intel.com with ESMTP; 18 Oct 2017 05:06:16 -0700 Received: by pflykt-mobl1.ger.corp.intel.com (Postfix, from userid 1100) id 8F7A6320086; Wed, 18 Oct 2017 15:06:15 +0300 (EEST) From: Patrik Flykt To: linux-bluetooth@vger.kernel.org, linux-wpan@vger.kernel.org Cc: luiz.von.dentz@intel.com Subject: [RFC 2/3] 6lowpan: Factor out lowpan device context initialization Date: Wed, 18 Oct 2017 15:06:14 +0300 Message-Id: <20171018120615.24126-3-patrik.flykt@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171018120615.24126-1-patrik.flykt@linux.intel.com> References: <20171018120615.24126-1-patrik.flykt@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - PL 281, 00181 Helsinki Sender: linux-wpan-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 6lowpan context initialization will be used in other places, factor it out without any changes in functionality. Signed-off-by: Patrik Flykt --- include/net/6lowpan.h | 2 ++ net/6lowpan/core.c | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/include/net/6lowpan.h b/include/net/6lowpan.h index 7f21e156c9d6..1df9ecf22a57 100644 --- a/include/net/6lowpan.h +++ b/include/net/6lowpan.h @@ -289,6 +289,8 @@ int lowpan_register_netdev(struct net_device *dev, void lowpan_unregister_netdevice(struct net_device *dev); void lowpan_unregister_netdev(struct net_device *dev); +int lowpan_initialize_ctx(struct lowpan_dev *ldev, enum lowpan_lltypes lltype); + /** * lowpan_header_decompress - replace 6LoWPAN header with IPv6 header * diff --git a/net/6lowpan/core.c b/net/6lowpan/core.c index 40d3d72beb53..29150a2c5e04 100644 --- a/net/6lowpan/core.c +++ b/net/6lowpan/core.c @@ -18,10 +18,24 @@ #include "6lowpan_i.h" +int lowpan_initialize_ctx(struct lowpan_dev *ldev, enum lowpan_lltypes lltype) +{ + int i; + + ldev->lltype = lltype; + + spin_lock_init(&ldev->ctx.lock); + for (i = 0; i < LOWPAN_IPHC_CTX_TABLE_SIZE; i++) + ldev->ctx.table[i].id = i; + + return 0; +} +EXPORT_SYMBOL(lowpan_initialize_ctx); + int lowpan_register_netdevice(struct net_device *dev, enum lowpan_lltypes lltype) { - int i, ret; + int ret; switch (lltype) { case LOWPAN_LLTYPE_IEEE802154: @@ -36,11 +50,7 @@ int lowpan_register_netdevice(struct net_device *dev, dev->type = ARPHRD_6LOWPAN; dev->mtu = IPV6_MIN_MTU; - lowpan_dev(dev)->lltype = lltype; - - spin_lock_init(&lowpan_dev(dev)->ctx.lock); - for (i = 0; i < LOWPAN_IPHC_CTX_TABLE_SIZE; i++) - lowpan_dev(dev)->ctx.table[i].id = i; + lowpan_initialize_ctx(lowpan_dev(dev), lltype); dev->ndisc_ops = &lowpan_ndisc_ops;