From patchwork Sat Sep 1 15:57:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Ott X-Patchwork-Id: 181145 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 425C42C0089 for ; Sun, 2 Sep 2012 01:59:03 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755584Ab2IAP6f (ORCPT ); Sat, 1 Sep 2012 11:58:35 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:60424 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753083Ab2IAP5T (ORCPT ); Sat, 1 Sep 2012 11:57:19 -0400 Received: from compute4.internal (compute4.nyi.mail.srv.osa [10.202.2.44]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 1CEB520FE4; Sat, 1 Sep 2012 11:57:19 -0400 (EDT) Received: from frontend2.nyi.mail.srv.osa ([10.202.2.161]) by compute4.internal (MEProxy); Sat, 01 Sep 2012 11:57:19 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=signal11.us; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=olz8edeUO1VMZNI9f3uupFS42Og=; b=oUjC51cj+3k8S5i2Ecjfs W87msoVVVq+YWAgdSAA8srXSOU4ZS3mDAyZ+wgjgmFWuAlH5h9xMf5QnmipcY+Or Uupk726mION9iz6mt6JvjXE+pO6/mhVCmQDe9TOYGgNSre5Idtk5KMaT+38kVQPE rGjD6fxdi5Y+Mhd42oGDKs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=from:to:cc:subject:date:message-id :in-reply-to:references; s=smtpout; bh=olz8edeUO1VMZNI9f3uupFS42 Og=; b=HogUU5JDjHdfTFftZKBXvx+QZd0r+rDu+rz1mDKqLQ4V26//BLUsQ70oJ 8pymbwdHB8psKgnV74+hhAUwveXQq+ezYUgmdlN0L9B2YEBP5G3eaeU+Zt94zCOJ l7/egQPfCT8QnSRKHW3Ou/9nbat5xyEf97qTX2lo2BmG7PPtXY= X-Sasl-enc: h/NaTAEXzc4q9DflIwIz2EcTFp43HY6oIQvkIXmimCBW 1346515038 Received: from localhost.localdomain (unknown [68.62.240.236]) by mail.messagingengine.com (Postfix) with ESMTPA id 50C1B4827CB; Sat, 1 Sep 2012 11:57:18 -0400 (EDT) From: Alan Ott To: Alexander Smirnov , Dmitry Eremin-Solenikov , "David S. Miller" , Tony Cheneau Cc: linux-zigbee-devel@lists.sourceforge.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alan Ott Subject: [PATCH v3 2/2] 6lowpan: handle NETDEV_UNREGISTER event Date: Sat, 1 Sep 2012 11:57:07 -0400 Message-Id: <1346515027-5237-3-git-send-email-alan@signal11.us> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1346294341-26808-1-git-send-email-alan@signal11.us> References: <1346294341-26808-1-git-send-email-alan@signal11.us> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Before, it was impossible to remove a wpan device which had lowpan attached to it. Signed-off-by: Alan Ott --- net/ieee802154/6lowpan.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 files changed, 37 insertions(+), 7 deletions(-) diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c index b28ec79..d529111 100644 --- a/net/ieee802154/6lowpan.c +++ b/net/ieee802154/6lowpan.c @@ -1063,12 +1063,6 @@ out: return (err < 0 ? NETDEV_TX_BUSY : NETDEV_TX_OK); } -static void lowpan_dev_free(struct net_device *dev) -{ - dev_put(lowpan_dev_info(dev)->real_dev); - free_netdev(dev); -} - static struct wpan_phy *lowpan_get_phy(const struct net_device *dev) { struct net_device *real_dev = lowpan_dev_info(dev)->real_dev; @@ -1118,7 +1112,7 @@ static void lowpan_setup(struct net_device *dev) dev->netdev_ops = &lowpan_netdev_ops; dev->header_ops = &lowpan_header_ops; dev->ml_priv = &lowpan_mlme; - dev->destructor = lowpan_dev_free; + dev->destructor = free_netdev; } static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[]) @@ -1244,6 +1238,34 @@ static inline void __init lowpan_netlink_fini(void) rtnl_link_unregister(&lowpan_link_ops); } +static int lowpan_device_event(struct notifier_block *unused, + unsigned long event, + void *ptr) +{ + struct net_device *dev = ptr; + LIST_HEAD(del_list); + struct lowpan_dev_record *entry, *tmp; + + if (dev->type != ARPHRD_IEEE802154) + goto out; + + if (event == NETDEV_UNREGISTER) { + list_for_each_entry_safe(entry, tmp, &lowpan_devices, list) { + if (lowpan_dev_info(entry->ldev)->real_dev == dev) + lowpan_dellink(entry->ldev, &del_list); + } + + unregister_netdevice_many(&del_list); + }; + +out: + return NOTIFY_DONE; +} + +static struct notifier_block lowpan_dev_notifier = { + .notifier_call = lowpan_device_event, +}; + static struct packet_type lowpan_packet_type = { .type = __constant_htons(ETH_P_IEEE802154), .func = lowpan_rcv, @@ -1258,6 +1280,12 @@ static int __init lowpan_init_module(void) goto out; dev_add_pack(&lowpan_packet_type); + + err = register_netdevice_notifier(&lowpan_dev_notifier); + if (err < 0) { + dev_remove_pack(&lowpan_packet_type); + lowpan_netlink_fini(); + } out: return err; } @@ -1270,6 +1298,8 @@ static void __exit lowpan_cleanup_module(void) dev_remove_pack(&lowpan_packet_type); + unregister_netdevice_notifier(&lowpan_dev_notifier); + /* Now 6lowpan packet_type is removed, so no new fragments are * expected on RX, therefore that's the time to clean incomplete * fragments.