File tree 3 files changed +18
-15
lines changed
3 files changed +18
-15
lines changed Original file line number Diff line number Diff line change @@ -7,23 +7,25 @@ obj-m += xoro.o
7
7
xoro-objs := \
8
8
xoro_mod.o
9
9
10
+ CFLAGS = -Wall -Werror
11
+
10
12
GIT_HOOKS := .git/hooks/applied
11
13
12
14
KDIR := /lib/modules/$(shell uname -r) /build
13
15
PWD := $(shell pwd)
14
16
15
- all : $(GIT_HOOKS ) user
17
+ all : $(GIT_HOOKS ) user test_xoro
16
18
$(MAKE ) -C $(KDIR ) M=$(PWD ) modules
17
19
18
20
$(GIT_HOOKS ) :
19
21
@scripts/install-git-hooks
20
22
@echo
21
23
22
24
user : user.c
23
- $(CC ) -o $@ $^
25
+ $(CC ) $( CFLAGS ) -o $@ $^
24
26
25
27
test_xoro : test_xoro.c
26
- $(CC ) -o $@ $^
28
+ $(CC ) $( CFLAGS ) -o $@ $^
27
29
28
30
insmod : all rmmod
29
31
sudo insmod sort.ko
33
35
@sudo rmmod sort 2> /dev/null || echo
34
36
@sudo rmmod xoro 2> /dev/null || echo
35
37
36
- check : user test_xoro
38
+ check : all
37
39
$(MAKE ) insmod
38
40
sudo ./user
39
41
sudo ./test_xoro
Original file line number Diff line number Diff line change 6
6
#include <unistd.h>
7
7
8
8
#define MAX_BYTES_PER_READ 8
9
- static unsigned char rx [MAX_BYTES_PER_READ ]; // Receive buffer from the LKM.
9
+ static unsigned char rx [MAX_BYTES_PER_READ ]; /* Receive buffer from the LKM */
10
10
11
11
void zero_rx (void )
12
12
{
@@ -23,12 +23,13 @@ int main(int argc, char *argv[])
23
23
return errno ;
24
24
}
25
25
26
- // Test reading different numbers of bytes.
26
+ /* Test reading different numbers of bytes. */
27
27
for (int n_bytes = 0 ; n_bytes < 10 ; n_bytes ++ ) {
28
- zero_rx (); // Clear/zero the buffer before copying in read data.
28
+ /* Clear/zero the buffer before copying in read data. */
29
+ zero_rx ();
29
30
30
- ssize_t n_bytes_read =
31
- read (fd , rx , n_bytes ); // Read the response from the LKM
31
+ /* Read the response from the LKM. */
32
+ ssize_t n_bytes_read = read (fd , rx , n_bytes );
32
33
33
34
if (0 > n_bytes_read ) {
34
35
perror ("Failed to read all bytes." );
Original file line number Diff line number Diff line change 2
2
#include <stdbool.h>
3
3
#include <stdio.h>
4
4
#include <stdlib.h>
5
- #include <string.h>
6
5
#include <unistd.h>
7
6
8
7
#define KSORT_DEV "/dev/sort"
@@ -15,13 +14,14 @@ int main()
15
14
goto error ;
16
15
}
17
16
18
- size_t nelem = 1000 ;
19
- size_t size = nelem * sizeof (int );
17
+ size_t n_elements = 1000 ;
18
+ size_t size = n_elements * sizeof (int );
20
19
int * inbuf = malloc (size );
21
20
if (!inbuf )
22
21
goto error ;
23
- for (size_t i = 0 ; i < nelem ; i ++ )
24
- inbuf [i ] = rand () % nelem ;
22
+
23
+ for (size_t i = 0 ; i < n_elements ; i ++ )
24
+ inbuf [i ] = rand () % n_elements ;
25
25
26
26
ssize_t r_sz = read (fd , inbuf , size );
27
27
if (r_sz != size ) {
@@ -32,7 +32,7 @@ int main()
32
32
bool pass = true;
33
33
int ret = 0 ;
34
34
/* Verify the result of sorting */
35
- for (size_t i = 1 ; i < nelem ; i ++ ) {
35
+ for (size_t i = 1 ; i < n_elements ; i ++ ) {
36
36
if (inbuf [i ] < inbuf [i - 1 ]) {
37
37
pass = false;
38
38
break ;
You can’t perform that action at this time.
0 commit comments