Skip to content

Commit 8f982de

Browse files
committed
Refine the naming scheme for character device
The project is named "ksort" to reflect its purpose as a Linux kernel module. However, to align with the naming conventions of other subsystems, its character device is designated as /dev/sort.
1 parent 8b31e12 commit 8f982de

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ksort
22

3-
A Linux kernel module that creates the device `/dev/ksort`, capable of performing concurrent sorts.
3+
A Linux kernel module that creates the device `/dev/sort`, capable of performing concurrent sorts.
44

55
## User access to the character device
66

sort.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,15 @@ void sort_main(void *sort_buffer, size_t size, size_t es, cmp_t cmp)
204204
* within the work function.
205205
*/
206206
struct qsort *q = kmalloc(sizeof(struct qsort), GFP_KERNEL);
207-
struct common common;
208-
209-
common.swaptype =
210-
((char *) sort_buffer - (char *) 0) % sizeof(long) || es % sizeof(long)
211-
? 2
212-
: es == sizeof(long) ? 0
213-
: 1;
214-
common.es = es;
215-
common.cmp = cmp;
207+
struct common common = {
208+
.swaptype = ((char *) sort_buffer - (char *) 0) % sizeof(long) ||
209+
es % sizeof(long)
210+
? 2
211+
: es == sizeof(long) ? 0
212+
: 1,
213+
.es = es,
214+
.cmp = cmp,
215+
};
216216

217217
init_qsort(q, sort_buffer, size, &common);
218218

sort_mod.c

+19-19
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ static struct class *class;
1919

2020
struct workqueue_struct *workqueue;
2121

22-
static int ksort_open(struct inode *inode, struct file *file)
22+
static int sort_open(struct inode *inode, struct file *file)
2323
{
2424
return 0;
2525
}
2626

27-
static int ksort_release(struct inode *inode, struct file *file)
27+
static int sort_release(struct inode *inode, struct file *file)
2828
{
2929
return 0;
3030
}
@@ -34,10 +34,10 @@ static int num_compare(const void *a, const void *b)
3434
return (*(int *) a - *(int *) b);
3535
}
3636

37-
static ssize_t ksort_read(struct file *file,
38-
char *buf,
39-
size_t size,
40-
loff_t *offset)
37+
static ssize_t sort_read(struct file *file,
38+
char *buf,
39+
size_t size,
40+
loff_t *offset)
4141
{
4242
unsigned long len;
4343
size_t es;
@@ -68,23 +68,23 @@ static ssize_t ksort_read(struct file *file,
6868
return size;
6969
}
7070

71-
static ssize_t ksort_write(struct file *file,
72-
const char *buf,
73-
size_t size,
74-
loff_t *offset)
71+
static ssize_t sort_write(struct file *file,
72+
const char *buf,
73+
size_t size,
74+
loff_t *offset)
7575
{
7676
return 0;
7777
}
7878

7979
static const struct file_operations fops = {
80-
.read = ksort_read,
81-
.write = ksort_write,
82-
.open = ksort_open,
83-
.release = ksort_release,
80+
.read = sort_read,
81+
.write = sort_write,
82+
.open = sort_open,
83+
.release = sort_release,
8484
.owner = THIS_MODULE,
8585
};
8686

87-
static int __init ksort_init(void)
87+
static int __init sort_init(void)
8888
{
8989
struct device *device;
9090

@@ -107,7 +107,7 @@ static int __init ksort_init(void)
107107
if (cdev_add(&cdev, dev, 1) < 0)
108108
goto error_device_destroy;
109109

110-
workqueue = alloc_workqueue("ksortq", 0, WQ_MAX_ACTIVE);
110+
workqueue = alloc_workqueue("sortq", 0, WQ_MAX_ACTIVE);
111111
if (!workqueue)
112112
goto error_cdev_del;
113113

@@ -125,7 +125,7 @@ static int __init ksort_init(void)
125125
return -1;
126126
}
127127

128-
static void __exit ksort_exit(void)
128+
static void __exit sort_exit(void)
129129
{
130130
/* Given that drain_workqueue will be executed, there is no need for an
131131
* explicit flush action.
@@ -140,5 +140,5 @@ static void __exit ksort_exit(void)
140140
printk(KERN_INFO DEVICE_NAME ": unloaded\n");
141141
}
142142

143-
module_init(ksort_init);
144-
module_exit(ksort_exit);
143+
module_init(sort_init);
144+
module_exit(sort_exit);

0 commit comments

Comments
 (0)