DRM: Replace kmalloc/memset combos with kzalloc
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / uio / uio_pdrv.c
blob7d3e469b99045be5ad1ff6e0dfecc4dd1870d50e
1 /*
2 * drivers/uio/uio_pdrv.c
4 * Copyright (C) 2008 by Digi International Inc.
5 * All rights reserved.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
11 #include <linux/platform_device.h>
12 #include <linux/uio_driver.h>
13 #include <linux/stringify.h>
14 #include <linux/slab.h>
16 #define DRIVER_NAME "uio_pdrv"
18 struct uio_platdata {
19 struct uio_info *uioinfo;
22 static int uio_pdrv_probe(struct platform_device *pdev)
24 struct uio_info *uioinfo = pdev->dev.platform_data;
25 struct uio_platdata *pdata;
26 struct uio_mem *uiomem;
27 int ret = -ENODEV;
28 int i;
30 if (!uioinfo || !uioinfo->name || !uioinfo->version) {
31 dev_dbg(&pdev->dev, "%s: err_uioinfo\n", __func__);
32 goto err_uioinfo;
35 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
36 if (!pdata) {
37 ret = -ENOMEM;
38 dev_dbg(&pdev->dev, "%s: err_alloc_pdata\n", __func__);
39 goto err_alloc_pdata;
42 pdata->uioinfo = uioinfo;
44 uiomem = &uioinfo->mem[0];
46 for (i = 0; i < pdev->num_resources; ++i) {
47 struct resource *r = &pdev->resource[i];
49 if (r->flags != IORESOURCE_MEM)
50 continue;
52 if (uiomem >= &uioinfo->mem[MAX_UIO_MAPS]) {
53 dev_warn(&pdev->dev, "device has more than "
54 __stringify(MAX_UIO_MAPS)
55 " I/O memory resources.\n");
56 break;
59 uiomem->memtype = UIO_MEM_PHYS;
60 uiomem->addr = r->start;
61 uiomem->size = r->end - r->start + 1;
62 ++uiomem;
65 while (uiomem < &uioinfo->mem[MAX_UIO_MAPS]) {
66 uiomem->size = 0;
67 ++uiomem;
70 pdata->uioinfo->priv = pdata;
72 ret = uio_register_device(&pdev->dev, pdata->uioinfo);
74 if (ret) {
75 kfree(pdata);
76 err_alloc_pdata:
77 err_uioinfo:
78 return ret;
81 platform_set_drvdata(pdev, pdata);
83 return 0;
86 static int uio_pdrv_remove(struct platform_device *pdev)
88 struct uio_platdata *pdata = platform_get_drvdata(pdev);
90 uio_unregister_device(pdata->uioinfo);
92 kfree(pdata);
94 return 0;
97 static struct platform_driver uio_pdrv = {
98 .probe = uio_pdrv_probe,
99 .remove = uio_pdrv_remove,
100 .driver = {
101 .name = DRIVER_NAME,
102 .owner = THIS_MODULE,
106 static int __init uio_pdrv_init(void)
108 return platform_driver_register(&uio_pdrv);
111 static void __exit uio_pdrv_exit(void)
113 platform_driver_unregister(&uio_pdrv);
115 module_init(uio_pdrv_init);
116 module_exit(uio_pdrv_exit);
118 MODULE_AUTHOR("Uwe Kleine-Koenig");
119 MODULE_DESCRIPTION("Userspace I/O platform driver");
120 MODULE_LICENSE("GPL v2");
121 MODULE_ALIAS("platform:" DRIVER_NAME);