From: Salah Triki <salah.triki@gmail.com>
To: "Felix Kuehling" <Felix.Kuehling@amd.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Cc: Salah Triki <salah.triki@gmail.com>
Subject: [PATCH] drm: amdkfd: Replace (un)register_chrdev() by (unregister/alloc)_chrdev_region()
Date: Wed, 5 Mar 2025 22:08:09 +0100 [thread overview]
Message-ID: <20250305210809.218138-1-salah.triki@gmail.com> (raw)
Replace (un)register_chrdev() by (unregister/alloc)_chrdev_region() as
they are deprecated since kernel 2.6. alloc_chrdev_region() generates a
dev_t value, so replace the kfd_char_dev_major int variable by the
kfd_char_dev_id dev_t variable and drop the MKDEV() call. Initialize a
cdev structure and add it to the device driver model as register_chrdev()
used to do and since alloc_chrdev_region() does not do it. Drop the
iminor() call since alloc_chrdev_region() allocates only one minor number.
On error and in the module exit function, remove the cdev structure from
the device driver model as unregister_chrdev() used to do.
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 35 ++++++++++++++++--------
1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 065d87841459..55c74466d2c5 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -37,6 +37,8 @@
#include <linux/ptrace.h>
#include <linux/dma-buf.h>
#include <linux/processor.h>
+#include <linux/cdev.h>
+
#include "kfd_priv.h"
#include "kfd_device_queue_manager.h"
#include "kfd_svm.h"
@@ -61,12 +63,14 @@ static const struct file_operations kfd_fops = {
.mmap = kfd_mmap,
};
-static int kfd_char_dev_major = -1;
+static dev_t kfd_char_dev_id;
struct device *kfd_device;
static const struct class kfd_class = {
.name = kfd_dev_name,
};
+static struct cdev kfd_cdev;
+
static inline struct kfd_process_device *kfd_lock_pdd_by_id(struct kfd_process *p, __u32 gpu_id)
{
struct kfd_process_device *pdd;
@@ -90,17 +94,24 @@ int kfd_chardev_init(void)
{
int err = 0;
- kfd_char_dev_major = register_chrdev(0, kfd_dev_name, &kfd_fops);
- err = kfd_char_dev_major;
+ err = alloc_chrdev_region(&kfd_char_dev_id, 0, 1, kfd_dev_name);
+
if (err < 0)
- goto err_register_chrdev;
+ goto err_alloc_chrdev_region;
+
+ cdev_init(&kfd_cdev, &kfd_fops);
+ kfd_cdev.owner = THIS_MODULE;
+
+ err = cdev_add(&kfd_cdev, kfd_char_dev_id, 1);
+ if (err)
+ goto err_cdev_add;
err = class_register(&kfd_class);
if (err)
goto err_class_create;
kfd_device = device_create(&kfd_class, NULL,
- MKDEV(kfd_char_dev_major, 0),
+ kfd_char_dev_id,
NULL, kfd_dev_name);
err = PTR_ERR(kfd_device);
if (IS_ERR(kfd_device))
@@ -111,16 +122,19 @@ int kfd_chardev_init(void)
err_device_create:
class_unregister(&kfd_class);
err_class_create:
- unregister_chrdev(kfd_char_dev_major, kfd_dev_name);
-err_register_chrdev:
+ cdev_del(&kfd_cdev);
+err_cdev_add:
+ unregister_chrdev_region(kfd_char_dev_id, 1);
+err_alloc_chrdev_region:
return err;
}
void kfd_chardev_exit(void)
{
- device_destroy(&kfd_class, MKDEV(kfd_char_dev_major, 0));
+ device_destroy(&kfd_class, kfd_char_dev_id);
class_unregister(&kfd_class);
- unregister_chrdev(kfd_char_dev_major, kfd_dev_name);
+ cdev_del(&kfd_cdev);
+ unregister_chrdev_region(kfd_char_dev_id, 1);
kfd_device = NULL;
}
@@ -130,9 +144,6 @@ static int kfd_open(struct inode *inode, struct file *filep)
struct kfd_process *process;
bool is_32bit_user_mode;
- if (iminor(inode) != 0)
- return -ENODEV;
-
is_32bit_user_mode = in_compat_syscall();
if (is_32bit_user_mode) {
--
2.34.1
next reply other threads:[~2025-03-06 8:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-05 21:08 Salah Triki [this message]
2025-03-06 0:18 ` [PATCH] drm: amdkfd: Replace (un)register_chrdev() by (unregister/alloc)_chrdev_region() Felix Kuehling
2025-03-07 19:10 ` Salah Triki
2025-03-10 12:11 ` Christian König
2025-03-10 15:19 ` Salah Triki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250305210809.218138-1-salah.triki@gmail.com \
--to=salah.triki@gmail.com \
--cc=Felix.Kuehling@amd.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox