Skip to content

Commit 3447660

Browse files
committed
Specify the verbose compilation warnings
1 parent c611838 commit 3447660

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

Makefile

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,25 @@ obj-m += xoro.o
77
xoro-objs := \
88
xoro_mod.o
99

10+
CFLAGS = -Wall -Werror
11+
1012
GIT_HOOKS := .git/hooks/applied
1113

1214
KDIR := /lib/modules/$(shell uname -r)/build
1315
PWD := $(shell pwd)
1416

15-
all: $(GIT_HOOKS) user
17+
all: $(GIT_HOOKS) user test_xoro
1618
$(MAKE) -C $(KDIR) M=$(PWD) modules
1719

1820
$(GIT_HOOKS):
1921
@scripts/install-git-hooks
2022
@echo
2123

2224
user: user.c
23-
$(CC) -o $@ $^
25+
$(CC) $(CFLAGS) -o $@ $^
2426

2527
test_xoro: test_xoro.c
26-
$(CC) -o $@ $^
28+
$(CC) $(CFLAGS) -o $@ $^
2729

2830
insmod: all rmmod
2931
sudo insmod sort.ko
@@ -33,7 +35,7 @@ rmmod:
3335
@sudo rmmod sort 2>/dev/null || echo
3436
@sudo rmmod xoro 2>/dev/null || echo
3537

36-
check: user test_xoro
38+
check: all
3739
$(MAKE) insmod
3840
sudo ./user
3941
sudo ./test_xoro

test_xoro.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <unistd.h>
77

88
#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 */
1010

1111
void zero_rx(void)
1212
{
@@ -23,12 +23,13 @@ int main(int argc, char *argv[])
2323
return errno;
2424
}
2525

26-
// Test reading different numbers of bytes.
26+
/* Test reading different numbers of bytes. */
2727
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();
2930

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);
3233

3334
if (0 > n_bytes_read) {
3435
perror("Failed to read all bytes.");

user.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <stdbool.h>
33
#include <stdio.h>
44
#include <stdlib.h>
5-
#include <string.h>
65
#include <unistd.h>
76

87
#define KSORT_DEV "/dev/sort"
@@ -15,13 +14,14 @@ int main()
1514
goto error;
1615
}
1716

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);
2019
int *inbuf = malloc(size);
2120
if (!inbuf)
2221
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;
2525

2626
ssize_t r_sz = read(fd, inbuf, size);
2727
if (r_sz != size) {
@@ -32,7 +32,7 @@ int main()
3232
bool pass = true;
3333
int ret = 0;
3434
/* Verify the result of sorting */
35-
for (size_t i = 1; i < nelem; i++) {
35+
for (size_t i = 1; i < n_elements; i++) {
3636
if (inbuf[i] < inbuf[i - 1]) {
3737
pass = false;
3838
break;

0 commit comments

Comments
 (0)