git: b8f113cab91f - main - Implement cdev_device_add() and cdev_device_del() in the LinuxKPI.
Hans Petter Selasky
hselasky at FreeBSD.org
Tue May 11 19:02:41 UTC 2021
The branch main has been updated by hselasky:
URL: https://cgit.FreeBSD.org/src/commit/?id=b8f113cab91f288e5d5e29d21184d1601b87cfdd
commit b8f113cab91f288e5d5e29d21184d1601b87cfdd
Author: Hans Petter Selasky <hselasky at FreeBSD.org>
AuthorDate: 2021-05-11 18:51:59 +0000
Commit: Hans Petter Selasky <hselasky at FreeBSD.org>
CommitDate: 2021-05-11 19:00:23 +0000
Implement cdev_device_add() and cdev_device_del() in the LinuxKPI.
MFC after: 1 week
Sponsored by: Mellanox Technologies // NVIDIA Networking
---
sys/compat/linuxkpi/common/include/linux/cdev.h | 11 ++++++-
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 dcbbc3a80b8a..a8f090ed0bd5 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
@@ -2244,6 +2244,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)
{
More information about the dev-commits-src-main
mailing list