summaryrefslogtreecommitdiff
path: root/drivers/regulator
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/regulator
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
downloadlinux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz
linux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.zip
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/regulator')
-rw-r--r--drivers/regulator/core.c17
-rw-r--r--drivers/regulator/fixed-helper.c2
-rw-r--r--drivers/regulator/of_regulator.c5
3 files changed, 11 insertions, 13 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 80bb95750a20..386304bc200c 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1740,7 +1740,7 @@ static int regulator_event_forward_notifier(struct notifier_block *nb,
return NOTIFY_DONE;
}
- rew = kmalloc(sizeof(*rew), GFP_ATOMIC);
+ rew = kmalloc_obj(*rew, GFP_ATOMIC);
if (!rew)
return NOTIFY_DONE;
@@ -1855,7 +1855,7 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
else
has_dev = 0;
- new_node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL);
+ new_node = kzalloc_obj(struct regulator_map, GFP_KERNEL);
if (new_node == NULL)
return -ENOMEM;
@@ -2021,7 +2021,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
return NULL;
}
- regulator = kzalloc(sizeof(*regulator), GFP_KERNEL);
+ regulator = kzalloc_obj(*regulator, GFP_KERNEL);
if (regulator == NULL) {
kfree_const(supply_name);
return NULL;
@@ -2701,7 +2701,7 @@ int regulator_register_supply_alias(struct device *dev, const char *id,
struct regulator_supply_alias *map;
struct regulator_supply_alias *new_map;
- new_map = kzalloc(sizeof(struct regulator_supply_alias), GFP_KERNEL);
+ new_map = kzalloc_obj(struct regulator_supply_alias, GFP_KERNEL);
if (!new_map)
return -ENOMEM;
@@ -2825,7 +2825,7 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev,
struct gpio_desc *gpiod;
gpiod = config->ena_gpiod;
- new_pin = kzalloc(sizeof(*new_pin), GFP_KERNEL);
+ new_pin = kzalloc_obj(*new_pin, GFP_KERNEL);
mutex_lock(&regulator_list_mutex);
@@ -5913,7 +5913,7 @@ static int regulator_init_coupling(struct regulator_dev *rdev)
else
n_phandles = of_get_n_coupled(rdev);
- coupled = kcalloc(n_phandles + 1, sizeof(*coupled), GFP_KERNEL);
+ coupled = kzalloc_objs(*coupled, n_phandles + 1, GFP_KERNEL);
if (!coupled)
return -ENOMEM;
@@ -6034,7 +6034,7 @@ regulator_register(struct device *dev,
goto rinse;
}
- rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
+ rdev = kzalloc_obj(struct regulator_dev, GFP_KERNEL);
if (rdev == NULL) {
ret = -ENOMEM;
goto rinse;
@@ -6117,8 +6117,7 @@ regulator_register(struct device *dev,
sizeof(*rdev->constraints),
GFP_KERNEL);
else
- rdev->constraints = kzalloc(sizeof(*rdev->constraints),
- GFP_KERNEL);
+ rdev->constraints = kzalloc_obj(*rdev->constraints, GFP_KERNEL);
if (!rdev->constraints) {
ret = -ENOMEM;
goto wash;
diff --git a/drivers/regulator/fixed-helper.c b/drivers/regulator/fixed-helper.c
index b6cb0aaac3b1..186a05b00733 100644
--- a/drivers/regulator/fixed-helper.c
+++ b/drivers/regulator/fixed-helper.c
@@ -34,7 +34,7 @@ struct platform_device *regulator_register_always_on(int id, const char *name,
{
struct fixed_regulator_data *data;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return NULL;
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 33463926a2a6..93fab4fb2adf 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -973,9 +973,8 @@ restart:
}
if (num_consumers == 0)
return 0;
- _consumers = kmalloc_array(num_consumers,
- sizeof(struct regulator_bulk_data),
- GFP_KERNEL);
+ _consumers = kmalloc_objs(struct regulator_bulk_data, num_consumers,
+ GFP_KERNEL);
if (!_consumers)
return -ENOMEM;
goto restart;