Added headers and macros to support IB core on RHEL7.4
[compat-rdma/compat.git] / include / linux / cdev.h
1 #ifndef COMPAT_CDEV_H
2 #define COMPAT_CDEV_H
3
4 #include "../../compat/config.h"
5
6 #include_next <linux/cdev.h>
7
8 #ifndef HAVE_CDEV_SET_PARENT
9 #include <linux/device.h>
10
11 #define cdev_set_parent LINUX_BACKPORT(cdev_set_parent)
12 static inline void cdev_set_parent(struct cdev *p, struct kobject *kobj)
13 {
14         WARN_ON(!kobj->state_initialized);
15         p->kobj.parent = kobj;
16 }
17
18 #define cdev_device_add LINUX_BACKPORT(cdev_device_add)
19 static inline int cdev_device_add(struct cdev *cdev, struct device *dev)
20 {
21         int rc = 0;
22
23         if (dev->devt) {
24                 cdev_set_parent(cdev, &dev->kobj);
25
26                 rc = cdev_add(cdev, dev->devt, 1);
27                 if (rc)
28                         return rc;
29         }
30
31         rc = device_add(dev);
32         if (rc)
33                 cdev_del(cdev);
34
35         return rc;
36 }
37
38 #define cdev_device_del LINUX_BACKPORT(cdev_device_del)
39 static inline void cdev_device_del(struct cdev *cdev, struct device *dev)
40 {
41         device_del(dev);
42         if (dev->devt)
43                 cdev_del(cdev);
44 }
45
46 #endif /* HAVE_CDEV_SET_PARENT */
47
48 #endif /* COMPAT_CDEV_H */