hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/usb/gadget/legacy/inode.c
....@@ -12,6 +12,7 @@
1212 #include <linux/init.h>
1313 #include <linux/module.h>
1414 #include <linux/fs.h>
15
+#include <linux/fs_context.h>
1516 #include <linux/pagemap.h>
1617 #include <linux/uts.h>
1718 #include <linux/wait.h>
....@@ -20,7 +21,7 @@
2021 #include <linux/sched.h>
2122 #include <linux/slab.h>
2223 #include <linux/poll.h>
23
-#include <linux/mmu_context.h>
24
+#include <linux/kthread.h>
2425 #include <linux/aio.h>
2526 #include <linux/uio.h>
2627 #include <linux/refcount.h>
....@@ -313,7 +314,7 @@
313314 case STATE_EP_READY: /* not configured yet */
314315 if (is_write)
315316 return 0;
316
- // FALLTHRU
317
+ fallthrough;
317318 case STATE_EP_UNBOUND: /* clean disconnect */
318319 break;
319320 // case STATE_EP_DISABLED: /* "can't happen" */
....@@ -345,7 +346,7 @@
345346 spin_unlock_irq (&epdata->dev->lock);
346347
347348 if (likely (value == 0)) {
348
- value = wait_event_interruptible (done.wait, done.done);
349
+ value = wait_for_completion_interruptible(&done);
349350 if (value != 0) {
350351 spin_lock_irq (&epdata->dev->lock);
351352 if (likely (epdata->ep != NULL)) {
....@@ -354,13 +355,14 @@
354355 usb_ep_dequeue (epdata->ep, epdata->req);
355356 spin_unlock_irq (&epdata->dev->lock);
356357
357
- wait_event (done.wait, done.done);
358
+ wait_for_completion(&done);
358359 if (epdata->status == -ECONNRESET)
359360 epdata->status = -EINTR;
360361 } else {
361362 spin_unlock_irq (&epdata->dev->lock);
362363
363364 DBG (epdata->dev, "endpoint gone\n");
365
+ wait_for_completion(&done);
364366 epdata->status = -ENODEV;
365367 }
366368 }
....@@ -463,9 +465,9 @@
463465 struct kiocb *iocb = priv->iocb;
464466 size_t ret;
465467
466
- use_mm(mm);
468
+ kthread_use_mm(mm);
467469 ret = copy_to_iter(priv->buf, priv->actual, &priv->to);
468
- unuse_mm(mm);
470
+ kthread_unuse_mm(mm);
469471 if (!ret)
470472 ret = -EFAULT;
471473
....@@ -1085,7 +1087,7 @@
10851087 case GADGETFS_DISCONNECT:
10861088 if (dev->state == STATE_DEV_SETUP)
10871089 dev->setup_abort = 1;
1088
- // FALL THROUGH
1090
+ fallthrough;
10891091 case GADGETFS_CONNECT:
10901092 dev->ev_next = 0;
10911093 break;
....@@ -1220,27 +1222,27 @@
12201222 if (dev->state <= STATE_DEV_OPENED)
12211223 return DEFAULT_POLLMASK;
12221224
1223
- poll_wait(fd, &dev->wait, wait);
1225
+ poll_wait(fd, &dev->wait, wait);
12241226
1225
- spin_lock_irq (&dev->lock);
1227
+ spin_lock_irq(&dev->lock);
12261228
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
+ }
12331235
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
+ }
12411243 out:
1242
- spin_unlock_irq(&dev->lock);
1243
- return mask;
1244
+ spin_unlock_irq(&dev->lock);
1245
+ return mask;
12441246 }
12451247
12461248 static long dev_ioctl (struct file *fd, unsigned code, unsigned long value)
....@@ -1394,7 +1396,6 @@
13941396 make_qualifier (dev);
13951397 break;
13961398 case USB_DT_OTHER_SPEED_CONFIG:
1397
- // FALLTHROUGH
13981399 case USB_DT_CONFIG:
13991400 value = config_buf (dev,
14001401 w_value >> 8,
....@@ -1731,7 +1732,7 @@
17311732 case STATE_DEV_UNCONNECTED:
17321733 next_event (dev, GADGETFS_SUSPEND);
17331734 ep0_readable (dev);
1734
- /* FALLTHROUGH */
1735
+ fallthrough;
17351736 default:
17361737 break;
17371738 }
....@@ -1748,7 +1749,7 @@
17481749 .suspend = gadgetfs_suspend,
17491750
17501751 .driver = {
1751
- .name = (char *) shortname,
1752
+ .name = shortname,
17521753 },
17531754 };
17541755
....@@ -1828,8 +1829,9 @@
18281829 spin_lock_irq (&dev->lock);
18291830 value = -EINVAL;
18301831 if (dev->buf) {
1832
+ spin_unlock_irq(&dev->lock);
18311833 kfree(kbuf);
1832
- goto fail;
1834
+ return value;
18331835 }
18341836 dev->buf = kbuf;
18351837
....@@ -1876,8 +1878,8 @@
18761878
18771879 value = usb_gadget_probe_driver(&gadgetfs_driver);
18781880 if (value != 0) {
1879
- kfree (dev->buf);
1880
- dev->buf = NULL;
1881
+ spin_lock_irq(&dev->lock);
1882
+ goto fail;
18811883 } else {
18821884 /* at this point "good" hardware has for the first time
18831885 * let the USB the host see us. alternatively, if users
....@@ -1894,6 +1896,9 @@
18941896 return value;
18951897
18961898 fail:
1899
+ dev->config = NULL;
1900
+ dev->hs_config = NULL;
1901
+ dev->dev = NULL;
18971902 spin_unlock_irq (&dev->lock);
18981903 pr_debug ("%s: %s fail %zd, %p\n", shortname, __func__, value, dev);
18991904 kfree (dev->buf);
....@@ -2003,7 +2008,7 @@
20032008 };
20042009
20052010 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)
20072012 {
20082013 struct inode *inode;
20092014 struct dev_data *dev;
....@@ -2060,11 +2065,19 @@
20602065 }
20612066
20622067 /* "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)
20662069 {
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;
20682081 }
20692082
20702083 static void
....@@ -2084,7 +2097,7 @@
20842097 static struct file_system_type gadgetfs_type = {
20852098 .owner = THIS_MODULE,
20862099 .name = shortname,
2087
- .mount = gadgetfs_mount,
2100
+ .init_fs_context = gadgetfs_init_fs_context,
20882101 .kill_sb = gadgetfs_kill_sb,
20892102 };
20902103 MODULE_ALIAS_FS("gadgetfs");