Merge tag '9p-for-5.3' of git://github.com/martinetd/linux
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 13 Jul 2019 00:31:19 +0000 (17:31 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 13 Jul 2019 00:31:19 +0000 (17:31 -0700)
Pull 9p updates from Dominique Martinet:
 "Two small fixes to properly cleanup the 9p transports list if
  virtio/xen module initialization fail.

  9p might otherwise try to access memory from a module that failed to
  register got freed"

* tag '9p-for-5.3' of git://github.com/martinetd/linux:
  9p/xen: Add cleanup path in p9_trans_xen_init
  9p/virtio: Add cleanup path in p9_virtio_init

1  2 
net/9p/trans_virtio.c
net/9p/trans_xen.c

diff --combined net/9p/trans_virtio.c
index 549938af02e780493c7f8ac4deb8a322ff1fafa3,6753ee9326b8d1144fe4a85834e8d8db1ed8d59b..a3cd90a74012be927c838dc1e9916f78538948fc
@@@ -1,4 -1,3 +1,4 @@@
 +// SPDX-License-Identifier: GPL-2.0-only
  /*
   * The Virtio 9p transport driver
   *
@@@ -9,6 -8,22 +9,6 @@@
   *
   *  Based on virtio console driver
   *  Copyright (C) 2006, 2007 Rusty Russell, IBM Corporation
 - *
 - *  This program is free software; you can redistribute it and/or modify
 - *  it under the terms of the GNU General Public License version 2
 - *  as published by the Free Software Foundation.
 - *
 - *  This program is distributed in the hope that it will be useful,
 - *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 - *  GNU General Public License for more details.
 - *
 - *  You should have received a copy of the GNU General Public License
 - *  along with this program; if not, write to:
 - *  Free Software Foundation
 - *  51 Franklin Street, Fifth Floor
 - *  Boston, MA  02111-1301  USA
 - *
   */
  
  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@@ -767,10 -782,16 +767,16 @@@ static struct p9_trans_module p9_virtio
  /* The standard init function */
  static int __init p9_virtio_init(void)
  {
+       int rc;
        INIT_LIST_HEAD(&virtio_chan_list);
  
        v9fs_register_trans(&p9_virtio_trans);
-       return register_virtio_driver(&p9_virtio_drv);
+       rc = register_virtio_driver(&p9_virtio_drv);
+       if (rc)
+               v9fs_unregister_trans(&p9_virtio_trans);
+       return rc;
  }
  
  static void __exit p9_virtio_cleanup(void)
diff --combined net/9p/trans_xen.c
index 29420ebb8f070acfa01c11b979285ecd6c2c82a2,9daab0dd833b31cbb663b7756970a545cc59f3cf..3963eb11c3fbdd841197f9d9ac7f9426db52ecba
@@@ -513,7 -513,7 +513,7 @@@ static void xen_9pfs_front_changed(stru
        case XenbusStateClosed:
                if (dev->state == XenbusStateClosed)
                        break;
 -              /* Missed the backend's CLOSING state -- fallthrough */
 +              /* fall through - Missed the backend's CLOSING state */
        case XenbusStateClosing:
                xenbus_frontend_closed(dev);
                break;
@@@ -530,13 -530,19 +530,19 @@@ static struct xenbus_driver xen_9pfs_fr
  
  static int p9_trans_xen_init(void)
  {
+       int rc;
        if (!xen_domain())
                return -ENODEV;
  
        pr_info("Initialising Xen transport for 9pfs\n");
  
        v9fs_register_trans(&p9_xen_trans);
-       return xenbus_register_frontend(&xen_9pfs_front_driver);
+       rc = xenbus_register_frontend(&xen_9pfs_front_driver);
+       if (rc)
+               v9fs_unregister_trans(&p9_xen_trans);
+       return rc;
  }
  module_init(p9_trans_xen_init);