treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / vfio / platform / vfio_platform.c
blobae1a5eb98620f1d5080b4a3c280c1cbc09a70f84
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2013 - Virtual Open Systems
4 * Author: Antonios Motakis <a.motakis@virtualopensystems.com>
5 */
7 #include <linux/module.h>
8 #include <linux/slab.h>
9 #include <linux/vfio.h>
10 #include <linux/platform_device.h>
12 #include "vfio_platform_private.h"
14 #define DRIVER_VERSION "0.10"
15 #define DRIVER_AUTHOR "Antonios Motakis <a.motakis@virtualopensystems.com>"
16 #define DRIVER_DESC "VFIO for platform devices - User Level meta-driver"
18 static bool reset_required = true;
19 module_param(reset_required, bool, 0444);
20 MODULE_PARM_DESC(reset_required, "override reset requirement (default: 1)");
22 /* probing devices from the linux platform bus */
24 static struct resource *get_platform_resource(struct vfio_platform_device *vdev,
25 int num)
27 struct platform_device *dev = (struct platform_device *) vdev->opaque;
28 int i;
30 for (i = 0; i < dev->num_resources; i++) {
31 struct resource *r = &dev->resource[i];
33 if (resource_type(r) & (IORESOURCE_MEM|IORESOURCE_IO)) {
34 if (!num)
35 return r;
37 num--;
40 return NULL;
43 static int get_platform_irq(struct vfio_platform_device *vdev, int i)
45 struct platform_device *pdev = (struct platform_device *) vdev->opaque;
47 return platform_get_irq(pdev, i);
50 static int vfio_platform_probe(struct platform_device *pdev)
52 struct vfio_platform_device *vdev;
53 int ret;
55 vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
56 if (!vdev)
57 return -ENOMEM;
59 vdev->opaque = (void *) pdev;
60 vdev->name = pdev->name;
61 vdev->flags = VFIO_DEVICE_FLAGS_PLATFORM;
62 vdev->get_resource = get_platform_resource;
63 vdev->get_irq = get_platform_irq;
64 vdev->parent_module = THIS_MODULE;
65 vdev->reset_required = reset_required;
67 ret = vfio_platform_probe_common(vdev, &pdev->dev);
68 if (ret)
69 kfree(vdev);
71 return ret;
74 static int vfio_platform_remove(struct platform_device *pdev)
76 struct vfio_platform_device *vdev;
78 vdev = vfio_platform_remove_common(&pdev->dev);
79 if (vdev) {
80 kfree(vdev);
81 return 0;
84 return -EINVAL;
87 static struct platform_driver vfio_platform_driver = {
88 .probe = vfio_platform_probe,
89 .remove = vfio_platform_remove,
90 .driver = {
91 .name = "vfio-platform",
95 module_platform_driver(vfio_platform_driver);
97 MODULE_VERSION(DRIVER_VERSION);
98 MODULE_LICENSE("GPL v2");
99 MODULE_AUTHOR(DRIVER_AUTHOR);
100 MODULE_DESCRIPTION(DRIVER_DESC);