Giter VIP home page Giter VIP logo

ldd3's Introduction

ldd3: Linux Device Drivers 3 examples updated to work with recent kernels

About


Linux Device Drivers 3 (http://lwn.net/Kernel/LDD3/) book is now a few years old and most of the example drivers do not compile in recent kernels.

This project aims to keep LDD3 example drivers up-to-date with recent kernels.

The original code can be found at: http://examples.oreilly.com/9780596005900/

Compiling


The example drivers should compile against latest Linus Torvalds kernel tree:

  • git://git.kernel.org/pub/scm/linux/kernel/git/sfr/linux-next.git

To compile the drivers against a specific tree (for example Linus tree):

$ git clone git://github.com/martinezjavier/ldd3.git
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
$ export KERNELDIR=/path/to/linux
$ cd ldd3
$ make

Bugs, comments or patches: See https://github.com/martinezjavier/ldd3/issues

Latest Tested Kernel Builds


The kernel builds below are the versions most recently tested/supported

  • Ubuntu 18.04 kernel as of July 2020: 5.4.0-42-generic
  • Ubuntu 20.04 kernel as of July 2021: 5.4.0-73-generic
  • Yocto poky warrior branch kernel for qemu aarch64 builds: 5.0.19
  • Yocto poky hardknott branch kernel for qemu aarch64 builds: 5.10.46
  • Buildroot 2019.05 kernel for qemu builds: 4.9.16
  • Buildroot 2021.02 kernel for qemu builds: 5.10
  • Alpine 3.13 kernel as of May 2021: 5.10.29-lts, see here for detail.

Eclipse Integration

---------4 Eclipse CDT integration is provided by symlinking the correct linux source directory with the ./linux_source_cdt symlink. The .project and .cproject files were setup using instructions in this link and assuming a symlink is setup in the local project directory to point to relevant kernel headers

This can be done on a system with kernel headers installed using:

ln -s /usr/src/linux-headers-`uname -r`/ linux_source_cdt

ldd3's People

Contributors

akostrikov avatar alexlav126 avatar cataldor avatar dwalkes avatar ekoops avatar ericwq avatar eu1793 avatar hwangcc23 avatar illegalprime avatar jajoosiddhant avatar jypan-ccu avatar lushl9301 avatar martinezjavier avatar mbgg avatar mibez avatar pablito2020 avatar quantumforge avatar spinech0 avatar tatetian avatar ttousai avatar veidongrayg avatar wangwangwar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ldd3's Issues

scull pipe.c

scull's pipe.c does not compile on 4.11.9, with GCC 7.1.1

error: implicit declaration of function ‘signal_pendin ’; did you mean ‘timer_pending’? [-Werror=implicit-function-declaration]
if (signal_pending(current))
^~~~~~~~~~~~~~
timer_pending

scullc does not build properly

Thanks for this page! If I make in ldd3-master/scull, everything works as is should. However, if I cd to ldd3-master/scullc, make err's out starting with
error: implicit declaration of function ‘aio_complete’ ...

Am I missing something?

Error compiling misc-progs in ARM aarch64.

I tried running these examples in two different ARM aarch64 kernels, but I got the same error after running the main Makefile. I built only the misc-modules dir with the Makefile in it and it worked. Apparently, the problem lies inside misc-progs.
First kernel I tried with (Raspberri Pi 4B):

5.4.83-1-MANJARO-ARM #1 SMP PREEMPT Mon Dec 14 08:37:33 CST 2020 aarch64 GNU/Linux

Second one (Jetson Nano):

4.9.201-tegra #1 SMP PREEMPT Fri Jan 15 14:41:02 PST 2021 aarch64 GNU/Linux

After cloning and running the main Makefile I got:

[oliver@ManjaroARM ldd3]$ make
for n in misc-progs misc-modules skull scull scullc scullp lddbus sculld scullv shortprint simple tty pci usb sbull snull short; do make -C $n || exit 1; done
make[1]: Entering directory '/home/oliver/Documentos/GitClone/ldd3/misc-progs'
cc -O2 -fomit-frame-pointer -Wall -I/lib/modules/5.4.83-1-MANJARO-ARM/build/include    asynctest.c   -o asynctest
In file included from /usr/include/asm/sigcontext.h:22,
                 from /usr/include/bits/sigcontext.h:30,
                 from /usr/include/signal.h:288,
                 from asynctest.c:20:
/lib/modules/5.4.83-1-MANJARO-ARM/build/include/linux/types.h:15:26: error: conflicting types for ‘fd_set’
   15 | typedef __kernel_fd_set  fd_set;
      |                          ^~~~~~
In file included from /usr/include/sys/types.h:179,
                 from /usr/include/stdlib.h:394,
                 from asynctest.c:17:
/usr/include/sys/select.h:70:5: note: previous declaration of ‘fd_set’ was here
   70 |   } fd_set;
      |     ^~~~~~
In file included from /usr/include/asm/sigcontext.h:22,
                 from /usr/include/bits/sigcontext.h:30,
                 from /usr/include/signal.h:288,
                 from asynctest.c:20:
/lib/modules/5.4.83-1-MANJARO-ARM/build/include/linux/types.h:16:25: error: conflicting types for ‘dev_t’
   16 | typedef __kernel_dev_t  dev_t;
      |                         ^~~~~
In file included from /usr/include/stdlib.h:394,
                 from asynctest.c:17:
/usr/include/sys/types.h:59:17: note: previous declaration of ‘dev_t’ was here
   59 | typedef __dev_t dev_t;
      |                 ^~~~~
In file included from /usr/include/asm/sigcontext.h:22,
                 from /usr/include/bits/sigcontext.h:30,
                 from /usr/include/signal.h:288,
                 from asynctest.c:20:
/lib/modules/5.4.83-1-MANJARO-ARM/build/include/linux/types.h:26:26: error: conflicting types for ‘timer_t’
   26 | typedef __kernel_timer_t timer_t;
      |                          ^~~~~~~
In file included from /usr/include/sys/types.h:130,
                 from /usr/include/stdlib.h:394,
                 from asynctest.c:17:
/usr/include/bits/types/timer_t.h:7:19: note: previous declaration of ‘timer_t’ was here
    7 | typedef __timer_t timer_t;
      |                   ^~~~~~~
In file included from /usr/include/asm/sigcontext.h:22,
                 from /usr/include/bits/sigcontext.h:30,
                 from /usr/include/signal.h:288,
                 from asynctest.c:20:
/lib/modules/5.4.83-1-MANJARO-ARM/build/include/linux/types.h:46:26: error: conflicting types for ‘loff_t’
   46 | typedef __kernel_loff_t  loff_t;
      |                          ^~~~~~
In file included from /usr/include/stdlib.h:394,
                 from asynctest.c:17:
/usr/include/sys/types.h:42:18: note: previous declaration of ‘loff_t’ was here
   42 | typedef __loff_t loff_t;
      |                  ^~~~~~
In file included from /usr/include/asm/sigcontext.h:22,
                 from /usr/include/bits/sigcontext.h:30,
                 from /usr/include/signal.h:288,
                 from asynctest.c:20:
/lib/modules/5.4.83-1-MANJARO-ARM/build/include/linux/types.h:113:15: error: conflicting types for ‘u_int64_t’
  113 | typedef u64   u_int64_t;
      |               ^~~~~~~~~
In file included from /usr/include/stdlib.h:394,
                 from asynctest.c:17:
/usr/include/sys/types.h:161:20: note: previous declaration of ‘u_int64_t’ was here
  161 | typedef __uint64_t u_int64_t;
      |                    ^~~~~~~~~
In file included from /usr/include/asm/sigcontext.h:22,
                 from /usr/include/bits/sigcontext.h:30,
                 from /usr/include/signal.h:288,
                 from asynctest.c:20:
/lib/modules/5.4.83-1-MANJARO-ARM/build/include/linux/types.h:114:15: error: conflicting types for ‘int64_t’
  114 | typedef s64   int64_t;
      |               ^~~~~~~
In file included from /usr/include/sys/types.h:155,
                 from /usr/include/stdlib.h:394,
                 from asynctest.c:17:
/usr/include/bits/stdint-intn.h:27:19: note: previous declaration of ‘int64_t’ was here
   27 | typedef __int64_t int64_t;
      |                   ^~~~~~~
In file included from /usr/include/asm/sigcontext.h:22,
                 from /usr/include/bits/sigcontext.h:30,
                 from /usr/include/signal.h:288,
                 from asynctest.c:20:
/lib/modules/5.4.83-1-MANJARO-ARM/build/include/linux/types.h:131:13: error: conflicting types for ‘blkcnt_t’
  131 | typedef u64 blkcnt_t;
      |             ^~~~~~~~
In file included from /usr/include/stdlib.h:394,
                 from asynctest.c:17:
/usr/include/sys/types.h:192:20: note: previous declaration of ‘blkcnt_t’ was here
  192 | typedef __blkcnt_t blkcnt_t;  /* Type to count number of disk blocks.  */
      |                    ^~~~~~~~
make[1]: *** [<builtin>: asynctest] Error 1
make[1]: Leaving directory '/home/oliver/Documentos/GitClone/ldd3/misc-progs'
make: *** [Makefile:10: subdirs] Error 1

I know aarch64 is not a "standard" kernel, but I would be great to run all the examples in a cheap computer.
Thank you.

A lock is missing to relaese in snull_get_tx_buffer

The lock is missing to release at Line 143. Should it be a bug?

ldd3/snull/snull.c

Lines 139 to 150 in dd5c9c7

spin_lock_irqsave(&priv->lock, flags);
pkt = priv->ppool;
if(!pkt) {
PDEBUG("Out of Pool\n");
return pkt;
}
priv->ppool = pkt->next;
if (priv->ppool == NULL) {
printk (KERN_INFO "Pool empty\n");
netif_stop_queue(dev);
}
spin_unlock_irqrestore(&priv->lock, flags);

Updated UID handling

Hi Javier,

I've created a pull request that fixes some compile issues with the scull driver. I may fix others if I have time before class!

Cheers
./m

kernel panic generation when i run "insmod snull.ko" at 4.19.94-ti-r50

sudo insmod snull.ko

I have a kernel panic when i run sudo insmod snull.ko. at Beaglbone AI ( 4.19.94-ti-r50)

i have kernel panic
I use 4.19.94-ti-r50 at Beaglebone AI

root@beaglebone:/home/debian/LDD/snull# sudo insmod snull.ko
root@beaglebone:/home/debian/LDD/snull# [ 4026.234112] Pool empty
[ 4027.008435] ------------[ cut here ]------------
[ 4027.013118] WARNING: CPU: 0 PID: 0 at net/sched/sch_generic.c:466 dev_watchdog+0x258/0x25c
[ 4027.021453] NETDEV WATCHDOG: sn0 (): transmit queue 0 timed out
[ 4027.027421] Modules linked in: snull(O) sbull(O+) hello_1(O) xt_state xt_conntrack nft_counter nft_chain_nat_ipv4 ipt_MASQUERADE nft_compat pru_rproc irq_pruss_intc rpmsg_rpc pruss bnep virtio_rpmsg_bus uio_pruss_shmem pruss_soc_bus ti_vip ti_vpe btsdio ti_sc videobuf2_dma_contig ti_csc bluetooth ti_vpdma v4l2_fwnode v4l2_mem2mem v4l2_common videobuf2_memops videobuf2_v4l2 videobuf2_common videodev media ecdh_generic brcmfmac brcmutil cfg80211 omap_remoteproc remoteproc virtio virtio_ring usb_f_ncm usb_f_mass_storage usb_f_rndis u_ether libcomposite uio_pdrv_genirq uio gpio_pisosr spidev [last unloaded: snull]
[ 4027.081808] CPU: 0 PID: 0 Comm: swapper/0 Tainted: G D W O 4.19.94-ti-r50 #1buster
[ 4027.090371] Hardware name: Generic DRA74X (Flattened Device Tree)
[ 4027.096513] [] (unwind_backtrace) from [] (show_stack+0x20/0x24)
[ 4027.104299] [] (show_stack) from [] (dump_stack+0x8c/0xa0)
[ 4027.111562] [] (dump_stack) from [] (__warn.part.3+0xcc/0xe8)
[ 4027.119085] [] (__warn.part.3) from [] (warn_slowpath_fmt+0x78/0x94)
[ 4027.127217] [] (warn_slowpath_fmt) from [] (dev_watchdog+0x258/0x25c)
[ 4027.135439] [] (dev_watchdog) from [] (call_timer_fn+0x3c/0x210)
[ 4027.143222] [] (call_timer_fn) from [] (expire_timers+0xcc/0x174)
[ 4027.151090] [] (expire_timers) from [] (run_timer_softirq+0xbc/0x1bc)
[ 4027.159308] [] (run_timer_softirq) from [] (__do_softirq+0x16c/0x438)
[ 4027.167529] [] (__do_softirq) from [] (irq_exit+0xd8/0xec)
[ 4027.174792] [] (irq_exit) from [] (__handle_domain_irq+0x90/0xfc)
[ 4027.182663] [] (__handle_domain_irq) from [] (gic_handle_irq+0x4c/0x88)
[ 4027.191054] [] (gic_handle_irq) from [] (__irq_svc+0x6c/0xa8)
[ 4027.198569] Exception stack(0xc1501ed8 to 0xc1501f20)
[ 4027.203644] 1ec0: 00000000 007c7460
[ 4027.211861] 1ee0: fe600000 00000000 ffffe000 c1506e34 c1506e7c 00000001 00000001 c15de2ba
[ 4027.220078] 1f00: c10e6414 c1501f34 c1501f14 c1501f28 c012cdd4 c010a6f4 60010013 ffffffff
[ 4027.228297] [] (__irq_svc) from [] (arch_cpu_idle+0x30/0x4c)
[ 4027.235732] [] (arch_cpu_idle) from [] (default_idle_call+0x38/0x3c)
[ 4027.243863] [] (default_idle_call) from [] (do_idle+0x11c/0x158)
[ 4027.251643] [] (do_idle) from [] (cpu_startup_entry+0x28/0x30)
[ 4027.259251] [] (cpu_startup_entry) from [] (rest_init+0xd4/0xd8)
[ 4027.267036] [] (rest_init) from [] (start_kernel+0x490/0x4c0)
[ 4027.274579] ---[ end trace 0152fed7b0e69663 ]---
[ 4027.279905] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[ 4027.288098] pgd = 2f826f0f
[ 4027.290843] [00000000] *pgd=00000000
[ 4027.294466] Internal error: Oops: 5 [#2] PREEMPT SMP ARM
[ 4027.299804] Modules linked in: snull(O) sbull(O+) hello_1(O) xt_state xt_conntrack nft_counter nft_chain_nat_ipv4 ipt_MASQUERADE nft_compat pru_rproc irq_pruss_intc rpmsg_rpc pruss bnep virtio_rpmsg_bus uio_pruss_shmem pruss_soc_bus ti_vip ti_vpe btsdio ti_sc videobuf2_dma_contig ti_csc bluetooth ti_vpdma v4l2_fwnode v4l2_mem2mem v4l2_common videobuf2_memops videobuf2_v4l2 videobuf2_common videodev media ecdh_generic brcmfmac brcmutil cfg80211 omap_remoteproc remoteproc virtio virtio_ring usb_f_ncm usb_f_mass_storage usb_f_rndis u_ether libcomposite uio_pdrv_genirq uio gpio_pisosr spidev [last unloaded: snull]
[ 4027.354148] CPU: 0 PID: 9 Comm: ksoftirqd/0 Tainted: G D W O 4.19.94-ti-r50 #1buster
[ 4027.362884] Hardware name: Generic DRA74X (Flattened Device Tree)
[ 4027.369016] PC is at snull_tx+0xf4/0x234 [snull]
[ 4027.373660] LR is at dev_hard_start_xmit+0xd4/0x2cc
[ 4027.378560] pc : [] lr : [] psr: 000f0013
[ 4027.384854] sp : d4197d28 ip : 00000000 fp : d4197d9c
[ 4027.390102] r10: 00000000 r9 : bf7b7280 r8 : 0000006e
[ 4027.395349] r7 : 0000006e r6 : c1506e08 r5 : d1cdf800 r4 : d1ce6002
[ 4027.401905] r3 : 00000020 r2 : d1cdf800 r1 : 6674692a r0 : 000002ff
[ 4027.408462] Flags: nzcv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none
[ 4027.415629] Control: 10c5387d Table: 9196806a DAC: 00000051
[ 4027.421401] Process ksoftirqd/0 (pid: 9, stack limit = 0xf5db9d5e)
[ 4027.427609] Stack: (0xd4197d28 to 0xd4198000)
[ 4027.431988] 7d20: 00000400 00000000 0000002a 00000400 000002aa 00000400
[ 4027.440204] 7d40: d4197d6c c0b6a16c 00004008 d18c0240 00000000 c1506e08 00000000 c0b6a4a0
[ 4027.448421] 7d60: d4197d9c d4197d70 c0b6a16c 7d8a13bb 00000000 d18c0240 d1cdf800 c1506e08
[ 4027.456638] 7d80: 00000000 00000000 d1cdf800 d0af0a00 d4197dfc d4197da0 c0b6a92c bf7b5360
[ 4027.464855] 7da0: d4197e07 d1cdf800 d4197dcc d4197e08 00000000 c15e3b60 c1504d00 c15e3b78
[ 4027.473072] 7dc0: c1506e34 c1508544 0000006e ffffe000 c1506e08 d41f0800 d18c0240 c1506e08
[ 4027.481289] 7de0: 00000000 d0af0a00 d1cdf800 00000000 d4197e3c d4197e00 c0bac180 c0b6a864
[ 4027.489506] 7e00: c0731668 00731528 00000010 7d8a13bb c0bab410 d41f0800 d18c0240 00000001
[ 4027.497721] 7e20: ffffff92 d0af0a00 d18c0240 00000001 d4197e8c d4197e40 c0bac60c c0bac070
[ 4027.505938] 7e40: 00000000 00000001 c15e3938 c1506e34 d41f088c d41f0840 ffffe000 00000040
[ 4027.514154] 7e60: dff14640 d41f0800 d2377c00 dff14640 00000000 00000100 000000a1 00000000
[ 4027.522370] 7e80: d4197ec4 d4197e90 c0b66804 c0bac4ac d4197ec4 c111b97c 00000008 00000002
[ 4027.530586] 7ea0: 00000001 c1504088 ffffe000 00000100 000000a1 00000000 d4197f2c d4197ec8
[ 4027.538803] 7ec0: c010250c c0b666cc c1506e08 c1507478 c0e03f78 04208040 c1504d00 000e37ec
[ 4027.547020] 7ee0: c1138158 0000000a c14cd6c0 c15de8f8 c1506e34 c11cf598 c14c5358 c1504080
[ 4027.555237] 7f00: ffffe000 ffffe000 d415f740 c15232c4 c1506e08 00000001 00000000 00000000
[ 4027.563454] 7f20: d4197f3c d4197f30 c01439c0 c01023ac d4197f74 d4197f40 c0165090 c0143984
[ 4027.571669] 7f40: d4197f74 7d8a13bb c015ffb0 d415f700 d415f780 00000000 d4196000 d415f740
[ 4027.579885] 7f60: c0164ea8 d4163dd4 d4197fac d4197f78 c01604c0 c0164eb4 d415f71c d415f71c
[ 4027.588100] 7f80: 00000000 d415f780 c0160354 00000000 00000000 00000000 00000000 00000000
[ 4027.596317] 7fa0: 00000000 d4197fb0 c01010e8 c0160360 00000000 00000000 00000000 00000000
[ 4027.604533] 7fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[ 4027.612749] 7fe0: 00000000 00000000 00000000 00000000 00000013 00000000 00000000 00000000
[ 4027.620996] [] (snull_tx [snull]) from [] (dev_hard_start_xmit+0xd4/0x2cc)
[ 4027.629654] [] (dev_hard_start_xmit) from [] (sch_direct_xmit+0x11c/0x43c)
[ 4027.638309] [] (sch_direct_xmit) from [] (__qdisc_run+0x16c/0x5e8)
[ 4027.646264] [] (__qdisc_run) from [] (net_tx_action+0x144/0x304)
[ 4027.654047] [] (net_tx_action) from [] (__do_softirq+0x16c/0x438)
[ 4027.661917] [] (__do_softirq) from [] (run_ksoftirqd+0x48/0x50)
[ 4027.669619] [] (run_ksoftirqd) from [] (smpboot_thread_fn+0x1e8/0x2fc)
[ 4027.677926] [] (smpboot_thread_fn) from [] (kthread+0x16c/0x174)
[ 4027.685706] [] (kthread) from [] (ret_from_fork+0x14/0x2c)
[ 4027.692959] Exception stack(0xd4197fb0 to 0xd4197ff8)
[ 4027.698035] 7fa0: 00000000 00000000 00000000 00000000
[ 4027.706251] 7fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[ 4027.714466] 7fe0: 00000000 00000000 00000000 00000000 00000013 00000000
[ 4027.721115] Code: e1c431b8 e0423005 e595a5e0 e16f3f13 (e59a2000)
[ 4027.727289] ---[ end trace 0152fed7b0e69664 ]---
[ 4027.731960] Kernel panic - not syncing: Fatal exception in interrupt
[ 4027.738354] CPU1: stopping
[ 4027.741081] CPU: 1 PID: 856 Comm: systemd-journal Tainted: G D W O 4.19.94-ti-r50 #1buster
[ 4027.750342] Hardware name: Generic DRA74X (Flattened Device Tree)
[ 4027.756479] [] (unwind_backtrace) from [] (show_stack+0x20/0x24)
[ 4027.764265] [] (show_stack) from [] (dump_stack+0x8c/0xa0)
[ 4027.771527] [] (dump_stack) from [] (handle_IPI+0x3f4/0x420)
[ 4027.778962] [] (handle_IPI) from [] (gic_handle_irq+0x84/0x88)
[ 4027.786569] [] (gic_handle_irq) from [] (__irq_usr+0x54/0x80)
[ 4027.794085] Exception stack(0xd23a7fb0 to 0xd23a7ff8)
[ 4027.799162] 7fa0: 00000000 00000000 00000013 13aa538a
[ 4027.807381] 7fc0: 13aa538b 00000000 00000014 bea5d7a8 1f400000 00000000 00000000 00000000
[ 4027.815597] 7fe0: fffffff4 bea5d77c 0000000c b6da6e80 800f0030 ffffffff
[ 4027.822257] ---[ end Kernel panic - not syncing: Fatal exception in interrupt ]---

How solve this problem?
Thanks
Regards

Return value of cdev_add() in ldd3/scullp/main.c

This is my first time posting an issue. If I made any inappropriate mistakes, please correct me. Thanks in advance.

On line 454 of scullp/main.c, the return value of cdev_add() is assigned to err, which is then evaluated by the if-condition. According to API of cdev_add(), it returns a negative error code on failure; hence, if it fails, then err will be assigned a negative value, which means the error message will never be printed. Could anyone please tell me what the purpose of this is? Thanks in advance.

not compiling on raspberrypi 4 , help plz

make
for n in misc-progs misc-modules skull scull scullc scullp lddbus sculld scullv shortprint simple tty pci usb sbull snull short; do make -C $n || exit 1; done
make[1]: Entering directory '/home/pi/ldd3/ldd3/misc-progs'
cc -O2 -fomit-frame-pointer -Wall -I/usr/src/linux-headers-5.10.17-v7l+/include inp.c -o inp
inp.c:36:12: fatal error: sys/perm.h: No such file or directory

include <sys/perm.h>

        ^~~~~~~~~~~~

compilation terminated.
make[1]: *** [: inp] Error 1
make[1]: Leaving directory '/home/pi/ldd3/ldd3/misc-progs'
make: *** [Makefile:10: subdirs] Error 1ls

my current Linux header ===>>> linux-headers-5.10.17+ linux-headers-5.10.17-v7+ linux-headers-5.10.17-v7l+

Recent change in signature of netdevice.h/ndo_tx_timeout

Hi and thanks for maintaining these files up to date :)
While trying to compile snull, I encountered an issue with the signature of ndo_tx_timeout:

error: initialization of ‘void (*)(struct net_device *, unsigned int)’ from incompatible pointer type ‘void (*)(struct net_device *)’ [-Werror=incompatible-pointer-types]
  638 |  .ndo_tx_timeout      = snull_tx_timeout

This is correct according to the linux repo, and to my up-to-date arch linux machine.
Here is the specific line including the new definition:
https://github.com/torvalds/linux/blob/master/include/linux/netdevice.h#L1030
The change seems to have been included in this commit:
torvalds/linux@0290bd2

Many thanks for your time.

build error with Linux v5.9-rc8

mike@atel:~/git_rep/ldd3/sbull$ make
make -C /home/mike/git_rep/linux M=/home/mike/git_rep/ldd3/sbull modules
make[1]: Entering directory '/home/mike/git_rep/linux'
CC [M] /home/mike/git_rep/ldd3/sbull/sbull.o
/home/mike/git_rep/ldd3/sbull/sbull.c:94:25: error: unknown type name ‘make_request_fn’
blk_generic_alloc_queue(make_request_fn make_request, int node_id)
^
/home/mike/git_rep/ldd3/sbull/sbull.c:376:2: error: unknown field ‘media_changed’ specified in initializer
.media_changed = sbull_media_changed,
^
/home/mike/git_rep/ldd3/sbull/sbull.c:376:21: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
.media_changed = sbull_media_changed,
^
/home/mike/git_rep/ldd3/sbull/sbull.c:376:21: note: (near initialization for ‘sbull_ops.rw_page’)
/home/mike/git_rep/ldd3/sbull/sbull.c: In function ‘setup_device’:
/home/mike/git_rep/ldd3/sbull/sbull.c:426:17: error: implicit declaration of function ‘blk_generic_alloc_queue’ [-Werror=implicit-function-declaration]
dev->queue = blk_generic_alloc_queue(sbull_make_request, NUMA_NO_NODE);
^
/home/mike/git_rep/ldd3/sbull/sbull.c:426:14: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
dev->queue = blk_generic_alloc_queue(sbull_make_request, NUMA_NO_NODE);
^
/home/mike/git_rep/ldd3/sbull/sbull.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-implicit-fallthrough’
cc1: some warnings being treated as errors
scripts/Makefile.build:283: recipe for target '/home/mike/git_rep/ldd3/sbull/sbull.o' failed
make[2]: *** [/home/mike/git_rep/ldd3/sbull/sbull.o] Error 1
Makefile:1784: recipe for target '/home/mike/git_rep/ldd3/sbull' failed
make[1]: *** [/home/mike/git_rep/ldd3/sbull] Error 2
make[1]: Leaving directory '/home/mike/git_rep/linux'
Makefile:27: recipe for target 'default' failed
make: *** [default] Error 2

lddbus: bug: register_ldd_device

register_ldd_device always set ldddev->dev.name to "ldd0"

int register_ldd_device(struct ldd_device *ldddev)
{
	ldddev->dev.bus = &ldd_bus_type;
	ldddev->dev.parent = &ldd_bus;
	ldddev->dev.release = ldd_dev_release;
	dev_set_name(&ldddev->dev, "ldd0");
	return device_register(&ldddev->dev);
}
EXPORT_SYMBOL(register_ldd_device);

but ldd_driver->driver.name always "sculled"

static struct ldd_driver sculld_driver = {
	.version = "$Revision: 1.21 $",
	.module = THIS_MODULE,
	.driver = {
		.name = "sculld",
	},
};

that's make ldd device and ldd driver doesn't match:

static int ldd_match(struct device *dev, struct device_driver *driver)
{
	return !strncmp(dev_name(dev), driver->name, strlen(driver->name));
}

Compile fail Debian 11, kernel 5.10

I have just deployed a Debian 11 VM to start working through the LDD3 book.

I followed the instructions on the readme page of this project and encountered some build problems.

The first of these I believe is just a warning, I am not sure if this is harmless or not.

mapper.c:40:9: warning: implicit declaration of function ‘exit’ [-Wimplicit-function-declaration]

The second of these is the following:

  ERROR: Kernel configuration is invalid.
         include/generated/autoconf.h or include/config/auto.conf are missing.
         Run 'make oldconfig && make prepare' on kernel src to fix it.

I have no idea what this means. Given the instructions on the readme page do not have any mention of this (as far as I can see?) I guess this is a more serious issue.

I'm new to kernel/device driver development, so I am by no means an expert when it comes to this.

Bug in file short.c

function called with argument short_base:
release_mem_region(short_base, SHORT_NR_PORTS)
but value not exist after call to iounmap()
it should use base variable in place of it:
release_mem_region(base, SHORT_NR_PORTS)

If you will call following command you will get crash
cat /proc/iomem

Build failure with kernel versions < 5.17 due to usage of pde_data()

#78 replaced usages of PDE_DATA() with pde_data(), and now the examples fail to build with kernels before 5.17:

.../ldd3/misc-modules/jit.c:96:40: error: implicit declaration of function ‘pde_data’ [-Werror=implicit-function-declaration]
   96 |  return single_open(file, jit_fn_show, pde_data(inode));

Maybe some wrapper should be added to handle this depending on kernel version? I think it would be a good idea to not drop support for not the newest, but still recent and widely used kernels

build error: arch/x86/Makefile:153: CONFIG_X86_X32 enabled but no binutils support

Hi,
I just met build error with the following message.
Note that I have cross compile binary for aarch64 under my Download dir, but I remove the dir from PATH
I wonder how to avoid this problem, thanks.

make -C /lib/modules/4.13.0-37-generic/build M=/home/lihui/ldd3/scull modules
make[1]: Entering directory '/usr/src/linux-headers-4.13.0-37-generic'
arch/x86/Makefile:153: CONFIG_X86_X32 enabled but no binutils support
./scripts/gcc-version.sh: line 25: /home/lihui/Downloads/gcc-linaro-4.9.4-2017.01-x86_64_aarch64-elf/bingcc: No such file or directory
./scripts/gcc-version.sh: line 26: /home/lihui/Downloads/gcc-linaro-4.9.4-2017.01-x86_64_aarch64-elf/bingcc: No such file or directory
make[1]: /home/lihui/Downloads/gcc-linaro-4.9.4-2017.01-x86_64_aarch64-elf/bingcc: Command not found
make[1]: /home/lihui/Downloads/gcc-linaro-4.9.4-2017.01-x86_64_aarch64-elf/bingcc: Command not found
make[1]: /home/lihui/Downloads/gcc-linaro-4.9.4-2017.01-x86_64_aarch64-elf/bingcc: Command not found
make[1]: /home/lihui/Downloads/gcc-linaro-4.9.4-2017.01-x86_64_aarch64-elf/bingcc: Command not found
make[1]: /home/lihui/Downloads/gcc-linaro-4.9.4-2017.01-x86_64_aarch64-elf/bingcc: Command not found
CC [M] /home/lihui/ldd3/scull/main.o
/bin/sh: 1: /home/lihui/Downloads/gcc-linaro-4.9.4-2017.01-x86_64_aarch64-elf/bingcc: not found
scripts/Makefile.build:308: recipe for target '/home/lihui/ldd3/scull/main.o' failed
make[2]: *** [/home/lihui/ldd3/scull/main.o] Error 127
Makefile:1550: recipe for target 'module/home/lihui/ldd3/scull' failed
make[1]: *** [module/home/lihui/ldd3/scull] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.13.0-37-generic'
Makefile:30: recipe for target 'modules' failed
make: *** [modules] Error 2

Scull device number cleanup unregistering wrong major

Maybe I'm wrong (or it's an explicit omission, I haven't finished the book yet), but I think there is a bug with the example code in scull/main.c.

When doing cleanup, unregister_chrdev_region

unregister_chrdev_region(devno, scull_nr_devs);
is called on devno set at
dev_t devno = MKDEV(scull_major, scull_minor);
which is creating this with the parameters from the header. That covers one of the branchs of the if but in the case where we're dynamically allocating the major device number

ldd3/scull/main.c

Lines 628 to 632 in 13a7786

} else {
result = alloc_chrdev_region(&dev, scull_minor, scull_nr_devs,
"scull");
scull_major = MAJOR(dev);
}
there would be a mismatch I think.

I solved this by just initializing a global dev_t.

Errors while compiling => In jit.c

Was trying to make from directory ldd3. However, I got the following errors:
In function ‘jit_fn_open’: /home/meraj_hasan/ldd3/misc-modules/jit.c:96:40: error: implicit declaration of function ‘PDE_DATA’; did you mean ‘NODE_DATA’? [-Werror=implicit-function-declaration] 96 | return single_open(file, jit_fn_show, PDE_DATA(inode)); | ^~~~~~~~ | NODE_DATA /home/meraj_hasan/ldd3/misc-modules/jit.c:96:40: error: passing argument 3 of ‘single_open’ makes pointer from integer without a cast [-Werror=int-conversion] 96 | return single_open(file, jit_fn_show, PDE_DATA(inode)); | ^~~~~~~~~~~~~~~ | | | int In file included from /home/meraj_hasan/ldd3/misc-modules/jit.c:26: ./include/linux/seq_file.h:166:68: note: expected ‘void *’ but argument is of type ‘int’ 166 | int single_open(struct file *, int (*)(struct seq_file *, void *), void *); | ^~~~~~ /home/meraj_hasan/ldd3/misc-modules/jit.c: In function ‘jit_tasklet_open’: /home/meraj_hasan/ldd3/misc-modules/jit.c:306:45: error: passing argument 3 of ‘single_open’ makes pointer from integer without a cast [-Werror=int-conversion] 306 | return single_open(file, jit_tasklet_show, PDE_DATA(inode)); | ^~~~~~~~~~~~~~~ | | | int In file included from /home/meraj_hasan/ldd3/misc-modules/jit.c:26: ./include/linux/seq_file.h:166:68: note: expected ‘void *’ but argument is of type ‘int’ 166 | int single_open(struct file *, int (*)(struct seq_file *, void *), void *); | ^~~~~~ cc1: all warnings being treated as errors make[3]: *** [scripts/Makefile.build:250: /home/meraj_hasan/ldd3/misc-modules/jit.o] Error 1 make[2]: *** [Makefile:1992: /home/meraj_hasan/ldd3/misc-modules] Error 2 make[2]: Leaving directory '/home/meraj_hasan/linux' make[1]: *** [Makefile:20: modules] Error 2 make[1]: Leaving directory '/home/meraj_hasan/ldd3/misc-modules' make: *** [Makefile:10: subdirs] Error 1

How do I fix these? Earlier I had to do make oldconfig and make prepare in linux directory as some files were missing.

Bug for sbull and scull

when used linux 3.13.0-43-generic can,t build the .ko , has problem on scull/access.c error:invalid operands to binary. when make sbull .ko, has problem macro "__bio_kmap_atomic" passed 3 arguments but take just 2

*** No rule to make target 'Device'. Stop.

My hello.c code

#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
    printk(KERN_ALERT "Hello, world\n");
    return 0;
}

static void hello_exit(void)
{
    printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);

and my makefile

LDDINC=$(PWD)/../include
EXTRA_CFLAGS += -I$(LDDINC)

ifeq ($(KERNELRELEASE),)

    KERNELDIR ?= /lib/modules/$(shell uname -r)/build
    PWD := $(shell pwd)

modules:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

modules_install:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install

clean:
	rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions *.mod modules.order *.symvers

.PHONY: modules modules_install clean

else
    obj-m := hello.o
endif

and the output when i run make

make -C /lib/modules/5.13.0-22-generic/build M=/mnt/Programming/Programming/Linux Device Driver Dev modules
make[1]: Entering directory '/usr/src/linux-headers-5.13.0-22-generic'
make[1]: *** No rule to make target 'Device'.  Stop.
make[1]: Leaving directory '/usr/src/linux-headers-5.13.0-22-generic'
make: *** [Makefile:10: modules] Error 2

make dep doesn't work!

Hi guys!
I want to test the function of make dep,but it doesn't work properly.That's the log information.

uname -r

4.4.0-94-generic

pwd

/home/xxx/ldd3-examples-3.x/scull

make dep

cc -O2 -M *.c > .depend
access.c:21:26: fatal error: linux/module.h: No such file or directory
compilation terminated.
main.c:17:26: fatal error: linux/module.h: No such file or directory
compilation terminated.
pipe.c:17:26: fatal error: linux/module.h: No such file or directory
compilation terminated.
scull.mod.c:1:26: fatal error: linux/module.h: No such file or directory
compilation terminated.
Makefile:38: recipe for target 'dep' failed
make: *** [dep] Error 1

git branch

  • (HEAD detached at v4.4)
    master

sbull.c: implicit declaration of function blk_alloc_queue against kernel version 5.14.9

sbull.c fails to compile due to missing reference to blk_alloc_queue:

make[2]: Entering directory '/home/whanlon/kernelbuild/linux-5.14.9'
  CC [M]  /home/whanlon/LinuxDeviceDrivers/examples/ldd3/sbull/sbull.o
/home/whanlon/LinuxDeviceDrivers/examples/ldd3/sbull/sbull.c: In function 'blk_generic_alloc_queue':
/home/whanlon/LinuxDeviceDrivers/examples/ldd3/sbull/sbull.c:110:17: error: implicit declaration of function 'blk_alloc_queue'; did you mean 'blk_sync_queue'? [-Werror=implicit-function-declaration]
  110 |         return (blk_alloc_queue(node_id));
      |                 ^~~~~~~~~~~~~~~
      |                 blk_sync_queue
/home/whanlon/LinuxDeviceDrivers/examples/ldd3/sbull/sbull.c:110:17: warning: returning 'int' from a function with return type 'struct request_queue *' makes pointer from integer without a cast [-Wint-conversion]
  110 |         return (blk_alloc_queue(node_id));
      |                ~^~~~~~~~~~~~~~~~~~~~~~~~~

This is followed by a cascade of other errors, the end result is "make" fails when trying to compile sbull.c

Looking in the kernel source I find blk_alloc_queue in block/blk-core.c, but nowhere in linux-5.14.9/include. I also notice that blk_alloc_queue in blk-core.c is not followed by EXPORT_SYMBOL. Is this function deprecated in 5.14+ kernels? How to fix this to get ldd3 to compile?

NAPI in snull is broken

if (use_napi) {
    netif_napi_add(dev, &priv->napi, snull_poll,2);
}
memset(priv, 0, sizeof(struct snull_priv));

This code promptly erases the NAPI setup after adding it. As a result the poll never gets called after the interrupt handler calls napi_schedule.

does this project support to compile on WSL ?

uyplayer@UYPLAYER-PC:~/linux/ldd3$ make
for n in misc-progs misc-modules skull scull scullc scullp lddbus sculld scullv shortprint simple tty pci usb sbull snull short; do make -C $n || exit 1; done
make[1]: Entering directory '/home/uyplayer/linux/ldd3/misc-progs'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/uyplayer/linux/ldd3/misc-progs'
make[1]: Entering directory '/home/uyplayer/linux/ldd3/misc-modules'
make -C /lib/modules/5.10.16.3-microsoft-standard-WSL2/build M=/home/uyplayer/linux/ldd3/misc-modules modules
make[2]: Entering directory '/home/uyplayer/linux/ldd3/misc-modules'
make[2]: *** /lib/modules/5.10.16.3-microsoft-standard-WSL2/build: No such file or directory.  Stop.
make[2]: Leaving directory '/home/uyplayer/linux/ldd3/misc-modules'
make[1]: *** [Makefile:20: modules] Error 2
make[1]: Leaving directory '/home/uyplayer/linux/ldd3/misc-modules'
make: *** [Makefile:10: subdirs] Error 1

`dev_addr` in `struct net_device` has now been made `const`

dev_addr in struct net_device has now been made const and cannot be directly written to, e.g.:

https://patchwork.kernel.org/project/linux-media/patch/[email protected]/#24558423

The change I made to get snull to compile (but maybe not the best way):

        /*
         * Assign the hardware address of the board: use "\0SNULx", where
         * x is 0 or 1. The first byte is '\0' to avoid being a multicast
         * address (the first byte of multicast addrs is odd).
         */
-       memcpy(dev->dev_addr, "\0SNUL0", ETH_ALEN);
        if (dev == snull_devs[1])
-               dev->dev_addr[ETH_ALEN-1]++; /* \0SNUL1 */
+               eth_hw_addr_set(dev, "\0SNUL1");
+       else
+               eth_hw_addr_set(dev, "\0SNUL0");

(Not included the full diff, since I've changed other stuff in there while messing with it so the line numbers won't match; but between looking at it today and the last time I was messing with it, this const problem came up.)

May be an issue elsewhere? Not sure - haven't checked the other modules; just raising this as something that may need looking at.

driver scullpipe

scullpipe0-3, don't work after successfully run the command "scull.init start".
And then i find , the minor of scullpipe0-3 is 4-7 in scull_load shell, but the minor of scullpipe0-3 is 32~35 in scull.init shell.
error minor number is the reason.

proc interface has changed

The proc interface has changed and create_proc_entry is outdated. It will not compile under the 4.7.5 kernel, use proc_create instead (see proc_fs.h)

ldd3/misc-modules/seq.c: In function ‘ct_init’:
ldd3/misc-modules/seq.c:97:2: error: implicit declaration of function ‘create_proc_entry’ [-Werror=implicit-function-declaration]
entry = create_proc_entry("sequence", 0, NULL);
^
ldd3/misc-modules/seq.c:97:8: warning: assignment makes pointer from integer without a cast [enabled by default]
entry = create_proc_entry("sequence", 0, NULL);
^
ldd3/misc-modules/seq.c:99:8: error: dereferencing pointer to incomplete type
entry->proc_fops = &ct_file_ops;

Is the assignment operation is redundant?

dev->cdev.ops = &scull_fops;

Hi, martinezjavier.

The assignment operation: "dev->cdev.ops = &scull_fops;", already included in function cdev_init, whether in v2.6.12 or in v5.1-rc4.

so, the assignment is redundant?

The following code is taken from :
https://github.com/torvalds/linux/blob/master/fs/char_dev.c
v5.1-rc4

/**
 * cdev_init() - initialize a cdev structure
 * @cdev: the structure to initialize
 * @fops: the file_operations for this device
 *
 * Initializes @cdev, remembering @fops, making it ready to add to the
 * system with cdev_add().
 */
void cdev_init(struct cdev *cdev, const struct file_operations *fops)
{
	memset(cdev, 0, sizeof *cdev);
	INIT_LIST_HEAD(&cdev->list);
	kobject_init(&cdev->kobj, &ktype_cdev_default);
	cdev->ops = fops;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.