| .. | .. |
|---|
| 12 | 12 | #include <linux/init.h> |
|---|
| 13 | 13 | #include <linux/module.h> |
|---|
| 14 | 14 | #include <linux/fs.h> |
|---|
| 15 | +#include <linux/fs_context.h> |
|---|
| 15 | 16 | #include <linux/pagemap.h> |
|---|
| 16 | 17 | #include <linux/uts.h> |
|---|
| 17 | 18 | #include <linux/wait.h> |
|---|
| .. | .. |
|---|
| 20 | 21 | #include <linux/sched.h> |
|---|
| 21 | 22 | #include <linux/slab.h> |
|---|
| 22 | 23 | #include <linux/poll.h> |
|---|
| 23 | | -#include <linux/mmu_context.h> |
|---|
| 24 | +#include <linux/kthread.h> |
|---|
| 24 | 25 | #include <linux/aio.h> |
|---|
| 25 | 26 | #include <linux/uio.h> |
|---|
| 26 | 27 | #include <linux/refcount.h> |
|---|
| .. | .. |
|---|
| 313 | 314 | case STATE_EP_READY: /* not configured yet */ |
|---|
| 314 | 315 | if (is_write) |
|---|
| 315 | 316 | return 0; |
|---|
| 316 | | - // FALLTHRU |
|---|
| 317 | + fallthrough; |
|---|
| 317 | 318 | case STATE_EP_UNBOUND: /* clean disconnect */ |
|---|
| 318 | 319 | break; |
|---|
| 319 | 320 | // case STATE_EP_DISABLED: /* "can't happen" */ |
|---|
| .. | .. |
|---|
| 345 | 346 | spin_unlock_irq (&epdata->dev->lock); |
|---|
| 346 | 347 | |
|---|
| 347 | 348 | if (likely (value == 0)) { |
|---|
| 348 | | - value = swait_event_interruptible_exclusive(done.wait, done.done); |
|---|
| 349 | + value = wait_for_completion_interruptible(&done); |
|---|
| 349 | 350 | if (value != 0) { |
|---|
| 350 | 351 | spin_lock_irq (&epdata->dev->lock); |
|---|
| 351 | 352 | if (likely (epdata->ep != NULL)) { |
|---|
| .. | .. |
|---|
| 354 | 355 | usb_ep_dequeue (epdata->ep, epdata->req); |
|---|
| 355 | 356 | spin_unlock_irq (&epdata->dev->lock); |
|---|
| 356 | 357 | |
|---|
| 357 | | - swait_event_exclusive(done.wait, done.done); |
|---|
| 358 | + wait_for_completion(&done); |
|---|
| 358 | 359 | if (epdata->status == -ECONNRESET) |
|---|
| 359 | 360 | epdata->status = -EINTR; |
|---|
| 360 | 361 | } else { |
|---|
| 361 | 362 | spin_unlock_irq (&epdata->dev->lock); |
|---|
| 362 | 363 | |
|---|
| 363 | 364 | DBG (epdata->dev, "endpoint gone\n"); |
|---|
| 365 | + wait_for_completion(&done); |
|---|
| 364 | 366 | epdata->status = -ENODEV; |
|---|
| 365 | 367 | } |
|---|
| 366 | 368 | } |
|---|
| .. | .. |
|---|
| 463 | 465 | struct kiocb *iocb = priv->iocb; |
|---|
| 464 | 466 | size_t ret; |
|---|
| 465 | 467 | |
|---|
| 466 | | - use_mm(mm); |
|---|
| 468 | + kthread_use_mm(mm); |
|---|
| 467 | 469 | ret = copy_to_iter(priv->buf, priv->actual, &priv->to); |
|---|
| 468 | | - unuse_mm(mm); |
|---|
| 470 | + kthread_unuse_mm(mm); |
|---|
| 469 | 471 | if (!ret) |
|---|
| 470 | 472 | ret = -EFAULT; |
|---|
| 471 | 473 | |
|---|
| .. | .. |
|---|
| 1085 | 1087 | case GADGETFS_DISCONNECT: |
|---|
| 1086 | 1088 | if (dev->state == STATE_DEV_SETUP) |
|---|
| 1087 | 1089 | dev->setup_abort = 1; |
|---|
| 1088 | | - // FALL THROUGH |
|---|
| 1090 | + fallthrough; |
|---|
| 1089 | 1091 | case GADGETFS_CONNECT: |
|---|
| 1090 | 1092 | dev->ev_next = 0; |
|---|
| 1091 | 1093 | break; |
|---|
| .. | .. |
|---|
| 1220 | 1222 | if (dev->state <= STATE_DEV_OPENED) |
|---|
| 1221 | 1223 | return DEFAULT_POLLMASK; |
|---|
| 1222 | 1224 | |
|---|
| 1223 | | - poll_wait(fd, &dev->wait, wait); |
|---|
| 1225 | + poll_wait(fd, &dev->wait, wait); |
|---|
| 1224 | 1226 | |
|---|
| 1225 | | - spin_lock_irq (&dev->lock); |
|---|
| 1227 | + spin_lock_irq(&dev->lock); |
|---|
| 1226 | 1228 | |
|---|
| 1227 | | - /* report fd mode change before acting on it */ |
|---|
| 1228 | | - if (dev->setup_abort) { |
|---|
| 1229 | | - dev->setup_abort = 0; |
|---|
| 1230 | | - mask = EPOLLHUP; |
|---|
| 1231 | | - goto out; |
|---|
| 1232 | | - } |
|---|
| 1229 | + /* report fd mode change before acting on it */ |
|---|
| 1230 | + if (dev->setup_abort) { |
|---|
| 1231 | + dev->setup_abort = 0; |
|---|
| 1232 | + mask = EPOLLHUP; |
|---|
| 1233 | + goto out; |
|---|
| 1234 | + } |
|---|
| 1233 | 1235 | |
|---|
| 1234 | | - if (dev->state == STATE_DEV_SETUP) { |
|---|
| 1235 | | - if (dev->setup_in || dev->setup_can_stall) |
|---|
| 1236 | | - mask = EPOLLOUT; |
|---|
| 1237 | | - } else { |
|---|
| 1238 | | - if (dev->ev_next != 0) |
|---|
| 1239 | | - mask = EPOLLIN; |
|---|
| 1240 | | - } |
|---|
| 1236 | + if (dev->state == STATE_DEV_SETUP) { |
|---|
| 1237 | + if (dev->setup_in || dev->setup_can_stall) |
|---|
| 1238 | + mask = EPOLLOUT; |
|---|
| 1239 | + } else { |
|---|
| 1240 | + if (dev->ev_next != 0) |
|---|
| 1241 | + mask = EPOLLIN; |
|---|
| 1242 | + } |
|---|
| 1241 | 1243 | out: |
|---|
| 1242 | | - spin_unlock_irq(&dev->lock); |
|---|
| 1243 | | - return mask; |
|---|
| 1244 | + spin_unlock_irq(&dev->lock); |
|---|
| 1245 | + return mask; |
|---|
| 1244 | 1246 | } |
|---|
| 1245 | 1247 | |
|---|
| 1246 | 1248 | static long dev_ioctl (struct file *fd, unsigned code, unsigned long value) |
|---|
| .. | .. |
|---|
| 1394 | 1396 | make_qualifier (dev); |
|---|
| 1395 | 1397 | break; |
|---|
| 1396 | 1398 | case USB_DT_OTHER_SPEED_CONFIG: |
|---|
| 1397 | | - // FALLTHROUGH |
|---|
| 1398 | 1399 | case USB_DT_CONFIG: |
|---|
| 1399 | 1400 | value = config_buf (dev, |
|---|
| 1400 | 1401 | w_value >> 8, |
|---|
| .. | .. |
|---|
| 1731 | 1732 | case STATE_DEV_UNCONNECTED: |
|---|
| 1732 | 1733 | next_event (dev, GADGETFS_SUSPEND); |
|---|
| 1733 | 1734 | ep0_readable (dev); |
|---|
| 1734 | | - /* FALLTHROUGH */ |
|---|
| 1735 | + fallthrough; |
|---|
| 1735 | 1736 | default: |
|---|
| 1736 | 1737 | break; |
|---|
| 1737 | 1738 | } |
|---|
| .. | .. |
|---|
| 1748 | 1749 | .suspend = gadgetfs_suspend, |
|---|
| 1749 | 1750 | |
|---|
| 1750 | 1751 | .driver = { |
|---|
| 1751 | | - .name = (char *) shortname, |
|---|
| 1752 | + .name = shortname, |
|---|
| 1752 | 1753 | }, |
|---|
| 1753 | 1754 | }; |
|---|
| 1754 | 1755 | |
|---|
| .. | .. |
|---|
| 1828 | 1829 | spin_lock_irq (&dev->lock); |
|---|
| 1829 | 1830 | value = -EINVAL; |
|---|
| 1830 | 1831 | if (dev->buf) { |
|---|
| 1832 | + spin_unlock_irq(&dev->lock); |
|---|
| 1831 | 1833 | kfree(kbuf); |
|---|
| 1832 | | - goto fail; |
|---|
| 1834 | + return value; |
|---|
| 1833 | 1835 | } |
|---|
| 1834 | 1836 | dev->buf = kbuf; |
|---|
| 1835 | 1837 | |
|---|
| .. | .. |
|---|
| 1876 | 1878 | |
|---|
| 1877 | 1879 | value = usb_gadget_probe_driver(&gadgetfs_driver); |
|---|
| 1878 | 1880 | if (value != 0) { |
|---|
| 1879 | | - kfree (dev->buf); |
|---|
| 1880 | | - dev->buf = NULL; |
|---|
| 1881 | + spin_lock_irq(&dev->lock); |
|---|
| 1882 | + goto fail; |
|---|
| 1881 | 1883 | } else { |
|---|
| 1882 | 1884 | /* at this point "good" hardware has for the first time |
|---|
| 1883 | 1885 | * let the USB the host see us. alternatively, if users |
|---|
| .. | .. |
|---|
| 1894 | 1896 | return value; |
|---|
| 1895 | 1897 | |
|---|
| 1896 | 1898 | fail: |
|---|
| 1899 | + dev->config = NULL; |
|---|
| 1900 | + dev->hs_config = NULL; |
|---|
| 1901 | + dev->dev = NULL; |
|---|
| 1897 | 1902 | spin_unlock_irq (&dev->lock); |
|---|
| 1898 | 1903 | pr_debug ("%s: %s fail %zd, %p\n", shortname, __func__, value, dev); |
|---|
| 1899 | 1904 | kfree (dev->buf); |
|---|
| .. | .. |
|---|
| 2003 | 2008 | }; |
|---|
| 2004 | 2009 | |
|---|
| 2005 | 2010 | static int |
|---|
| 2006 | | -gadgetfs_fill_super (struct super_block *sb, void *opts, int silent) |
|---|
| 2011 | +gadgetfs_fill_super (struct super_block *sb, struct fs_context *fc) |
|---|
| 2007 | 2012 | { |
|---|
| 2008 | 2013 | struct inode *inode; |
|---|
| 2009 | 2014 | struct dev_data *dev; |
|---|
| .. | .. |
|---|
| 2060 | 2065 | } |
|---|
| 2061 | 2066 | |
|---|
| 2062 | 2067 | /* "mount -t gadgetfs path /dev/gadget" ends up here */ |
|---|
| 2063 | | -static struct dentry * |
|---|
| 2064 | | -gadgetfs_mount (struct file_system_type *t, int flags, |
|---|
| 2065 | | - const char *path, void *opts) |
|---|
| 2068 | +static int gadgetfs_get_tree(struct fs_context *fc) |
|---|
| 2066 | 2069 | { |
|---|
| 2067 | | - return mount_single (t, flags, opts, gadgetfs_fill_super); |
|---|
| 2070 | + return get_tree_single(fc, gadgetfs_fill_super); |
|---|
| 2071 | +} |
|---|
| 2072 | + |
|---|
| 2073 | +static const struct fs_context_operations gadgetfs_context_ops = { |
|---|
| 2074 | + .get_tree = gadgetfs_get_tree, |
|---|
| 2075 | +}; |
|---|
| 2076 | + |
|---|
| 2077 | +static int gadgetfs_init_fs_context(struct fs_context *fc) |
|---|
| 2078 | +{ |
|---|
| 2079 | + fc->ops = &gadgetfs_context_ops; |
|---|
| 2080 | + return 0; |
|---|
| 2068 | 2081 | } |
|---|
| 2069 | 2082 | |
|---|
| 2070 | 2083 | static void |
|---|
| .. | .. |
|---|
| 2084 | 2097 | static struct file_system_type gadgetfs_type = { |
|---|
| 2085 | 2098 | .owner = THIS_MODULE, |
|---|
| 2086 | 2099 | .name = shortname, |
|---|
| 2087 | | - .mount = gadgetfs_mount, |
|---|
| 2100 | + .init_fs_context = gadgetfs_init_fs_context, |
|---|
| 2088 | 2101 | .kill_sb = gadgetfs_kill_sb, |
|---|
| 2089 | 2102 | }; |
|---|
| 2090 | 2103 | MODULE_ALIAS_FS("gadgetfs"); |
|---|