treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / vfio / platform / vfio_amba.c
blob9636a2afaecd1b4599473debb5ee7dc7908055b0
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/amba/bus.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 AMBA devices - User Level meta-driver"
18 /* probing devices from the AMBA bus */
20 static struct resource *get_amba_resource(struct vfio_platform_device *vdev,
21 int i)
23 struct amba_device *adev = (struct amba_device *) vdev->opaque;
25 if (i == 0)
26 return &adev->res;
28 return NULL;
31 static int get_amba_irq(struct vfio_platform_device *vdev, int i)
33 struct amba_device *adev = (struct amba_device *) vdev->opaque;
34 int ret = 0;
36 if (i < AMBA_NR_IRQS)
37 ret = adev->irq[i];
39 /* zero is an unset IRQ for AMBA devices */
40 return ret ? ret : -ENXIO;
43 static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id)
45 struct vfio_platform_device *vdev;
46 int ret;
48 vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
49 if (!vdev)
50 return -ENOMEM;
52 vdev->name = kasprintf(GFP_KERNEL, "vfio-amba-%08x", adev->periphid);
53 if (!vdev->name) {
54 kfree(vdev);
55 return -ENOMEM;
58 vdev->opaque = (void *) adev;
59 vdev->flags = VFIO_DEVICE_FLAGS_AMBA;
60 vdev->get_resource = get_amba_resource;
61 vdev->get_irq = get_amba_irq;
62 vdev->parent_module = THIS_MODULE;
63 vdev->reset_required = false;
65 ret = vfio_platform_probe_common(vdev, &adev->dev);
66 if (ret) {
67 kfree(vdev->name);
68 kfree(vdev);
71 return ret;
74 static int vfio_amba_remove(struct amba_device *adev)
76 struct vfio_platform_device *vdev;
78 vdev = vfio_platform_remove_common(&adev->dev);
79 if (vdev) {
80 kfree(vdev->name);
81 kfree(vdev);
82 return 0;
85 return -EINVAL;
88 static const struct amba_id pl330_ids[] = {
89 { 0, 0 },
92 MODULE_DEVICE_TABLE(amba, pl330_ids);
94 static struct amba_driver vfio_amba_driver = {
95 .probe = vfio_amba_probe,
96 .remove = vfio_amba_remove,
97 .id_table = pl330_ids,
98 .drv = {
99 .name = "vfio-amba",
100 .owner = THIS_MODULE,
104 module_amba_driver(vfio_amba_driver);
106 MODULE_VERSION(DRIVER_VERSION);
107 MODULE_LICENSE("GPL v2");
108 MODULE_AUTHOR(DRIVER_AUTHOR);
109 MODULE_DESCRIPTION(DRIVER_DESC);