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/base/power | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (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/base/power')
| -rw-r--r-- | drivers/base/power/clock_ops.c | 4 | ||||
| -rw-r--r-- | drivers/base/power/common.c | 4 | ||||
| -rw-r--r-- | drivers/base/power/qos.c | 10 | ||||
| -rw-r--r-- | drivers/base/power/wakeirq.c | 4 | ||||
| -rw-r--r-- | drivers/base/power/wakeup.c | 2 | ||||
| -rw-r--r-- | drivers/base/power/wakeup_stats.c | 2 |
6 files changed, 13 insertions, 13 deletions
diff --git a/drivers/base/power/clock_ops.c b/drivers/base/power/clock_ops.c index b69bcb37c830..0ac1e6757ec5 100644 --- a/drivers/base/power/clock_ops.c +++ b/drivers/base/power/clock_ops.c @@ -201,7 +201,7 @@ static int __pm_clk_add(struct device *dev, const char *con_id, if (!psd) return -EINVAL; - ce = kzalloc(sizeof(*ce), GFP_KERNEL); + ce = kzalloc_obj(*ce, GFP_KERNEL); if (!ce) return -ENOMEM; @@ -282,7 +282,7 @@ int of_pm_clk_add_clks(struct device *dev) if (count <= 0) return -ENODEV; - clks = kcalloc(count, sizeof(*clks), GFP_KERNEL); + clks = kzalloc_objs(*clks, count, GFP_KERNEL); if (!clks) return -ENOMEM; diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c index 6ecf9ce4a4e6..5902658ee94f 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -27,7 +27,7 @@ int dev_pm_get_subsys_data(struct device *dev) { struct pm_subsys_data *psd; - psd = kzalloc(sizeof(*psd), GFP_KERNEL); + psd = kzalloc_obj(*psd, GFP_KERNEL); if (!psd) return -ENOMEM; @@ -222,7 +222,7 @@ int dev_pm_domain_attach_list(struct device *dev, if (num_pds <= 0) return 0; - pds = kzalloc(sizeof(*pds), GFP_KERNEL); + pds = kzalloc_obj(*pds, GFP_KERNEL); if (!pds) return -ENOMEM; diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c index ff393cba7649..31acf7ef5d87 100644 --- a/drivers/base/power/qos.c +++ b/drivers/base/power/qos.c @@ -198,11 +198,11 @@ static int dev_pm_qos_constraints_allocate(struct device *dev) struct pm_qos_constraints *c; struct blocking_notifier_head *n; - qos = kzalloc(sizeof(*qos), GFP_KERNEL); + qos = kzalloc_obj(*qos, GFP_KERNEL); if (!qos) return -ENOMEM; - n = kcalloc(3, sizeof(*n), GFP_KERNEL); + n = kzalloc_objs(*n, 3, GFP_KERNEL); if (!n) { kfree(qos); return -ENOMEM; @@ -704,7 +704,7 @@ int dev_pm_qos_expose_latency_limit(struct device *dev, s32 value) if (!device_is_registered(dev) || value < 0) return -EINVAL; - req = kzalloc(sizeof(*req), GFP_KERNEL); + req = kzalloc_obj(*req, GFP_KERNEL); if (!req) return -ENOMEM; @@ -780,7 +780,7 @@ int dev_pm_qos_expose_flags(struct device *dev, s32 val) if (!device_is_registered(dev)) return -EINVAL; - req = kzalloc(sizeof(*req), GFP_KERNEL); + req = kzalloc_obj(*req, GFP_KERNEL); if (!req) return -ENOMEM; @@ -919,7 +919,7 @@ int dev_pm_qos_update_user_latency_tolerance(struct device *dev, s32 val) ret = -EINVAL; goto out; } - req = kzalloc(sizeof(*req), GFP_KERNEL); + req = kzalloc_obj(*req, GFP_KERNEL); if (!req) { ret = -ENOMEM; goto out; diff --git a/drivers/base/power/wakeirq.c b/drivers/base/power/wakeirq.c index aab843f6dfcc..19abc6a8eaa3 100644 --- a/drivers/base/power/wakeirq.c +++ b/drivers/base/power/wakeirq.c @@ -55,7 +55,7 @@ int dev_pm_set_wake_irq(struct device *dev, int irq) if (irq < 0) return -EINVAL; - wirq = kzalloc(sizeof(*wirq), GFP_KERNEL); + wirq = kzalloc_obj(*wirq, GFP_KERNEL); if (!wirq) return -ENOMEM; @@ -179,7 +179,7 @@ static int __dev_pm_set_dedicated_wake_irq(struct device *dev, int irq, unsigned if (irq < 0) return -EINVAL; - wirq = kzalloc(sizeof(*wirq), GFP_KERNEL); + wirq = kzalloc_obj(*wirq, GFP_KERNEL); if (!wirq) return -ENOMEM; diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index e69033d16fba..a3714a9e4e46 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c @@ -83,7 +83,7 @@ static struct wakeup_source *wakeup_source_create(const char *name) const char *ws_name; int id; - ws = kzalloc(sizeof(*ws), GFP_KERNEL); + ws = kzalloc_obj(*ws, GFP_KERNEL); if (!ws) goto err_ws; diff --git a/drivers/base/power/wakeup_stats.c b/drivers/base/power/wakeup_stats.c index 3ffd427248e8..af888678156f 100644 --- a/drivers/base/power/wakeup_stats.c +++ b/drivers/base/power/wakeup_stats.c @@ -141,7 +141,7 @@ static struct device *wakeup_source_device_create(struct device *parent, struct device *dev = NULL; int retval; - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + dev = kzalloc_obj(*dev, GFP_KERNEL); if (!dev) { retval = -ENOMEM; goto error; |
