hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/uio/uio.c
....@@ -274,7 +274,7 @@
274274 .dev_groups = uio_groups,
275275 };
276276
277
-bool uio_class_registered;
277
+static bool uio_class_registered;
278278
279279 /*
280280 * device functions
....@@ -398,7 +398,7 @@
398398
399399 static int uio_get_minor(struct uio_device *idev)
400400 {
401
- int retval = -ENOMEM;
401
+ int retval;
402402
403403 mutex_lock(&minor_lock);
404404 retval = idr_alloc(&uio_idr, idev, 0, UIO_MAX_DEVICES, GFP_KERNEL);
....@@ -491,10 +491,10 @@
491491 if (!idev->info) {
492492 mutex_unlock(&idev->info_lock);
493493 ret = -EINVAL;
494
- goto err_alloc_listener;
494
+ goto err_infoopen;
495495 }
496496
497
- if (idev->info && idev->info->open)
497
+ if (idev->info->open)
498498 ret = idev->info->open(idev->info, inode);
499499 mutex_unlock(&idev->info_lock);
500500 if (ret)
....@@ -569,20 +569,20 @@
569569 ssize_t retval = 0;
570570 s32 event_count;
571571
572
- mutex_lock(&idev->info_lock);
573
- if (!idev->info || !idev->info->irq)
574
- retval = -EIO;
575
- mutex_unlock(&idev->info_lock);
576
-
577
- if (retval)
578
- return retval;
579
-
580572 if (count != sizeof(s32))
581573 return -EINVAL;
582574
583575 add_wait_queue(&idev->wait, &wait);
584576
585577 do {
578
+ mutex_lock(&idev->info_lock);
579
+ if (!idev->info || !idev->info->irq) {
580
+ retval = -EIO;
581
+ mutex_unlock(&idev->info_lock);
582
+ break;
583
+ }
584
+ mutex_unlock(&idev->info_lock);
585
+
586586 set_current_state(TASK_INTERRUPTIBLE);
587587
588588 event_count = atomic_read(&idev->event);
....@@ -635,7 +635,7 @@
635635 goto out;
636636 }
637637
638
- if (!idev->info || !idev->info->irq) {
638
+ if (!idev->info->irq) {
639639 retval = -EIO;
640640 goto out;
641641 }
....@@ -670,7 +670,7 @@
670670 struct page *page;
671671 unsigned long offset;
672672 void *addr;
673
- int ret = 0;
673
+ vm_fault_t ret = 0;
674674 int mi;
675675
676676 mutex_lock(&idev->info_lock);
....@@ -738,7 +738,8 @@
738738 return -EINVAL;
739739
740740 vma->vm_ops = &uio_physical_vm_ops;
741
- vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
741
+ if (idev->info->mem[mi].memtype == UIO_MEM_PHYS)
742
+ vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
742743
743744 /*
744745 * We cannot use the vm_iomap_memory() helper here,
....@@ -795,18 +796,19 @@
795796 }
796797
797798 switch (idev->info->mem[mi].memtype) {
798
- case UIO_MEM_PHYS:
799
- ret = uio_mmap_physical(vma);
800
- break;
801
- case UIO_MEM_LOGICAL:
802
- case UIO_MEM_VIRTUAL:
803
- ret = uio_mmap_logical(vma);
804
- break;
805
- default:
806
- ret = -EINVAL;
799
+ case UIO_MEM_IOVA:
800
+ case UIO_MEM_PHYS:
801
+ ret = uio_mmap_physical(vma);
802
+ break;
803
+ case UIO_MEM_LOGICAL:
804
+ case UIO_MEM_VIRTUAL:
805
+ ret = uio_mmap_logical(vma);
806
+ break;
807
+ default:
808
+ ret = -EINVAL;
807809 }
808810
809
-out:
811
+ out:
810812 mutex_unlock(&idev->info_lock);
811813 return ret;
812814 }
....@@ -994,6 +996,44 @@
994996 }
995997 EXPORT_SYMBOL_GPL(__uio_register_device);
996998
999
+static void devm_uio_unregister_device(struct device *dev, void *res)
1000
+{
1001
+ uio_unregister_device(*(struct uio_info **)res);
1002
+}
1003
+
1004
+/**
1005
+ * devm_uio_register_device - Resource managed uio_register_device()
1006
+ * @owner: module that creates the new device
1007
+ * @parent: parent device
1008
+ * @info: UIO device capabilities
1009
+ *
1010
+ * returns zero on success or a negative error code.
1011
+ */
1012
+int __devm_uio_register_device(struct module *owner,
1013
+ struct device *parent,
1014
+ struct uio_info *info)
1015
+{
1016
+ struct uio_info **ptr;
1017
+ int ret;
1018
+
1019
+ ptr = devres_alloc(devm_uio_unregister_device, sizeof(*ptr),
1020
+ GFP_KERNEL);
1021
+ if (!ptr)
1022
+ return -ENOMEM;
1023
+
1024
+ *ptr = info;
1025
+ ret = __uio_register_device(owner, parent, info);
1026
+ if (ret) {
1027
+ devres_free(ptr);
1028
+ return ret;
1029
+ }
1030
+
1031
+ devres_add(parent, ptr);
1032
+
1033
+ return 0;
1034
+}
1035
+EXPORT_SYMBOL_GPL(__devm_uio_register_device);
1036
+
9971037 /**
9981038 * uio_unregister_device - unregister a industrial IO device
9991039 * @info: UIO device capabilities
....@@ -1019,6 +1059,9 @@
10191059 idev->info = NULL;
10201060 mutex_unlock(&idev->info_lock);
10211061
1062
+ wake_up_interruptible(&idev->wait);
1063
+ kill_fasync(&idev->async_queue, SIGIO, POLL_HUP);
1064
+
10221065 device_unregister(&idev->dev);
10231066
10241067 uio_free_minor(minor);