diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/tty/vt | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:
Single allocations: kmalloc(sizeof(TYPE), ...)
are replaced with: kmalloc_obj(TYPE, ...)
Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with: kmalloc_objs(TYPE, COUNT, ...)
Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...)
(where TYPE may also be *VAR)
The resulting allocations no longer return "void *", instead returning
"TYPE *".
Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'drivers/tty/vt')
| -rw-r--r-- | drivers/tty/vt/consolemap.c | 2 | ||||
| -rw-r--r-- | drivers/tty/vt/keyboard.c | 3 | ||||
| -rw-r--r-- | drivers/tty/vt/vc_screen.c | 2 | ||||
| -rw-r--r-- | drivers/tty/vt/vt.c | 5 |
4 files changed, 7 insertions, 5 deletions
diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c index 7a11c3f2e875..97cf1ceb6709 100644 --- a/drivers/tty/vt/consolemap.c +++ b/drivers/tty/vt/consolemap.c @@ -539,7 +539,7 @@ static int con_allocate_new(struct vc_data *vc) { struct uni_pagedict *new, *old = *vc->uni_pagedict_loc; - new = kzalloc(sizeof(*new), GFP_KERNEL); + new = kzalloc_obj(*new, GFP_KERNEL); if (!new) return -ENOMEM; diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c index 3538d54d6a6a..dba09eb91f38 100644 --- a/drivers/tty/vt/keyboard.c +++ b/drivers/tty/vt/keyboard.c @@ -1548,7 +1548,8 @@ static int kbd_connect(struct input_handler *handler, struct input_dev *dev, { int error; - struct input_handle __free(kfree) *handle = kzalloc(sizeof(*handle), GFP_KERNEL); + struct input_handle __free(kfree) *handle = kzalloc_obj(*handle, + GFP_KERNEL); if (!handle) return -ENOMEM; diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c index c814644ef4ee..824a74626548 100644 --- a/drivers/tty/vt/vc_screen.c +++ b/drivers/tty/vt/vc_screen.c @@ -131,7 +131,7 @@ vcs_poll_data_get(struct file *file) if (poll) return poll; - poll = kzalloc(sizeof(*poll), GFP_KERNEL); + poll = kzalloc_obj(*poll, GFP_KERNEL); if (!poll) return NULL; poll->cons_num = console(file_inode(file)); diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 3bdbd4c52c2f..cca7bdf8f2fe 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -1065,7 +1065,7 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */ /* although the numbers above are not valid since long ago, the point is still up-to-date and the comment still has its value even if only as a historical artifact. --mj, July 1998 */ - param.vc = vc = kzalloc(sizeof(struct vc_data), GFP_KERNEL); + param.vc = vc = kzalloc_obj(struct vc_data, GFP_KERNEL); if (!vc) return -ENOMEM; @@ -3777,7 +3777,8 @@ static int __init con_init(void) } for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) { - vc_cons[currcons].d = vc = kzalloc(sizeof(struct vc_data), GFP_NOWAIT); + vc_cons[currcons].d = vc = kzalloc_obj(struct vc_data, + GFP_NOWAIT); INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); tty_port_init(&vc->port); visual_init(vc, currcons, true); |
