8000 Merge branch 'master' of https://github.com/PacktPublishing/Linux-Ker… · yurembo/Linux-Kernel-Programming@fc61781 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc61781

Browse files
committed
2 parents 7f04301 + 657b736 commit fc61781

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ Wrt the PDF doc:
8181

8282
`Aarch64: 4 : 48 --> 49 : 256T:256T : corrected (allows for total of 512 T)`
8383

84+
- pg 385:
85+
- 'On high-end enterprise server class systems running the Itanium (IA-64) processor, MAX_ORDER can be as high as 17 (implying a
86+
largest chunk size on order (17-1), thus of 216 = 65,536 pages = 512 MB chunks of physically contiguous RAM on order 16 of the freelists, for
87+
a 4 KB page size).'
88+
should be:
89+
'On high-end enterprise server class systems running the Itanium (IA-64) processor, MAX_ORDER can be as high as 17 (implying a
90+
largest chunk size on order (17-1), thus of 216 = 65,536 pages = *256 MB* chunks of physically contiguous RAM on order 16 of the freelists, for
91+
a 4 KB page size).'
92+
8493
- pg 388:
8594
- '... the next available memory chunk is on order 7, of size 256 KB.' should be: '... the next available memory chunk is on order 6, of size 256 KB.
8695

@@ -107,7 +116,7 @@ peripheral device (chip) memory and registers; we have covered this in detail in
107116
Linux Kernel Programming Part 2 - Chapter 3, Working with Hardware I/O Memory.
108117
Please ensure that you understand it before moving forward."
109118
```
110-
119+
* pg 183 : **Wiring to the console** _should be_ **Writing to the console**
111120

112121
### Related products
113122
* Mastering Linux Device Driver Development [[Packt]](https://www.packtpub.com/product/Mastering-Linux-Device-Driver-Development/9781789342048) [[Amazon]](https://www.amazon.com/Mastering-Linux-Device-Driver-Development/dp/178934204X)

ch12/1_miscdrv_rdwr_mutexlock/miscdrv_rdwr_mutexlock.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@
1111
* From: Ch 12 : Kernel Synchronization - Part 1
1212
****************************************************************
1313
* Brief Description:
14-
* This driver is built upon our previous ch12/miscdrv_rdwr/ misc driver.
14+
* This driver is built upon the LKP Part 2 book's first chapter 'misc' driver here:
15+
* https://github.com/PacktPublishing/Linux-Kernel-Programming-Part-2/tree/main/ch1/miscdrv_rdwr
16+
*
1517
* The really important and key difference: previously, we used a few global data
1618
* items throughout *without* protection; this time, we fix this egregious error
1719
* by using a mutex lock to protect the critical sections - the places in the
1820
* code where we access global / shared writeable data.
1921
* The functionality (the get and set of the 'secret') remains identical to the
2022
* original implementation.
2123
*
22-
* For details, please refer the book, Ch 12.
24+
* Note: also do
25+
* make rdwr_test_secret
26+
* to build the user space app for testing...
27+
*
28+
* For details, please refer both the books, Ch 12 and Ch 1 resp.
2329
*/
2430
#define pr_fmt(fmt) "%s:%s(): " fmt, KBUILD_MODNAME, __func__
2531

@@ -286,7 +292,7 @@ static int __init miscdrv_init_mutexlock(void)
286292
* freeing the memory automatically upon driver 'detach' or when the driver
287293
* is unloaded from memory
288294
*/
289-
ctx = kzalloc(sizeof(struct drv_ctx), GFP_KERNEL);
295+
ctx = devm_kzalloc(llkd_miscdev.this_device, sizeof(struct drv_ctx), GFP_KERNEL);
290296
if (unlikely(!ctx))
291297
return -ENOMEM;
292298

ch12/2_miscdrv_rdwr_spinlock/miscdrv_rdwr_spinlock.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@
1313
* Brief Description:
1414
* This driver is built upon our previous ch12/1_miscdrv_rdwr_mutexlock/
1515
* misc driver.
16-
* The key difference: we use spinlocks in place of the mutex locks (this isn't
16+
*
17+
* The key difference: we use a spinlock in place of the mutex locks (this isn't
1718
* the case everywhere in the driver though; we keep the mutex as well for some
1819
* portions of the driver).
20+
* The functionality (the get and set of the 'secret') remains identical to the
21+
* original implementation.
22+
*
23+
* Note: also do
24+
* make rdwr_test_secret
25+
* to build the user space app for testing...
1926
*
20-
* For details, please refer the book, Ch 12.
27+
* For details, please refer both the books, Ch 12 and Ch 1 resp.
2128
*/
2229
#define pr_fmt(fmt) "%s:%s(): " fmt, KBUILD_MODNAME, __func__
2330

@@ -324,7 +331,7 @@ static int __init miscdrv_init_spinlock(void)
324331
* freeing the memory automatically upon driver 'detach' or when the driver
325332
* is unloaded from memory
326333
*/
327-
ctx = kzalloc(sizeof(struct drv_ctx), GFP_KERNEL);
334+
ctx = devm_kzalloc(llkd_miscdev.this_device, sizeof(struct drv_ctx), GFP_KERNEL);
328335
if (unlikely(!ctx))
329336
return -ENOMEM;
330337

ch8/lowlevel_mem/lowlevel_mem.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ static int bsa_alloc(void)
120120
" (struct page addr=%pK (%px))\n",
121121
OURMODNAME, (void *)gptr4, (void *)gptr4, pg_ptr1, pg_ptr1);
122122

123-
/* 5. Allocate and init 2^5 = 32 pages with the alloc_pages() API.
123+
/* 5. Allocate and init 2^3 = 8 pages with the alloc_pages() API.
124124
* < Same warning as above applies here too! >
125125
*/
126-
gptr5 = page_address(alloc_pages(GFP_KERNEL, 5));
126+
gptr5 = page_address(alloc_pages(GFP_KERNEL, 3));
127127
if (!gptr5)
128128
goto out5;
129129
pr_info("%s: 5. alloc_pages() alloc'ed %lld pages from the BSA @ %pK (%px)\n",
130-
OURMODNAME, powerof(2, 5), (void *)gptr5, (void *)gptr5);
130+
OURMODNAME, powerof(2, 3), (void *)gptr5, (void *)gptr5);
131131

132132
return 0;
133133
out5:

0 commit comments

Comments
 (0)
0