summaryrefslogtreecommitdiff
path: root/drivers/hwmon
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/hwmon
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/hwmon')
-rw-r--r--drivers/hwmon/acpi_power_meter.c7
-rw-r--r--drivers/hwmon/applesmc.c4
-rw-r--r--drivers/hwmon/coretemp.c12
-rw-r--r--drivers/hwmon/drivetemp.c2
-rw-r--r--drivers/hwmon/fschmd.c2
-rw-r--r--drivers/hwmon/hwmon.c8
-rw-r--r--drivers/hwmon/i5k_amb.c2
-rw-r--r--drivers/hwmon/ibmaem.c4
-rw-r--r--drivers/hwmon/ibmpex.c6
-rw-r--r--drivers/hwmon/sch56xx-common.c2
-rw-r--r--drivers/hwmon/via-cputemp.c2
-rw-r--r--drivers/hwmon/w83793.c2
12 files changed, 26 insertions, 27 deletions
diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
index 7cb66216f358..1fa3657f4630 100644
--- a/drivers/hwmon/acpi_power_meter.c
+++ b/drivers/hwmon/acpi_power_meter.c
@@ -245,9 +245,8 @@ static int read_domain_devices(struct acpi_power_meter_resource *resource)
if (!pss->package.count)
goto end;
- resource->domain_devices = kcalloc(pss->package.count,
- sizeof(struct acpi_device *),
- GFP_KERNEL);
+ resource->domain_devices = kzalloc_objs(struct acpi_device *,
+ pss->package.count, GFP_KERNEL);
if (!resource->domain_devices) {
res = -ENOMEM;
goto end;
@@ -893,7 +892,7 @@ static int acpi_power_meter_add(struct acpi_device *device)
if (!device)
return -EINVAL;
- resource = kzalloc(sizeof(*resource), GFP_KERNEL);
+ resource = kzalloc_obj(*resource, GFP_KERNEL);
if (!resource)
return -ENOMEM;
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index fc6d6a9053ce..0dbad1d3808c 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -586,7 +586,7 @@ static int applesmc_init_smcreg_try(void)
s->key_count = count;
if (!s->cache)
- s->cache = kcalloc(s->key_count, sizeof(*s->cache), GFP_KERNEL);
+ s->cache = kzalloc_objs(*s->cache, s->key_count, GFP_KERNEL);
if (!s->cache)
return -ENOMEM;
@@ -1141,7 +1141,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
int ret, i;
for (grp = groups; grp->format; grp++) {
- grp->nodes = kcalloc(num + 1, sizeof(*node), GFP_KERNEL);
+ grp->nodes = kzalloc_objs(*node, num + 1, GFP_KERNEL);
if (!grp->nodes) {
ret = -ENOMEM;
goto out;
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index d2dfa4e30407..eb00a9f08955 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -492,13 +492,13 @@ init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag)
* when this information becomes available.
*/
pdata->nr_cores = NUM_REAL_CORES;
- pdata->core_data = kcalloc(pdata->nr_cores, sizeof(struct temp_data *),
- GFP_KERNEL);
+ pdata->core_data = kzalloc_objs(struct temp_data *,
+ pdata->nr_cores, GFP_KERNEL);
if (!pdata->core_data)
return NULL;
}
- tdata = kzalloc(sizeof(struct temp_data), GFP_KERNEL);
+ tdata = kzalloc_obj(struct temp_data, GFP_KERNEL);
if (!tdata)
return NULL;
@@ -625,7 +625,7 @@ static int coretemp_device_add(int zoneid)
int err;
/* Initialize the per-zone data structures */
- pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+ pdata = kzalloc_obj(*pdata, GFP_KERNEL);
if (!pdata)
return -ENOMEM;
@@ -804,8 +804,8 @@ static int __init coretemp_init(void)
return -ENODEV;
max_zones = topology_max_packages() * topology_max_dies_per_package();
- zone_devices = kcalloc(max_zones, sizeof(struct platform_device *),
- GFP_KERNEL);
+ zone_devices = kzalloc_objs(struct platform_device *, max_zones,
+ GFP_KERNEL);
if (!zone_devices)
return -ENOMEM;
diff --git a/drivers/hwmon/drivetemp.c b/drivers/hwmon/drivetemp.c
index 9c5b021aab86..f2fa7223be7a 100644
--- a/drivers/hwmon/drivetemp.c
+++ b/drivers/hwmon/drivetemp.c
@@ -556,7 +556,7 @@ static int drivetemp_add(struct device *dev)
struct drivetemp_data *st;
int err;
- st = kzalloc(sizeof(*st), GFP_KERNEL);
+ st = kzalloc_obj(*st, GFP_KERNEL);
if (!st)
return -ENOMEM;
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c
index a303959879ef..740d46634b4c 100644
--- a/drivers/hwmon/fschmd.c
+++ b/drivers/hwmon/fschmd.c
@@ -1088,7 +1088,7 @@ static int fschmd_probe(struct i2c_client *client)
int i, err;
enum chips kind = (uintptr_t)i2c_get_match_data(client);
- data = kzalloc(sizeof(struct fschmd_data), GFP_KERNEL);
+ data = kzalloc_obj(struct fschmd_data, GFP_KERNEL);
if (!data)
return -ENOMEM;
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 714caa6a36a3..a1173ea0b029 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -533,7 +533,7 @@ static struct attribute *hwmon_genattr(const void *drvdata,
if ((mode & 0222) && !ops->write)
return ERR_PTR(-EINVAL);
- hattr = kzalloc(sizeof(*hattr), GFP_KERNEL);
+ hattr = kzalloc_obj(*hattr, GFP_KERNEL);
if (!hattr)
return ERR_PTR(-ENOMEM);
@@ -879,7 +879,7 @@ __hwmon_create_attrs(const void *drvdata, const struct hwmon_chip_info *chip)
if (nattrs == 0)
return ERR_PTR(-EINVAL);
- attrs = kcalloc(nattrs + 1, sizeof(*attrs), GFP_KERNEL);
+ attrs = kzalloc_objs(*attrs, nattrs + 1, GFP_KERNEL);
if (!attrs)
return ERR_PTR(-ENOMEM);
@@ -917,7 +917,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
if (id < 0)
return ERR_PTR(id);
- hwdev = kzalloc(sizeof(*hwdev), GFP_KERNEL);
+ hwdev = kzalloc_obj(*hwdev, GFP_KERNEL);
if (hwdev == NULL) {
err = -ENOMEM;
goto ida_remove;
@@ -933,7 +933,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
for (i = 0; groups[i]; i++)
ngroups++;
- hwdev->groups = kcalloc(ngroups, sizeof(*groups), GFP_KERNEL);
+ hwdev->groups = kzalloc_objs(*groups, ngroups, GFP_KERNEL);
if (!hwdev->groups) {
err = -ENOMEM;
goto free_hwmon;
diff --git a/drivers/hwmon/i5k_amb.c b/drivers/hwmon/i5k_amb.c
index b22e0423e324..f3835606179c 100644
--- a/drivers/hwmon/i5k_amb.c
+++ b/drivers/hwmon/i5k_amb.c
@@ -494,7 +494,7 @@ static int i5k_amb_probe(struct platform_device *pdev)
struct resource *reso;
int i, res;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return -ENOMEM;
diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
index daed437d34a4..e62e7bab0865 100644
--- a/drivers/hwmon/ibmaem.c
+++ b/drivers/hwmon/ibmaem.c
@@ -517,7 +517,7 @@ static int aem_init_aem1_inst(struct aem_ipmi_data *probe, u8 module_handle)
int i;
int res = -ENOMEM;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return res;
mutex_init(&data->lock);
@@ -657,7 +657,7 @@ static int aem_init_aem2_inst(struct aem_ipmi_data *probe,
int i;
int res = -ENOMEM;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return res;
mutex_init(&data->lock);
diff --git a/drivers/hwmon/ibmpex.c b/drivers/hwmon/ibmpex.c
index 228c5f6c6f38..331aa8159ab8 100644
--- a/drivers/hwmon/ibmpex.c
+++ b/drivers/hwmon/ibmpex.c
@@ -367,8 +367,8 @@ static int ibmpex_find_sensors(struct ibmpex_bmc_data *data)
return -ENOENT;
data->num_sensors = err;
- data->sensors = kcalloc(data->num_sensors, sizeof(*data->sensors),
- GFP_KERNEL);
+ data->sensors = kzalloc_objs(*data->sensors, data->num_sensors,
+ GFP_KERNEL);
if (!data->sensors)
return -ENOMEM;
@@ -438,7 +438,7 @@ static void ibmpex_register_bmc(int iface, struct device *dev)
struct ibmpex_bmc_data *data;
int err;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return;
diff --git a/drivers/hwmon/sch56xx-common.c b/drivers/hwmon/sch56xx-common.c
index 98e075e54e9d..1b0442fe2bf3 100644
--- a/drivers/hwmon/sch56xx-common.c
+++ b/drivers/hwmon/sch56xx-common.c
@@ -330,7 +330,7 @@ struct regmap *devm_regmap_init_sch56xx(struct device *dev, struct mutex *lock,
if (config->reg_bits != 16 && config->val_bits != 8)
return ERR_PTR(-EOPNOTSUPP);
- context = kzalloc(sizeof(*context), GFP_KERNEL);
+ context = kzalloc_obj(*context, GFP_KERNEL);
if (!context)
return ERR_PTR(-ENOMEM);
diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
index 823bff2871e1..72a4f514a78c 100644
--- a/drivers/hwmon/via-cputemp.c
+++ b/drivers/hwmon/via-cputemp.c
@@ -222,7 +222,7 @@ static int via_cputemp_online(unsigned int cpu)
goto exit;
}
- pdev_entry = kzalloc(sizeof(struct pdev_entry), GFP_KERNEL);
+ pdev_entry = kzalloc_obj(struct pdev_entry, GFP_KERNEL);
if (!pdev_entry) {
err = -ENOMEM;
goto exit_device_put;
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index 67728f60333f..8081ef3b1592 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -1650,7 +1650,7 @@ static int w83793_probe(struct i2c_client *client)
int files_pwm = ARRAY_SIZE(w83793_left_pwm) / 5;
int files_temp = ARRAY_SIZE(w83793_temp) / 6;
- data = kzalloc(sizeof(struct w83793_data), GFP_KERNEL);
+ data = kzalloc_obj(struct w83793_data, GFP_KERNEL);
if (!data) {
err = -ENOMEM;
goto exit;