From patchwork Thu Jun 22 07:31:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arend van Spriel X-Patchwork-Id: 9803695 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 7214660329 for ; Thu, 22 Jun 2017 07:31:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B73C285ED for ; Thu, 22 Jun 2017 07:31:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EB8E2861A; Thu, 22 Jun 2017 07:31:20 +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 B8BA7285ED for ; Thu, 22 Jun 2017 07:31:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751152AbdFVHbT (ORCPT ); Thu, 22 Jun 2017 03:31:19 -0400 Received: from lpdvrndsmtp01.broadcom.com ([192.19.229.170]:54301 "EHLO rnd-relay.smtp.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751115AbdFVHbT (ORCPT ); Thu, 22 Jun 2017 03:31:19 -0400 Received: from mail-irv-17.broadcom.com (mail-irv-17.lvn.broadcom.net [10.75.224.233]) by rnd-relay.smtp.broadcom.com (Postfix) with ESMTP id 1E33A30C039; Thu, 22 Jun 2017 00:31:18 -0700 (PDT) Received: from jenkins-cam-14.cam.broadcom.com (jenkins-cam-14.cam.broadcom.com [10.177.128.77]) by mail-irv-17.broadcom.com (Postfix) with ESMTP id E7B1F81EA4; Thu, 22 Jun 2017 00:31:17 -0700 (PDT) Received: by jenkins-cam-14.cam.broadcom.com (Postfix, from userid 25152) id C914CB8289A; Thu, 22 Jun 2017 08:31:16 +0100 (BST) From: Arend van Spriel To: Johannes Berg Cc: backports@vger.kernel.org, Arend van Spriel Subject: [PATCH V3] backport: handle change in netdevice destructor usage Date: Thu, 22 Jun 2017 08:31:04 +0100 Message-Id: <1498116664-18399-1-git-send-email-arend.vanspriel@broadcom.com> X-Mailer: git-send-email 1.9.1 Sender: backports-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: backports@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch deals with changes made in struct net_device by commit cf124db566e6 ("net: Fix inconsistent teardown and release of private netdev state."). Signed-off-by: Arend van Spriel --- After a (somewhat) good night sleep here is V3. Regards, Arend changes: V2: - changed netdev_set_priv_destructor() to macro. - revised semantic patch covering drivers only needing free_netdev(). - used some tricks suggested by Julia in semantic patch. - added more version checks against 4.13. V3: - fixed netdev_set_priv_destructor() for >= 4.13. --- backport/backport-include/linux/netdevice.h | 10 ++++ patches/0079-netdev-destructor.cocci | 84 +++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 patches/0079-netdev-destructor.cocci diff --git a/backport/backport-include/linux/netdevice.h b/backport/backport-include/linux/netdevice.h index 06230b5..98e781e 100644 --- a/backport/backport-include/linux/netdevice.h +++ b/backport/backport-include/linux/netdevice.h @@ -320,4 +320,14 @@ static inline void netif_trans_update(struct net_device *dev) } #endif +#if LINUX_VERSION_IS_LESS(4,13,0) +#define netdev_set_priv_destructor(_dev, _destructor) \ + (_dev)->destructor = __ ## _destructor +#else +#define netdev_set_priv_destructor(_dev, _destructor) \ + (_dev)->needs_free_netdev = true; \ + if ((_destructor) != free_netdev) \ + (_dev)->priv_destructor = (_destructor); +#endif + #endif /* __BACKPORT_NETDEVICE_H */ diff --git a/patches/0079-netdev-destructor.cocci b/patches/0079-netdev-destructor.cocci new file mode 100644 index 0000000..fab8af1 --- /dev/null +++ b/patches/0079-netdev-destructor.cocci @@ -0,0 +1,84 @@ +@r1@ +struct net_device *NDEV; +identifier D, C; +identifier TRUE =~ "true"; +@@ +C(...) +{ + <... +- NDEV->needs_free_netdev = TRUE; +- NDEV->priv_destructor = D; ++ netdev_set_priv_destructor(NDEV, D); + ...> +} + +@r2 depends on r1@ +identifier r1.D, r1.C; +fresh identifier E = "__" ## D; +@@ + ++#if LINUX_VERSION_IS_LESS(4,13,0) ++static void E(struct net_device *ndev) ++{ ++ D(ndev); ++ free_netdev(ndev); ++} ++#endif ++ +C(...) +{ + ... +} + +@r3 depends on r1@ +type T; +identifier NDEV; +identifier r1.D; +T RET; +@@ + +RET = \(register_netdevice\|register_ndev\)(NDEV); +if (<+... RET ...+>) { + <... ++#if LINUX_VERSION_IS_LESS(4,13,0) ++ D(NDEV); ++#endif + free_netdev(NDEV); + ...> +} + +@r4 depends on r1@ +identifier NDEV; +identifier r1.D; +type T; +T RET; +@@ + +if (...) + RET = register_netdevice(NDEV); +else + RET = register_netdev(NDEV); +if (<+... RET ...+>) { + <... ++#if LINUX_VERSION_IS_LESS(4,13,0) ++ D(NDEV); ++#endif + free_netdev(NDEV); + ...> +} + +@r5@ +struct net_device *NDEV; +identifier TRUE =~ "true"; +@@ + +-NDEV->needs_free_netdev = TRUE; ++netdev_set_priv_destructor(NDEV, free_netdev); + +@r6@ +struct net_device *NDEV; +identifier D; +@@ + +-NDEV->priv_destructor = D; ++netdev_set_priv_destructor(NDEV, D);