summaryrefslogtreecommitdiff
path: root/drivers/gpib/common
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/gpib/common
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/gpib/common')
-rw-r--r--drivers/gpib/common/gpib_os.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/gpib/common/gpib_os.c b/drivers/gpib/common/gpib_os.c
index 9dbbac8b8436..08da67543bac 100644
--- a/drivers/gpib/common/gpib_os.c
+++ b/drivers/gpib/common/gpib_os.c
@@ -199,7 +199,7 @@ int push_status_byte(struct gpib_board *board, struct gpib_status_queue *device,
return retval;
}
- status = kmalloc(sizeof(*status), GFP_KERNEL);
+ status = kmalloc_obj(*status, GFP_KERNEL);
if (!status)
return -ENOMEM;
@@ -513,7 +513,7 @@ static int init_gpib_file_private(struct gpib_file_private *priv)
{
memset(priv, 0, sizeof(*priv));
atomic_set(&priv->holding_mutex, 0);
- priv->descriptors[0] = kmalloc(sizeof(struct gpib_descriptor), GFP_KERNEL);
+ priv->descriptors[0] = kmalloc_obj(struct gpib_descriptor, GFP_KERNEL);
if (!priv->descriptors[0]) {
pr_err("gpib: failed to allocate default board descriptor\n");
return -ENOMEM;
@@ -537,7 +537,7 @@ int ibopen(struct inode *inode, struct file *filep)
board = &board_array[minor];
- filep->private_data = kmalloc(sizeof(struct gpib_file_private), GFP_KERNEL);
+ filep->private_data = kmalloc_obj(struct gpib_file_private, GFP_KERNEL);
if (!filep->private_data)
return -ENOMEM;
@@ -1146,7 +1146,7 @@ static int increment_open_device_count(struct gpib_board *board, struct list_hea
}
/* otherwise we need to allocate a new struct gpib_status_queue */
- device = kmalloc(sizeof(struct gpib_status_queue), GFP_ATOMIC);
+ device = kmalloc_obj(struct gpib_status_queue, GFP_ATOMIC);
if (!device)
return -ENOMEM;
init_gpib_status_queue(device);
@@ -1241,7 +1241,8 @@ static int open_dev_ioctl(struct file *filep, struct gpib_board *board, unsigned
mutex_unlock(&file_priv->descriptors_mutex);
return -ERANGE;
}
- file_priv->descriptors[i] = kmalloc(sizeof(struct gpib_descriptor), GFP_KERNEL);
+ file_priv->descriptors[i] = kmalloc_obj(struct gpib_descriptor,
+ GFP_KERNEL);
if (!file_priv->descriptors[i]) {
mutex_unlock(&file_priv->descriptors_mutex);
return -ENOMEM;
@@ -1876,7 +1877,7 @@ static int push_gpib_event_nolock(struct gpib_board *board, short event_type)
return retval;
}
- event = kmalloc(sizeof(struct gpib_event), GFP_ATOMIC);
+ event = kmalloc_obj(struct gpib_event, GFP_ATOMIC);
if (!event) {
queue->dropped_event = 1;
dev_err(board->gpib_dev, "failed to allocate memory for event\n");
@@ -2041,7 +2042,7 @@ int gpib_register_driver(struct gpib_interface *interface, struct module *provid
{
struct gpib_interface_list *entry;
- entry = kmalloc(sizeof(*entry), GFP_KERNEL);
+ entry = kmalloc_obj(*entry, GFP_KERNEL);
if (!entry)
return -ENOMEM;