summaryrefslogtreecommitdiff
path: root/drivers/extcon
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/extcon
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/extcon')
-rw-r--r--drivers/extcon/extcon-usbc-cros-ec.c2
-rw-r--r--drivers/extcon/extcon.c24
2 files changed, 13 insertions, 13 deletions
diff --git a/drivers/extcon/extcon-usbc-cros-ec.c b/drivers/extcon/extcon-usbc-cros-ec.c
index 1fb627ea8b50..cf30d54fb418 100644
--- a/drivers/extcon/extcon-usbc-cros-ec.c
+++ b/drivers/extcon/extcon-usbc-cros-ec.c
@@ -68,7 +68,7 @@ static int cros_ec_pd_command(struct cros_ec_extcon_info *info,
struct cros_ec_command *msg;
int ret;
- msg = kzalloc(struct_size(msg, data, max(outsize, insize)), GFP_KERNEL);
+ msg = kzalloc_flex(*msg, data, max(outsize, insize), GFP_KERNEL);
if (!msg)
return -ENOMEM;
diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
index e7f55c021e56..8fc412ad3cf2 100644
--- a/drivers/extcon/extcon.c
+++ b/drivers/extcon/extcon.c
@@ -1060,7 +1060,7 @@ struct extcon_dev *extcon_dev_allocate(const unsigned int *supported_cable)
if (!supported_cable)
return ERR_PTR(-EINVAL);
- edev = kzalloc(sizeof(*edev), GFP_KERNEL);
+ edev = kzalloc_obj(*edev, GFP_KERNEL);
if (!edev)
return ERR_PTR(-ENOMEM);
@@ -1098,8 +1098,8 @@ static int extcon_alloc_cables(struct extcon_dev *edev)
if (!edev->max_supported)
return 0;
- edev->cables = kcalloc(edev->max_supported, sizeof(*edev->cables),
- GFP_KERNEL);
+ edev->cables = kzalloc_objs(*edev->cables, edev->max_supported,
+ GFP_KERNEL);
if (!edev->cables)
return -ENOMEM;
@@ -1160,13 +1160,13 @@ static int extcon_alloc_muex(struct extcon_dev *edev)
for (index = 0; edev->mutually_exclusive[index]; index++)
;
- edev->attrs_muex = kcalloc(index + 1, sizeof(*edev->attrs_muex),
- GFP_KERNEL);
+ edev->attrs_muex = kzalloc_objs(*edev->attrs_muex, index + 1,
+ GFP_KERNEL);
if (!edev->attrs_muex)
return -ENOMEM;
- edev->d_attrs_muex = kcalloc(index, sizeof(*edev->d_attrs_muex),
- GFP_KERNEL);
+ edev->d_attrs_muex = kzalloc_objs(*edev->d_attrs_muex, index,
+ GFP_KERNEL);
if (!edev->d_attrs_muex) {
kfree(edev->attrs_muex);
return -ENOMEM;
@@ -1210,9 +1210,9 @@ static int extcon_alloc_groups(struct extcon_dev *edev)
if (!edev->max_supported)
return 0;
- edev->extcon_dev_type.groups = kcalloc(edev->max_supported + 2,
- sizeof(*edev->extcon_dev_type.groups),
- GFP_KERNEL);
+ edev->extcon_dev_type.groups = kzalloc_objs(*edev->extcon_dev_type.groups,
+ edev->max_supported + 2,
+ GFP_KERNEL);
if (!edev->extcon_dev_type.groups)
return -ENOMEM;
@@ -1294,8 +1294,8 @@ int extcon_dev_register(struct extcon_dev *edev)
spin_lock_init(&edev->lock);
if (edev->max_supported) {
- edev->nh = kcalloc(edev->max_supported, sizeof(*edev->nh),
- GFP_KERNEL);
+ edev->nh = kzalloc_objs(*edev->nh, edev->max_supported,
+ GFP_KERNEL);
if (!edev->nh) {
ret = -ENOMEM;
goto err_alloc_nh;