summaryrefslogtreecommitdiff
path: root/drivers/tty/hvc
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-20 23:49:23 -0800
committerKees Cook <kees@kernel.org>2026-02-21 01:02:28 -0800
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/tty/hvc
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (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/hvc')
-rw-r--r--drivers/tty/hvc/hvc_console.c2
-rw-r--r--drivers/tty/hvc/hvc_iucv.c2
-rw-r--r--drivers/tty/hvc/hvc_opal.c2
-rw-r--r--drivers/tty/hvc/hvc_vio.c2
-rw-r--r--drivers/tty/hvc/hvc_xen.c8
-rw-r--r--drivers/tty/hvc/hvcs.c5
6 files changed, 10 insertions, 11 deletions
diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
index 6b58f340f210..9b3856766e8c 100644
--- a/drivers/tty/hvc/hvc_console.c
+++ b/drivers/tty/hvc/hvc_console.c
@@ -922,7 +922,7 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
return ERR_PTR(err);
}
- hp = kzalloc(struct_size(hp, outbuf, outbuf_size), GFP_KERNEL);
+ hp = kzalloc_flex(*hp, outbuf, outbuf_size, GFP_KERNEL);
if (!hp)
return ERR_PTR(-ENOMEM);
diff --git a/drivers/tty/hvc/hvc_iucv.c b/drivers/tty/hvc/hvc_iucv.c
index a7939c49c9cf..7fd3937d1396 100644
--- a/drivers/tty/hvc/hvc_iucv.c
+++ b/drivers/tty/hvc/hvc_iucv.c
@@ -1050,7 +1050,7 @@ static int __init hvc_iucv_alloc(int id, unsigned int is_console)
char name[9];
int rc;
- priv = kzalloc(sizeof(struct hvc_iucv_private), GFP_KERNEL);
+ priv = kzalloc_obj(struct hvc_iucv_private, GFP_KERNEL);
if (!priv)
return -ENOMEM;
diff --git a/drivers/tty/hvc/hvc_opal.c b/drivers/tty/hvc/hvc_opal.c
index b2ec1f6efa0a..72dfab77890c 100644
--- a/drivers/tty/hvc/hvc_opal.c
+++ b/drivers/tty/hvc/hvc_opal.c
@@ -181,7 +181,7 @@ static int hvc_opal_probe(struct platform_device *dev)
pv = hvc_opal_privs[termno];
boot = 1;
} else if (hvc_opal_privs[termno] == NULL) {
- pv = kzalloc(sizeof(struct hvc_opal_priv), GFP_KERNEL);
+ pv = kzalloc_obj(struct hvc_opal_priv, GFP_KERNEL);
if (!pv)
return -ENOMEM;
pv->proto = proto;
diff --git a/drivers/tty/hvc/hvc_vio.c b/drivers/tty/hvc/hvc_vio.c
index 47930601a26a..8725cc77c557 100644
--- a/drivers/tty/hvc/hvc_vio.c
+++ b/drivers/tty/hvc/hvc_vio.c
@@ -338,7 +338,7 @@ static int hvc_vio_probe(struct vio_dev *vdev,
pr_devel("->non-boot console, using termno %d\n", termno);
if (termno < 0)
return -ENODEV;
- pv = kzalloc(sizeof(struct hvterm_priv), GFP_KERNEL);
+ pv = kzalloc_obj(struct hvterm_priv, GFP_KERNEL);
if (!pv)
return -ENOMEM;
pv->termno = vdev->unit_address;
diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
index 95ec01b1aacf..138afdf3bbc4 100644
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -264,7 +264,7 @@ static int xen_hvm_console_init(void)
info = vtermno_to_xencons(HVC_COOKIE);
if (!info) {
- info = kzalloc(sizeof(struct xencons_info), GFP_KERNEL);
+ info = kzalloc_obj(struct xencons_info, GFP_KERNEL);
if (!info)
return -ENOMEM;
spin_lock_init(&info->ring_lock);
@@ -328,7 +328,7 @@ static int xen_pv_console_init(void)
info = vtermno_to_xencons(HVC_COOKIE);
if (!info) {
- info = kzalloc(sizeof(struct xencons_info), GFP_KERNEL);
+ info = kzalloc_obj(struct xencons_info, GFP_KERNEL);
if (!info)
return -ENOMEM;
} else if (info->intf != NULL) {
@@ -352,7 +352,7 @@ static int xen_initial_domain_console_init(void)
info = vtermno_to_xencons(HVC_COOKIE);
if (!info) {
- info = kzalloc(sizeof(struct xencons_info), GFP_KERNEL);
+ info = kzalloc_obj(struct xencons_info, GFP_KERNEL);
if (!info)
return -ENOMEM;
spin_lock_init(&info->ring_lock);
@@ -513,7 +513,7 @@ static int xencons_probe(struct xenbus_device *dev,
if (devid == 0)
return -ENODEV;
- info = kzalloc(sizeof(struct xencons_info), GFP_KERNEL);
+ info = kzalloc_obj(struct xencons_info, GFP_KERNEL);
if (!info)
return -ENOMEM;
spin_lock_init(&info->ring_lock);
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index f57fd9095f75..7ff3c87354b8 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -748,7 +748,7 @@ static int hvcs_probe(
return -EFAULT;
}
- hvcsd = kzalloc(sizeof(*hvcsd), GFP_KERNEL);
+ hvcsd = kzalloc_obj(*hvcsd, GFP_KERNEL);
if (!hvcsd)
return -ENODEV;
@@ -1394,8 +1394,7 @@ static int hvcs_alloc_index_list(int n)
{
int i;
- hvcs_index_list = kmalloc_array(n, sizeof(hvcs_index_count),
- GFP_KERNEL);
+ hvcs_index_list = kmalloc_objs(hvcs_index_count, n, GFP_KERNEL);
if (!hvcs_index_list)
return -ENOMEM;
hvcs_index_count = n;