8000 replace deprecated strlcpy() w/ strscpy() · secoba/Linux-Kernel-Programming@c55efbb · GitHub
[go: up one dir, main page]

Skip to content

Commit c55efbb

Browse files
committed
replace deprecated strlcpy() w/ strscpy()
1 parent 54b280f commit c55efbb

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

ch12/1_miscdrv_rdwr_mutexlock/miscdrv_rdwr_mutexlock.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static ssize_t write_miscdrv_rdwr(struct file *filp, const char __user *ubuf,
203203
* new 'secret' into our driver 'context' structure, and unlock.
204204
*/
205205
mutex_lock(&ctx->lock);
206-
strlcpy(ctx->oursecret, kbuf, (count > MAXBYTES ? MAXBYTES : count));
206+
strscpy(ctx->oursecret, kbuf, (count > MAXBYTES ? MAXBYTES : count));
207207
#if 0
208208
print_hex_dump_bytes("ctx ", DUMP_PREFIX_OFFSET, ctx, sizeof(struct drv_ctx));
209209
#endif
@@ -293,8 +293,8 @@ static int __init miscdrv_init_mutexlock(void)
293293
ctx->dev = llkd_miscdev.this_device;
294294

295295
/* Initialize the "secret" value :-) */
296-
strlcpy(ctx->oursecret, "initmsg", 8);
297-
/* Why don't we protect the above strlcpy() with the mutex lock?
296+
strscpy(ctx->oursecret, "initmsg", 8);
297+
/* Why don't we protect the above strscpy() with the mutex lock?
298298
* It's working on shared writable data, yes?
299299
* Yes, BUT this is the init code; it's guaranteed to run in exactly
300300
* one context (typically the insmod(8) process), thus there is

ch12/2_miscdrv_rdwr_spinlock/miscdrv_rdwr_spinlock.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
2-
* ch16/2_miscdrv_rdwr_spinlock/miscdrv_rdwr_spinlock.c
2+
* ch12/2_miscdrv_rdwr_spinlock/miscdrv_rdwr_spinlock.c
33
***************************************************************
44
* This program is part of the source code released for the book
5-
* "Linux Kernel Development Cookbook"
5+
* "Linux Kernel Programming"
66
* (c) Author: Kaiwan N Billimoria
77
* Publisher: Packt
88
* GitHub repository:
9-
* https://github.com/PacktPublishing/Linux-Kernel-Development-Cookbook
9+
* https://github.com/PacktPublishing/Linux-Kernel-Programming
1010
*
11-
* From: Ch 16 : Kernel Synchronization - Part 1
11+
* From: Ch 12 : Kernel Synchronization - Part 1
1212
****************************************************************
1313
* Brief Description:
1414
* This driver is built upon our previous ch16/1_miscdrv_rdwr_mutexlock/
@@ -17,7 +17,7 @@
1717
* the case everywhere in the driver though; we keep the mutex as well for some
1818
* portions of the driver).
1919
*
20-
* For details, please refer the book, Ch 16.
20+
* For details, please refer the book, Ch 12.
2121
*/
2222
#define pr_fmt(fmt) "%s:%s(): " fmt, KBUILD_MODNAME, __func__
2323

@@ -231,7 +231,7 @@ static ssize_t write_miscdrv_rdwr(struct file *filp, const char __user *ubuf,
231231
* new 'secret' into our driver 'context' structure, and unlock.
232232
*/
233233
spin_lock(&ctx->spinlock);
234-
strlcpy(ctx->oursecret, kbuf, (count > MAXBYTES ? MAXBYTES : count));
234+
strscpy(ctx->oursecret, kbuf, (count > MAXBYTES ? MAXBYTES : count));
235235
#if 0
236236
print_hex_dump_bytes("ctx ", DUMP_PREFIX_OFFSET,
237237
ctx, sizeof(struct drv_ctx));
@@ -331,8 +331,8 @@ static int __init miscdrv_init_spinlock(void)
331331
/* Retrieve the device pointer for this device */
332332
ctx->dev = llkd_miscdev.this_device;
333333

334-
strlcpy(ctx->oursecret, "initmsg", 8);
335-
/* Why don't we protect the above strlcpy() with the mutex / spinlock?
334+
strscpy(ctx->oursecret, "initmsg", 8);
335+
/* Why don't we protect the above strscpy() with the mutex / spinlock?
336336
* It's working on shared writable data, yes?
337337
* No; this is the init code; it's guaranteed to run in exactly
338338
* one context (typically the insmod(8) process), thus there is

0 commit comments

Comments
 (0)
0