diff options
author | Hans Petter Selasky <hselasky@FreeBSD.org> | 2021-05-11 18:51:59 +0000 |
---|---|---|
committer | Hans Petter Selasky <hselasky@FreeBSD.org> | 2021-06-02 11:25:20 +0000 |
commit | fba2292d65e04d3a07eb5d089f511f230d344ac8 (patch) | |
tree | de77cdb061eedcd2a95b05497f7e67b8ccc22f8a | |
parent | 303bef2a07974e6573774e04fbdb0e7c8e2f07ca (diff) | |
download | src-fba2292d65e04d3a07eb5d089f511f230d344ac8.tar.gz src-fba2292d65e04d3a07eb5d089f511f230d344ac8.zip |
Implement cdev_device_add() and cdev_device_del() in the LinuxKPI.
Sponsored by: Mellanox Technologies // NVIDIA Networking
(cherry picked from commit b8f113cab91f288e5d5e29d21184d1601b87cfdd)
-rw-r--r-- | sys/compat/linuxkpi/common/include/linux/cdev.h | 11 | ||||
-rw-r--r-- | sys/compat/linuxkpi/common/src/linux_compat.c | 38 |
2 files changed, 47 insertions, 2 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/cdev.h b/sys/compat/linuxkpi/common/include/linux/cdev.h index bdfb7e76c9a7..39a65472e921 100644 --- a/sys/compat/linuxkpi/common/include/linux/cdev.h +++ b/sys/compat/linuxkpi/common/include/linux/cdev.h @@ -2,7 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. - * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. + * Copyright (c) 2013-2021 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,6 +38,7 @@ #include <asm/atomic-long.h> +struct device; struct file_operations; struct inode; struct module; @@ -143,6 +144,14 @@ cdev_del(struct linux_cdev *cdev) struct linux_cdev *linux_find_cdev(const char *name, unsigned major, unsigned minor); +int linux_cdev_device_add(struct linux_cdev *, struct device *); +void linux_cdev_device_del(struct linux_cdev *, struct device *); + +#define cdev_device_add(...) \ + linux_cdev_device_add(__VA_ARGS__) +#define cdev_device_del(...) \ + linux_cdev_device_del(__VA_ARGS__) + #define cdev linux_cdev #endif /* _LINUX_CDEV_H_ */ diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index 35535eb75abb..0fc0ad702788 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -2,7 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. - * Copyright (c) 2013-2018 Mellanox Technologies, Ltd. + * Copyright (c) 2013-2021 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -2235,6 +2235,42 @@ linux_cdev_static_release(struct kobject *kobj) kobject_put(kobj->parent); } +int +linux_cdev_device_add(struct linux_cdev *ldev, struct device *dev) +{ + int ret; + + if (dev->devt != 0) { + /* Set parent kernel object. */ + ldev->kobj.parent = &dev->kobj; + + /* + * Unlike Linux we require the kobject of the + * character device structure to have a valid name + * before calling this function: + */ + if (ldev->kobj.name == NULL) + return (-EINVAL); + + ret = cdev_add(ldev, dev->devt, 1); + if (ret) + return (ret); + } + ret = device_add(dev); + if (ret != 0 && dev->devt != 0) + cdev_del(ldev); + return (ret); +} + +void +linux_cdev_device_del(struct linux_cdev *ldev, struct device *dev) +{ + device_del(dev); + + if (dev->devt != 0) + cdev_del(ldev); +} + static void linux_destroy_dev(struct linux_cdev *ldev) { |