Coding: Refactoring (Screenplay)#
Build Module From Multiple Files#
Factor
my_eventandmy_event_listout into separate files,event.{h,c}.Wonder why loading does not call
init(), and why nothing works.Kbuild apparently won’t accept a source file with the same name as the module (see here)
⟶ rename
my_driver.ctomain.c
Makefile#
obj-m += my_driver.o
my_driver-y += main.o event.o
Per-Device Structure#
Straightforward: cram all device related stuff into one
struct my_deviceLeave
init()andexit()as-is, mostly (except to access members ofmy_deviceinstead).
Want My Hair Pretty#
What’s still bad?
Style-wise, if we have a struct (
my_device) that is setup and torn down, we want to have dedicated methods.Add a go public method, for no apparent reason (and come back to it later when we add multiple devices).
Makefile: -Wswitch-enum#
Add a number of compiler flags
ccflags-y += -Werror -Wall -Wswitch-enum -Wimplicit
Add a
ioctl, and don’t make use of itFix until shuts up