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/power | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | linux-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/power')
| -rw-r--r-- | drivers/power/sequencing/core.c | 9 | ||||
| -rw-r--r-- | drivers/power/sequencing/pwrseq-thead-gpu.c | 2 | ||||
| -rw-r--r-- | drivers/power/supply/cros_peripheral_charger.c | 2 | ||||
| -rw-r--r-- | drivers/power/supply/cros_usbpd-charger.c | 2 | ||||
| -rw-r--r-- | drivers/power/supply/pmu_battery.c | 3 | ||||
| -rw-r--r-- | drivers/power/supply/power_supply_core.c | 2 | ||||
| -rw-r--r-- | drivers/power/supply/power_supply_leds.c | 2 |
7 files changed, 10 insertions, 12 deletions
diff --git a/drivers/power/sequencing/core.c b/drivers/power/sequencing/core.c index 1fcf0af7cc0b..666bcfd3c655 100644 --- a/drivers/power/sequencing/core.c +++ b/drivers/power/sequencing/core.c @@ -90,7 +90,7 @@ static struct pwrseq_unit *pwrseq_unit_new(const struct pwrseq_unit_data *data) { struct pwrseq_unit *unit; - unit = kzalloc(sizeof(*unit), GFP_KERNEL); + unit = kzalloc_obj(*unit, GFP_KERNEL); if (!unit) return NULL; @@ -138,7 +138,7 @@ static struct pwrseq_unit_dep *pwrseq_unit_dep_new(struct pwrseq_unit *unit) { struct pwrseq_unit_dep *dep; - dep = kzalloc(sizeof(*dep), GFP_KERNEL); + dep = kzalloc_obj(*dep, GFP_KERNEL); if (!dep) return NULL; @@ -195,7 +195,7 @@ pwrseq_target_new(const struct pwrseq_target_data *data) { struct pwrseq_target *target; - target = kzalloc(sizeof(*target), GFP_KERNEL); + target = kzalloc_obj(*target, GFP_KERNEL); if (!target) return NULL; @@ -669,8 +669,7 @@ struct pwrseq_desc *pwrseq_get(struct device *dev, const char *target) struct pwrseq_match_data match_data; int ret; - struct pwrseq_desc *desc __free(kfree) = kzalloc(sizeof(*desc), - GFP_KERNEL); + struct pwrseq_desc *desc __free(kfree) = kzalloc_obj(*desc, GFP_KERNEL); if (!desc) return ERR_PTR(-ENOMEM); diff --git a/drivers/power/sequencing/pwrseq-thead-gpu.c b/drivers/power/sequencing/pwrseq-thead-gpu.c index 7c82a10ca9f6..ce32201f5a21 100644 --- a/drivers/power/sequencing/pwrseq-thead-gpu.c +++ b/drivers/power/sequencing/pwrseq-thead-gpu.c @@ -145,7 +145,7 @@ static int pwrseq_thead_gpu_match(struct pwrseq_device *pwrseq, PWRSEQ_MATCH_OK : PWRSEQ_NO_MATCH; ctx->num_clks = ARRAY_SIZE(clk_names); - ctx->clks = kcalloc(ctx->num_clks, sizeof(*ctx->clks), GFP_KERNEL); + ctx->clks = kzalloc_objs(*ctx->clks, ctx->num_clks, GFP_KERNEL); if (!ctx->clks) return -ENOMEM; diff --git a/drivers/power/supply/cros_peripheral_charger.c b/drivers/power/supply/cros_peripheral_charger.c index 962a6fd29832..7d48ab4a60b2 100644 --- a/drivers/power/supply/cros_peripheral_charger.c +++ b/drivers/power/supply/cros_peripheral_charger.c @@ -64,7 +64,7 @@ static int cros_pchg_ec_command(const struct charger_data *charger, 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/power/supply/cros_usbpd-charger.c b/drivers/power/supply/cros_usbpd-charger.c index 47d3f58aa15c..6b525ed74197 100644 --- a/drivers/power/supply/cros_usbpd-charger.c +++ b/drivers/power/supply/cros_usbpd-charger.c @@ -94,7 +94,7 @@ static int cros_usbpd_charger_ec_command(struct charger_data *charger, 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/power/supply/pmu_battery.c b/drivers/power/supply/pmu_battery.c index ed83c5e05ca3..054f75d904a8 100644 --- a/drivers/power/supply/pmu_battery.c +++ b/drivers/power/supply/pmu_battery.c @@ -160,8 +160,7 @@ static int __init pmu_bat_init(void) for (i = 0; i < pmu_battery_count; i++) { struct power_supply_config psy_cfg = {}; - struct pmu_battery_dev *pbat = kzalloc(sizeof(*pbat), - GFP_KERNEL); + struct pmu_battery_dev *pbat = kzalloc_obj(*pbat, GFP_KERNEL); if (!pbat) break; diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 9a28381e2607..91e8b18e09ff 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -1426,7 +1426,7 @@ int power_supply_register_extension(struct power_supply *psy, const struct power if (power_supply_has_property(psy, ext->properties[i])) return -EEXIST; - reg = kmalloc(sizeof(*reg), GFP_KERNEL); + reg = kmalloc_obj(*reg, GFP_KERNEL); if (!reg) return -ENOMEM; diff --git a/drivers/power/supply/power_supply_leds.c b/drivers/power/supply/power_supply_leds.c index f4a7e566bea1..af32dc2e0210 100644 --- a/drivers/power/supply/power_supply_leds.c +++ b/drivers/power/supply/power_supply_leds.c @@ -48,7 +48,7 @@ static int power_supply_register_led_trigger(struct power_supply *psy, if (err && *err) return *err; - psy_trig = kzalloc(sizeof(*psy_trig), GFP_KERNEL); + psy_trig = kzalloc_obj(*psy_trig, GFP_KERNEL); if (!psy_trig) goto err_free_trigger; |
