From 497b46dbc660d53e94abf8a46cda9747023802ba Mon Sep 17 00:00:00 2001 From: Fengguang Wu Date: Mon, 2 Sep 2013 10:38:33 +0200 Subject: drivers: uio: mf624_disable_interrupt() can be static Signed-off-by: Fengguang Wu Signed-off-by: Rostislav Lisovy Signed-off-by: Greg Kroah-Hartman --- drivers/uio/uio_mf624.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/uio') diff --git a/drivers/uio/uio_mf624.c b/drivers/uio/uio_mf624.c index a1768b2f4493..92cf6a9f6871 100644 --- a/drivers/uio/uio_mf624.c +++ b/drivers/uio/uio_mf624.c @@ -42,7 +42,7 @@ enum mf624_interrupt_source {ADC, CTR4, ALL}; -void mf624_disable_interrupt(enum mf624_interrupt_source source, +static void mf624_disable_interrupt(enum mf624_interrupt_source source, struct uio_info *info) { void __iomem *INTCSR_reg = info->mem[0].internal_addr + INTCSR; @@ -70,7 +70,7 @@ void mf624_disable_interrupt(enum mf624_interrupt_source source, } } -void mf624_enable_interrupt(enum mf624_interrupt_source source, +static void mf624_enable_interrupt(enum mf624_interrupt_source source, struct uio_info *info) { void __iomem *INTCSR_reg = info->mem[0].internal_addr + INTCSR; -- cgit v1.2.2 From e6789cd3dfb553077606ccafeb05e0043f072481 Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Thu, 12 Sep 2013 07:39:59 +0200 Subject: uio: Simplify uio error path by using devres functions Using devres functions simplify driver error path. - Use devm_kzalloc - Use devm_request_irq Signed-off-by: Michal Simek Reviewed-by: Pavel Machek Signed-off-by: Greg Kroah-Hartman --- drivers/uio/uio.c | 16 ++++------------ drivers/uio/uio_pdrv_genirq.c | 34 ++++++++++------------------------ 2 files changed, 14 insertions(+), 36 deletions(-) (limited to 'drivers/uio') diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index ba475632c5fa..11d4e0a52579 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -796,10 +796,9 @@ int __uio_register_device(struct module *owner, info->uio_dev = NULL; - idev = kzalloc(sizeof(*idev), GFP_KERNEL); + idev = devm_kzalloc(parent, sizeof(*idev), GFP_KERNEL); if (!idev) { - ret = -ENOMEM; - goto err_kzalloc; + return -ENOMEM; } idev->owner = owner; @@ -809,7 +808,7 @@ int __uio_register_device(struct module *owner, ret = uio_get_minor(idev); if (ret) - goto err_get_minor; + return ret; idev->dev = device_create(&uio_class, parent, MKDEV(uio_major, idev->minor), idev, @@ -827,7 +826,7 @@ int __uio_register_device(struct module *owner, info->uio_dev = idev; if (info->irq && (info->irq != UIO_IRQ_CUSTOM)) { - ret = request_irq(info->irq, uio_interrupt, + ret = devm_request_irq(parent, info->irq, uio_interrupt, info->irq_flags, info->name, idev); if (ret) goto err_request_irq; @@ -841,9 +840,6 @@ err_uio_dev_add_attributes: device_destroy(&uio_class, MKDEV(uio_major, idev->minor)); err_device_create: uio_free_minor(idev); -err_get_minor: - kfree(idev); -err_kzalloc: return ret; } EXPORT_SYMBOL_GPL(__uio_register_device); @@ -864,13 +860,9 @@ void uio_unregister_device(struct uio_info *info) uio_free_minor(idev); - if (info->irq && (info->irq != UIO_IRQ_CUSTOM)) - free_irq(info->irq, idev); - uio_dev_del_attributes(idev); device_destroy(&uio_class, MKDEV(uio_major, idev->minor)); - kfree(idev); return; } diff --git a/drivers/uio/uio_pdrv_genirq.c b/drivers/uio/uio_pdrv_genirq.c index 90ff17a0202f..76669313e9a7 100644 --- a/drivers/uio/uio_pdrv_genirq.c +++ b/drivers/uio/uio_pdrv_genirq.c @@ -112,11 +112,11 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev) if (pdev->dev.of_node) { /* alloc uioinfo for one device */ - uioinfo = kzalloc(sizeof(*uioinfo), GFP_KERNEL); + uioinfo = devm_kzalloc(&pdev->dev, sizeof(*uioinfo), + GFP_KERNEL); if (!uioinfo) { - ret = -ENOMEM; dev_err(&pdev->dev, "unable to kmalloc\n"); - return ret; + return -ENOMEM; } uioinfo->name = pdev->dev.of_node->name; uioinfo->version = "devicetree"; @@ -125,20 +125,19 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev) if (!uioinfo || !uioinfo->name || !uioinfo->version) { dev_err(&pdev->dev, "missing platform_data\n"); - goto bad0; + return ret; } if (uioinfo->handler || uioinfo->irqcontrol || uioinfo->irq_flags & IRQF_SHARED) { dev_err(&pdev->dev, "interrupt configuration error\n"); - goto bad0; + return ret; } - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) { - ret = -ENOMEM; dev_err(&pdev->dev, "unable to kmalloc\n"); - goto bad0; + return -ENOMEM; } priv->uioinfo = uioinfo; @@ -153,7 +152,7 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev) uioinfo->irq = UIO_IRQ_NONE; else if (ret < 0) { dev_err(&pdev->dev, "failed to get IRQ\n"); - goto bad1; + return ret; } } @@ -209,20 +208,12 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev) ret = uio_register_device(&pdev->dev, priv->uioinfo); if (ret) { dev_err(&pdev->dev, "unable to register uio device\n"); - goto bad2; + pm_runtime_disable(&pdev->dev); + return ret; } platform_set_drvdata(pdev, priv); return 0; - bad2: - pm_runtime_disable(&pdev->dev); - bad1: - kfree(priv); - bad0: - /* kfree uioinfo for OF */ - if (pdev->dev.of_node) - kfree(uioinfo); - return ret; } static int uio_pdrv_genirq_remove(struct platform_device *pdev) @@ -235,11 +226,6 @@ static int uio_pdrv_genirq_remove(struct platform_device *pdev) priv->uioinfo->handler = NULL; priv->uioinfo->irqcontrol = NULL; - /* kfree uioinfo for OF */ - if (pdev->dev.of_node) - kfree(priv->uioinfo); - - kfree(priv); return 0; } -- cgit v1.2.2 From e56516867f3de862df5fd9cf30e54a0b73921e83 Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Thu, 12 Sep 2013 15:37:46 +0900 Subject: uio: uio_aec: remove unnecessary pci_set_drvdata() The driver core clears the driver data to NULL after device_release or on probe failure. Thus, it is not needed to manually clear the device driver data to NULL. Signed-off-by: Jingoo Han Signed-off-by: Greg Kroah-Hartman --- drivers/uio/uio_aec.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/uio') diff --git a/drivers/uio/uio_aec.c b/drivers/uio/uio_aec.c index f3611c2d83b6..1549fab633c6 100644 --- a/drivers/uio/uio_aec.c +++ b/drivers/uio/uio_aec.c @@ -147,7 +147,6 @@ static void remove(struct pci_dev *pdev) uio_unregister_device(info); pci_release_regions(pdev); pci_disable_device(pdev); - pci_set_drvdata(pdev, NULL); iounmap(info->priv); kfree(info); -- cgit v1.2.2 From 8a4c10f8ec89fa40b0de33ce3ebe00781d010f3d Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Thu, 12 Sep 2013 15:38:44 +0900 Subject: uio: uio_cif: remove unnecessary pci_set_drvdata() The driver core clears the driver data to NULL after device_release or on probe failure. Thus, it is not needed to manually clear the device driver data to NULL. Signed-off-by: Jingoo Han Signed-off-by: Greg Kroah-Hartman --- drivers/uio/uio_cif.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/uio') diff --git a/drivers/uio/uio_cif.c b/drivers/uio/uio_cif.c index 22cdf385ab33..30f533ce3758 100644 --- a/drivers/uio/uio_cif.c +++ b/drivers/uio/uio_cif.c @@ -106,7 +106,6 @@ static void hilscher_pci_remove(struct pci_dev *dev) uio_unregister_device(info); pci_release_regions(dev); pci_disable_device(dev); - pci_set_drvdata(dev, NULL); iounmap(info->mem[0].internal_addr); kfree (info); -- cgit v1.2.2 From 1129308885bb9031a2d714523368894338cf9e18 Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Thu, 12 Sep 2013 15:39:08 +0900 Subject: uio: uio_mf624: remove unnecessary pci_set_drvdata() The driver core clears the driver data to NULL after device_release or on probe failure. Thus, it is not needed to manually clear the device driver data to NULL. Signed-off-by: Jingoo Han Signed-off-by: Greg Kroah-Hartman --- drivers/uio/uio_mf624.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/uio') diff --git a/drivers/uio/uio_mf624.c b/drivers/uio/uio_mf624.c index 92cf6a9f6871..f764adbfe036 100644 --- a/drivers/uio/uio_mf624.c +++ b/drivers/uio/uio_mf624.c @@ -220,7 +220,6 @@ static void mf624_pci_remove(struct pci_dev *dev) uio_unregister_device(info); pci_release_regions(dev); pci_disable_device(dev); - pci_set_drvdata(dev, NULL); iounmap(info->mem[0].internal_addr); iounmap(info->mem[1].internal_addr); -- cgit v1.2.2 From c7a8eb001f4cdeeab912a9d59b02d93686998138 Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Thu, 12 Sep 2013 15:39:26 +0900 Subject: uio: uio_netx: remove unnecessary pci_set_drvdata() The driver core clears the driver data to NULL after device_release or on probe failure. Thus, it is not needed to manually clear the device driver data to NULL. Signed-off-by: Jingoo Han Signed-off-by: Greg Kroah-Hartman --- drivers/uio/uio_netx.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/uio') diff --git a/drivers/uio/uio_netx.c b/drivers/uio/uio_netx.c index 28a766b9e198..4c345db8b016 100644 --- a/drivers/uio/uio_netx.c +++ b/drivers/uio/uio_netx.c @@ -127,7 +127,6 @@ static void netx_pci_remove(struct pci_dev *dev) uio_unregister_device(info); pci_release_regions(dev); pci_disable_device(dev); - pci_set_drvdata(dev, NULL); iounmap(info->mem[0].internal_addr); kfree(info); -- cgit v1.2.2 From 37ecdbb012bf3a466d4dda85a93d1c69dc483d3a Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Thu, 12 Sep 2013 15:39:55 +0900 Subject: uio: uio_sercos3: remove unnecessary pci_set_drvdata() The driver core clears the driver data to NULL after device_release or on probe failure. Thus, it is not needed to manually clear the device driver data to NULL. Signed-off-by: Jingoo Han Signed-off-by: Greg Kroah-Hartman --- drivers/uio/uio_sercos3.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/uio') diff --git a/drivers/uio/uio_sercos3.c b/drivers/uio/uio_sercos3.c index 541983217085..9cfdfcafa262 100644 --- a/drivers/uio/uio_sercos3.c +++ b/drivers/uio/uio_sercos3.c @@ -188,7 +188,6 @@ static void sercos3_pci_remove(struct pci_dev *dev) uio_unregister_device(info); pci_release_regions(dev); pci_disable_device(dev); - pci_set_drvdata(dev, NULL); for (i = 0; i < 5; i++) { if (info->mem[i].internal_addr) iounmap(info->mem[i].internal_addr); -- cgit v1.2.2 From 75f0aef6220dc1e73bed238e57b20544ef4f38ec Mon Sep 17 00:00:00 2001 From: Cong Ding Date: Fri, 25 Oct 2013 00:25:53 -0700 Subject: uio: fix memory leak we have to call kobject_put() to clean up the kobject after function kobject_init(), kobject_add(), or kobject_uevent() is called. Signed-off-by: Cong Ding Acked-by: Sebastian Andrzej Siewior Signed-off-by: Greg Kroah-Hartman --- drivers/uio/uio.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'drivers/uio') diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index 11d4e0a52579..c8e45add506e 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -288,13 +288,13 @@ static int uio_dev_add_attributes(struct uio_device *idev) } map = kzalloc(sizeof(*map), GFP_KERNEL); if (!map) - goto err_map; + goto err_map_kobj; kobject_init(&map->kobj, &map_attr_type); map->mem = mem; mem->map = map; ret = kobject_add(&map->kobj, idev->map_dir, "map%d", mi); if (ret) - goto err_map; + goto err_map_kobj; ret = kobject_uevent(&map->kobj, KOBJ_ADD); if (ret) goto err_map; @@ -313,14 +313,14 @@ static int uio_dev_add_attributes(struct uio_device *idev) } portio = kzalloc(sizeof(*portio), GFP_KERNEL); if (!portio) - goto err_portio; + goto err_portio_kobj; kobject_init(&portio->kobj, &portio_attr_type); portio->port = port; port->portio = portio; ret = kobject_add(&portio->kobj, idev->portio_dir, "port%d", pi); if (ret) - goto err_portio; + goto err_portio_kobj; ret = kobject_uevent(&portio->kobj, KOBJ_ADD); if (ret) goto err_portio; @@ -329,14 +329,18 @@ static int uio_dev_add_attributes(struct uio_device *idev) return 0; err_portio: - for (pi--; pi >= 0; pi--) { + pi--; +err_portio_kobj: + for (; pi >= 0; pi--) { port = &idev->info->port[pi]; portio = port->portio; kobject_put(&portio->kobj); } kobject_put(idev->portio_dir); err_map: - for (mi--; mi>=0; mi--) { + mi--; +err_map_kobj: + for (; mi >= 0; mi--) { mem = &idev->info->mem[mi]; map = mem->map; kobject_put(&map->kobj); -- cgit v1.2.2 From e6418fcc8adaa5c3911295cbe7ddd368b9788616 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Sun, 27 Oct 2013 21:53:40 +0000 Subject: uio: Pass pointers to virt_to_page(), not integers Most architectures define virt_to_page() as a macro that casts its argument such that an argument of type unsigned long will be accepted without complaint. However, the proper type is void *, and passing unsigned long results in a warning on MIPS. Compile-tested only. Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- drivers/uio/uio.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'drivers/uio') diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index c8e45add506e..e221f13fcb61 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -605,6 +605,7 @@ static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) struct uio_device *idev = vma->vm_private_data; struct page *page; unsigned long offset; + void *addr; int mi = uio_find_mem_index(vma); if (mi < 0) @@ -616,10 +617,11 @@ static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) */ offset = (vmf->pgoff - mi) << PAGE_SHIFT; + addr = (void *)(unsigned long)idev->info->mem[mi].addr + offset; if (idev->info->mem[mi].memtype == UIO_MEM_LOGICAL) - page = virt_to_page(idev->info->mem[mi].addr + offset); + page = virt_to_page(addr); else - page = vmalloc_to_page((void *)(unsigned long)idev->info->mem[mi].addr + offset); + page = vmalloc_to_page(addr); get_page(page); vmf->page = page; return 0; -- cgit v1.2.2