mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
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>
This commit is contained in:
@@ -674,7 +674,7 @@ static int adb_open(struct inode *inode, struct file *file)
|
||||
ret = -ENXIO;
|
||||
goto out;
|
||||
}
|
||||
state = kmalloc(sizeof(struct adbdev_state), GFP_KERNEL);
|
||||
state = kmalloc_obj(struct adbdev_state, GFP_KERNEL);
|
||||
if (!state) {
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
@@ -783,8 +783,7 @@ static ssize_t adb_write(struct file *file, const char __user *buf,
|
||||
if (adb_controller == NULL)
|
||||
return -ENXIO;
|
||||
|
||||
req = kmalloc(sizeof(struct adb_request),
|
||||
GFP_KERNEL);
|
||||
req = kmalloc_obj(struct adb_request, GFP_KERNEL);
|
||||
if (req == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
@@ -764,7 +764,7 @@ adbhid_input_register(int id, int default_id, int original_handler_id,
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
adbhid[id] = hid = kzalloc(sizeof(struct adbhid), GFP_KERNEL);
|
||||
adbhid[id] = hid = kzalloc_obj(struct adbhid, GFP_KERNEL);
|
||||
input_dev = input_allocate_device();
|
||||
if (!hid || !input_dev) {
|
||||
err = -ENOMEM;
|
||||
|
||||
@@ -102,7 +102,7 @@ static int mac_hid_emumouse_connect(struct input_handler *handler,
|
||||
if (dev == mac_hid_emumouse_dev)
|
||||
return -ENODEV;
|
||||
|
||||
handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
|
||||
handle = kzalloc_obj(struct input_handle, GFP_KERNEL);
|
||||
if (!handle)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
@@ -368,7 +368,7 @@ static struct macio_dev * macio_add_one_device(struct macio_chip *chip,
|
||||
if (np == NULL)
|
||||
return NULL;
|
||||
|
||||
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
|
||||
dev = kzalloc_obj(*dev, GFP_KERNEL);
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
|
||||
@@ -396,7 +396,7 @@ static int rackmeter_probe(struct macio_dev* mdev,
|
||||
}
|
||||
|
||||
/* Create and initialize our instance data */
|
||||
rm = kzalloc(sizeof(*rm), GFP_KERNEL);
|
||||
rm = kzalloc_obj(*rm, GFP_KERNEL);
|
||||
if (rm == NULL) {
|
||||
printk(KERN_ERR "rackmeter: failed to allocate memory !\n");
|
||||
rc = -ENOMEM;
|
||||
|
||||
@@ -1081,7 +1081,7 @@ static int smu_open(struct inode *inode, struct file *file)
|
||||
struct smu_private *pp;
|
||||
unsigned long flags;
|
||||
|
||||
pp = kzalloc(sizeof(struct smu_private), GFP_KERNEL);
|
||||
pp = kzalloc_obj(struct smu_private, GFP_KERNEL);
|
||||
if (!pp)
|
||||
return -ENOMEM;
|
||||
spin_lock_init(&pp->lock);
|
||||
|
||||
@@ -498,7 +498,7 @@ static int probe_thermostat(struct i2c_client *client)
|
||||
}
|
||||
}
|
||||
|
||||
th = kzalloc(sizeof(struct thermostat), GFP_KERNEL);
|
||||
th = kzalloc_obj(struct thermostat, GFP_KERNEL);
|
||||
if (!th)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
@@ -2147,7 +2147,7 @@ pmu_open(struct inode *inode, struct file *file)
|
||||
struct pmu_private *pp;
|
||||
unsigned long flags;
|
||||
|
||||
pp = kmalloc(sizeof(struct pmu_private), GFP_KERNEL);
|
||||
pp = kmalloc_obj(struct pmu_private, GFP_KERNEL);
|
||||
if (!pp)
|
||||
return -ENOMEM;
|
||||
pp->rb_get = pp->rb_put = 0;
|
||||
|
||||
@@ -260,7 +260,7 @@ static int wf_ad7417_probe(struct i2c_client *client)
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
pv = kzalloc(sizeof(struct wf_ad7417_priv), GFP_KERNEL);
|
||||
pv = kzalloc_obj(struct wf_ad7417_priv, GFP_KERNEL);
|
||||
if (pv == NULL)
|
||||
return -ENODEV;
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ static int __init wf_cpufreq_clamp_init(void)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
clamp = kmalloc(sizeof(struct wf_control), GFP_KERNEL);
|
||||
clamp = kmalloc_obj(struct wf_control, GFP_KERNEL);
|
||||
if (clamp == NULL) {
|
||||
ret = -ENOMEM;
|
||||
goto fail;
|
||||
|
||||
@@ -363,7 +363,7 @@ static void wf_fcu_add_fan(struct wf_fcu_priv *pv, const char *name,
|
||||
{
|
||||
struct wf_fcu_fan *fan;
|
||||
|
||||
fan = kzalloc(sizeof(*fan), GFP_KERNEL);
|
||||
fan = kzalloc_obj(*fan, GFP_KERNEL);
|
||||
if (!fan)
|
||||
return;
|
||||
fan->fcu_priv = pv;
|
||||
@@ -518,7 +518,7 @@ static int wf_fcu_probe(struct i2c_client *client)
|
||||
{
|
||||
struct wf_fcu_priv *pv;
|
||||
|
||||
pv = kzalloc(sizeof(*pv), GFP_KERNEL);
|
||||
pv = kzalloc_obj(*pv, GFP_KERNEL);
|
||||
if (!pv)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ static int wf_lm75_probe(struct i2c_client *client)
|
||||
return -ENXIO;
|
||||
|
||||
|
||||
lm = kzalloc(sizeof(struct wf_lm75_sensor), GFP_KERNEL);
|
||||
lm = kzalloc_obj(struct wf_lm75_sensor, GFP_KERNEL);
|
||||
if (lm == NULL)
|
||||
return -ENODEV;
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ static int wf_lm87_probe(struct i2c_client *client)
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
lm = kzalloc(sizeof(struct wf_lm87_sensor), GFP_KERNEL);
|
||||
lm = kzalloc_obj(struct wf_lm87_sensor, GFP_KERNEL);
|
||||
if (lm == NULL)
|
||||
return -ENODEV;
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ static int wf_max6690_probe(struct i2c_client *client)
|
||||
else
|
||||
return -ENXIO;
|
||||
|
||||
max = kzalloc(sizeof(struct wf_6690_sensor), GFP_KERNEL);
|
||||
max = kzalloc_obj(struct wf_6690_sensor, GFP_KERNEL);
|
||||
if (max == NULL) {
|
||||
printk(KERN_ERR "windfarm: Couldn't create MAX6690 sensor: "
|
||||
"no memory\n");
|
||||
|
||||
@@ -531,8 +531,8 @@ static void pm121_create_sys_fans(int loop_id)
|
||||
control = controls[param->control_id];
|
||||
|
||||
/* Alloc & initialize state */
|
||||
pm121_sys_state[loop_id] = kmalloc(sizeof(struct pm121_sys_state),
|
||||
GFP_KERNEL);
|
||||
pm121_sys_state[loop_id] = kmalloc_obj(struct pm121_sys_state,
|
||||
GFP_KERNEL);
|
||||
if (pm121_sys_state[loop_id] == NULL) {
|
||||
printk(KERN_WARNING "pm121: Memory allocation error\n");
|
||||
goto fail;
|
||||
@@ -668,8 +668,7 @@ static void pm121_create_cpu_fans(void)
|
||||
tmax = 0x5e0000; /* 94 degree default */
|
||||
|
||||
/* Alloc & initialize state */
|
||||
pm121_cpu_state = kmalloc(sizeof(struct pm121_cpu_state),
|
||||
GFP_KERNEL);
|
||||
pm121_cpu_state = kmalloc_obj(struct pm121_cpu_state, GFP_KERNEL);
|
||||
if (pm121_cpu_state == NULL)
|
||||
goto fail;
|
||||
pm121_cpu_state->ticks = 1;
|
||||
|
||||
@@ -283,8 +283,7 @@ static void wf_smu_create_sys_fans(void)
|
||||
}
|
||||
|
||||
/* Alloc & initialize state */
|
||||
wf_smu_sys_fans = kmalloc(sizeof(struct wf_smu_sys_fans_state),
|
||||
GFP_KERNEL);
|
||||
wf_smu_sys_fans = kmalloc_obj(struct wf_smu_sys_fans_state, GFP_KERNEL);
|
||||
if (wf_smu_sys_fans == NULL) {
|
||||
printk(KERN_WARNING "windfarm: Memory allocation error"
|
||||
" max fan speed\n");
|
||||
@@ -419,8 +418,7 @@ static void wf_smu_create_cpu_fans(void)
|
||||
tmax = 0x5e0000; /* 94 degree default */
|
||||
|
||||
/* Alloc & initialize state */
|
||||
wf_smu_cpu_fans = kmalloc(sizeof(struct wf_smu_cpu_fans_state),
|
||||
GFP_KERNEL);
|
||||
wf_smu_cpu_fans = kmalloc_obj(struct wf_smu_cpu_fans_state, GFP_KERNEL);
|
||||
if (wf_smu_cpu_fans == NULL)
|
||||
goto fail;
|
||||
wf_smu_cpu_fans->ticks = 1;
|
||||
|
||||
@@ -168,8 +168,7 @@ static void wf_smu_create_cpu_fans(void)
|
||||
tmax = 0x5e0000; /* 94 degree default */
|
||||
|
||||
/* Alloc & initialize state */
|
||||
wf_smu_cpu_fans = kmalloc(sizeof(struct wf_smu_cpu_fans_state),
|
||||
GFP_KERNEL);
|
||||
wf_smu_cpu_fans = kmalloc_obj(struct wf_smu_cpu_fans_state, GFP_KERNEL);
|
||||
if (wf_smu_cpu_fans == NULL)
|
||||
goto fail;
|
||||
wf_smu_cpu_fans->ticks = 1;
|
||||
@@ -300,8 +299,8 @@ static void wf_smu_create_drive_fans(void)
|
||||
};
|
||||
|
||||
/* Alloc & initialize state */
|
||||
wf_smu_drive_fans = kmalloc(sizeof(struct wf_smu_drive_fans_state),
|
||||
GFP_KERNEL);
|
||||
wf_smu_drive_fans = kmalloc_obj(struct wf_smu_drive_fans_state,
|
||||
GFP_KERNEL);
|
||||
if (wf_smu_drive_fans == NULL) {
|
||||
printk(KERN_WARNING "windfarm: Memory allocation error"
|
||||
" max fan speed\n");
|
||||
@@ -381,8 +380,8 @@ static void wf_smu_create_slots_fans(void)
|
||||
};
|
||||
|
||||
/* Alloc & initialize state */
|
||||
wf_smu_slots_fans = kmalloc(sizeof(struct wf_smu_slots_fans_state),
|
||||
GFP_KERNEL);
|
||||
wf_smu_slots_fans = kmalloc_obj(struct wf_smu_slots_fans_state,
|
||||
GFP_KERNEL);
|
||||
if (wf_smu_slots_fans == NULL) {
|
||||
printk(KERN_WARNING "windfarm: Memory allocation error"
|
||||
" max fan speed\n");
|
||||
|
||||
@@ -162,7 +162,7 @@ static struct smu_fan_control *smu_fan_create(struct device_node *node,
|
||||
const u32 *reg;
|
||||
const char *l;
|
||||
|
||||
fct = kmalloc(sizeof(struct smu_fan_control), GFP_KERNEL);
|
||||
fct = kmalloc_obj(struct smu_fan_control, GFP_KERNEL);
|
||||
if (fct == NULL)
|
||||
return NULL;
|
||||
fct->ctrl.ops = &smu_fan_ops;
|
||||
|
||||
@@ -203,7 +203,7 @@ static int wf_sat_probe(struct i2c_client *client)
|
||||
char *name;
|
||||
int vsens[2], isens[2];
|
||||
|
||||
sat = kzalloc(sizeof(struct wf_sat), GFP_KERNEL);
|
||||
sat = kzalloc_obj(struct wf_sat, GFP_KERNEL);
|
||||
if (sat == NULL)
|
||||
return -ENOMEM;
|
||||
sat->nr = -1;
|
||||
|
||||
@@ -200,7 +200,7 @@ static struct smu_ad_sensor *smu_ads_create(struct device_node *node)
|
||||
const char *l;
|
||||
const u32 *v;
|
||||
|
||||
ads = kmalloc(sizeof(struct smu_ad_sensor), GFP_KERNEL);
|
||||
ads = kmalloc_obj(struct smu_ad_sensor, GFP_KERNEL);
|
||||
if (ads == NULL)
|
||||
return NULL;
|
||||
l = of_get_property(node, "location", NULL);
|
||||
@@ -338,7 +338,7 @@ smu_cpu_power_create(struct wf_sensor *volts, struct wf_sensor *amps)
|
||||
{
|
||||
struct smu_cpu_power_sensor *pow;
|
||||
|
||||
pow = kmalloc(sizeof(struct smu_cpu_power_sensor), GFP_KERNEL);
|
||||
pow = kmalloc_obj(struct smu_cpu_power_sensor, GFP_KERNEL);
|
||||
if (pow == NULL)
|
||||
return NULL;
|
||||
pow->sens.ops = &smu_cpu_power_ops;
|
||||
|
||||
Reference in New Issue
Block a user