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:
@@ -3485,7 +3485,7 @@ static int dct_hw_info_get(struct amd64_pvt *pvt)
|
||||
|
||||
static int umc_hw_info_get(struct amd64_pvt *pvt)
|
||||
{
|
||||
pvt->umc = kcalloc(pvt->max_mcs, sizeof(struct amd64_umc), GFP_KERNEL);
|
||||
pvt->umc = kzalloc_objs(struct amd64_umc, pvt->max_mcs, GFP_KERNEL);
|
||||
if (!pvt->umc)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -3716,7 +3716,7 @@ static int gpu_hw_info_get(struct amd64_pvt *pvt)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
pvt->umc = kcalloc(pvt->max_mcs, sizeof(struct amd64_umc), GFP_KERNEL);
|
||||
pvt->umc = kzalloc_objs(struct amd64_umc, pvt->max_mcs, GFP_KERNEL);
|
||||
if (!pvt->umc)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -3916,7 +3916,7 @@ static int per_family_init(struct amd64_pvt *pvt)
|
||||
scnprintf(pvt->ctl_name, sizeof(pvt->ctl_name), "F%02Xh_M%02Xh",
|
||||
pvt->fam, pvt->model);
|
||||
|
||||
pvt->csels = kcalloc(pvt->max_mcs, sizeof(*pvt->csels), GFP_KERNEL);
|
||||
pvt->csels = kzalloc_objs(*pvt->csels, pvt->max_mcs, GFP_KERNEL);
|
||||
if (!pvt->csels)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -4000,13 +4000,13 @@ static int probe_one_instance(unsigned int nid)
|
||||
int ret;
|
||||
|
||||
ret = -ENOMEM;
|
||||
s = kzalloc(sizeof(struct ecc_settings), GFP_KERNEL);
|
||||
s = kzalloc_obj(struct ecc_settings, GFP_KERNEL);
|
||||
if (!s)
|
||||
goto err_out;
|
||||
|
||||
ecc_stngs[nid] = s;
|
||||
|
||||
pvt = kzalloc(sizeof(struct amd64_pvt), GFP_KERNEL);
|
||||
pvt = kzalloc_obj(struct amd64_pvt, GFP_KERNEL);
|
||||
if (!pvt)
|
||||
goto err_settings;
|
||||
|
||||
@@ -4146,7 +4146,7 @@ static int __init amd64_edac_init(void)
|
||||
opstate_init();
|
||||
|
||||
err = -ENOMEM;
|
||||
ecc_stngs = kcalloc(amd_nb_num(), sizeof(ecc_stngs[0]), GFP_KERNEL);
|
||||
ecc_stngs = kzalloc_objs(ecc_stngs[0], amd_nb_num(), GFP_KERNEL);
|
||||
if (!ecc_stngs)
|
||||
goto err_free;
|
||||
|
||||
|
||||
@@ -67,17 +67,19 @@ edac_device_alloc_ctl_info(unsigned pvt_sz, char *dev_name, unsigned nr_instance
|
||||
|
||||
edac_dbg(4, "instances=%d blocks=%d\n", nr_instances, nr_blocks);
|
||||
|
||||
dev_ctl = kzalloc(sizeof(struct edac_device_ctl_info), GFP_KERNEL);
|
||||
dev_ctl = kzalloc_obj(struct edac_device_ctl_info, GFP_KERNEL);
|
||||
if (!dev_ctl)
|
||||
return NULL;
|
||||
|
||||
dev_inst = kcalloc(nr_instances, sizeof(struct edac_device_instance), GFP_KERNEL);
|
||||
dev_inst = kzalloc_objs(struct edac_device_instance, nr_instances,
|
||||
GFP_KERNEL);
|
||||
if (!dev_inst)
|
||||
goto free;
|
||||
|
||||
dev_ctl->instances = dev_inst;
|
||||
|
||||
dev_blk = kcalloc(nr_instances * nr_blocks, sizeof(struct edac_device_block), GFP_KERNEL);
|
||||
dev_blk = kzalloc_objs(struct edac_device_block,
|
||||
nr_instances * nr_blocks, GFP_KERNEL);
|
||||
if (!dev_blk)
|
||||
goto free;
|
||||
|
||||
@@ -642,22 +644,24 @@ int edac_dev_register(struct device *parent, char *name,
|
||||
}
|
||||
}
|
||||
|
||||
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
|
||||
ctx = kzalloc_obj(*ctx, GFP_KERNEL);
|
||||
if (!ctx)
|
||||
return -ENOMEM;
|
||||
|
||||
ras_attr_groups = kcalloc(attr_gcnt + 1, sizeof(*ras_attr_groups), GFP_KERNEL);
|
||||
ras_attr_groups = kzalloc_objs(*ras_attr_groups, attr_gcnt + 1,
|
||||
GFP_KERNEL);
|
||||
if (!ras_attr_groups)
|
||||
goto ctx_free;
|
||||
|
||||
if (scrub_cnt) {
|
||||
ctx->scrub = kcalloc(scrub_cnt, sizeof(*ctx->scrub), GFP_KERNEL);
|
||||
ctx->scrub = kzalloc_objs(*ctx->scrub, scrub_cnt, GFP_KERNEL);
|
||||
if (!ctx->scrub)
|
||||
goto groups_free;
|
||||
}
|
||||
|
||||
if (mem_repair_cnt) {
|
||||
ctx->mem_repair = kcalloc(mem_repair_cnt, sizeof(*ctx->mem_repair), GFP_KERNEL);
|
||||
ctx->mem_repair = kzalloc_objs(*ctx->mem_repair, mem_repair_cnt,
|
||||
GFP_KERNEL);
|
||||
if (!ctx->mem_repair)
|
||||
goto data_mem_free;
|
||||
}
|
||||
|
||||
@@ -216,14 +216,14 @@ static int edac_mc_alloc_csrows(struct mem_ctl_info *mci)
|
||||
/*
|
||||
* Allocate and fill the csrow/channels structs
|
||||
*/
|
||||
mci->csrows = kcalloc(tot_csrows, sizeof(*mci->csrows), GFP_KERNEL);
|
||||
mci->csrows = kzalloc_objs(*mci->csrows, tot_csrows, GFP_KERNEL);
|
||||
if (!mci->csrows)
|
||||
return -ENOMEM;
|
||||
|
||||
for (row = 0; row < tot_csrows; row++) {
|
||||
struct csrow_info *csr;
|
||||
|
||||
csr = kzalloc(sizeof(**mci->csrows), GFP_KERNEL);
|
||||
csr = kzalloc_obj(**mci->csrows, GFP_KERNEL);
|
||||
if (!csr)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -231,15 +231,15 @@ static int edac_mc_alloc_csrows(struct mem_ctl_info *mci)
|
||||
csr->csrow_idx = row;
|
||||
csr->mci = mci;
|
||||
csr->nr_channels = tot_channels;
|
||||
csr->channels = kcalloc(tot_channels, sizeof(*csr->channels),
|
||||
GFP_KERNEL);
|
||||
csr->channels = kzalloc_objs(*csr->channels, tot_channels,
|
||||
GFP_KERNEL);
|
||||
if (!csr->channels)
|
||||
return -ENOMEM;
|
||||
|
||||
for (chn = 0; chn < tot_channels; chn++) {
|
||||
struct rank_info *chan;
|
||||
|
||||
chan = kzalloc(sizeof(**csr->channels), GFP_KERNEL);
|
||||
chan = kzalloc_obj(**csr->channels, GFP_KERNEL);
|
||||
if (!chan)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -262,7 +262,7 @@ static int edac_mc_alloc_dimms(struct mem_ctl_info *mci)
|
||||
/*
|
||||
* Allocate and fill the dimm structs
|
||||
*/
|
||||
mci->dimms = kcalloc(mci->tot_dimms, sizeof(*mci->dimms), GFP_KERNEL);
|
||||
mci->dimms = kzalloc_objs(*mci->dimms, mci->tot_dimms, GFP_KERNEL);
|
||||
if (!mci->dimms)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -276,7 +276,7 @@ static int edac_mc_alloc_dimms(struct mem_ctl_info *mci)
|
||||
|
||||
chan = mci->csrows[row]->channels[chn];
|
||||
|
||||
dimm = kzalloc(sizeof(**mci->dimms), GFP_KERNEL);
|
||||
dimm = kzalloc_obj(**mci->dimms, GFP_KERNEL);
|
||||
if (!dimm)
|
||||
return -ENOMEM;
|
||||
mci->dimms[idx] = dimm;
|
||||
@@ -362,11 +362,11 @@ struct mem_ctl_info *edac_mc_alloc(unsigned int mc_num,
|
||||
per_rank = true;
|
||||
}
|
||||
|
||||
mci = kzalloc(sizeof(struct mem_ctl_info), GFP_KERNEL);
|
||||
mci = kzalloc_obj(struct mem_ctl_info, GFP_KERNEL);
|
||||
if (!mci)
|
||||
return NULL;
|
||||
|
||||
mci->layers = kcalloc(n_layers, sizeof(struct edac_mc_layer), GFP_KERNEL);
|
||||
mci->layers = kzalloc_objs(struct edac_mc_layer, n_layers, GFP_KERNEL);
|
||||
if (!mci->layers)
|
||||
goto error;
|
||||
|
||||
|
||||
@@ -648,7 +648,7 @@ int __init edac_mc_sysfs_init(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
mci_pdev = kzalloc(sizeof(*mci_pdev), GFP_KERNEL);
|
||||
mci_pdev = kzalloc_obj(*mci_pdev, GFP_KERNEL);
|
||||
if (!mci_pdev)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ struct edac_pci_ctl_info *edac_pci_alloc_ctl_info(unsigned int sz_pvt,
|
||||
|
||||
edac_dbg(1, "\n");
|
||||
|
||||
pci = kzalloc(sizeof(struct edac_pci_ctl_info), GFP_KERNEL);
|
||||
pci = kzalloc_obj(struct edac_pci_ctl_info, GFP_KERNEL);
|
||||
if (!pci)
|
||||
return NULL;
|
||||
|
||||
|
||||
@@ -361,7 +361,7 @@ static int edac_pci_main_kobj_setup(void)
|
||||
goto decrement_count_fail;
|
||||
}
|
||||
|
||||
edac_pci_top_main_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL);
|
||||
edac_pci_top_main_kobj = kzalloc_obj(struct kobject, GFP_KERNEL);
|
||||
if (!edac_pci_top_main_kobj) {
|
||||
edac_dbg(1, "Failed to allocate\n");
|
||||
err = -ENOMEM;
|
||||
|
||||
@@ -455,12 +455,12 @@ static struct i7core_dev *alloc_i7core_dev(u8 socket,
|
||||
{
|
||||
struct i7core_dev *i7core_dev;
|
||||
|
||||
i7core_dev = kzalloc(sizeof(*i7core_dev), GFP_KERNEL);
|
||||
i7core_dev = kzalloc_obj(*i7core_dev, GFP_KERNEL);
|
||||
if (!i7core_dev)
|
||||
return NULL;
|
||||
|
||||
i7core_dev->pdev = kcalloc(table->n_devs, sizeof(*i7core_dev->pdev),
|
||||
GFP_KERNEL);
|
||||
i7core_dev->pdev = kzalloc_objs(*i7core_dev->pdev, table->n_devs,
|
||||
GFP_KERNEL);
|
||||
if (!i7core_dev->pdev) {
|
||||
kfree(i7core_dev);
|
||||
return NULL;
|
||||
@@ -1159,7 +1159,7 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)
|
||||
struct i7core_pvt *pvt = mci->pvt_info;
|
||||
int rc;
|
||||
|
||||
pvt->addrmatch_dev = kzalloc(sizeof(*pvt->addrmatch_dev), GFP_KERNEL);
|
||||
pvt->addrmatch_dev = kzalloc_obj(*pvt->addrmatch_dev, GFP_KERNEL);
|
||||
if (!pvt->addrmatch_dev)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -1177,8 +1177,8 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)
|
||||
goto err_put_addrmatch;
|
||||
|
||||
if (!pvt->is_registered) {
|
||||
pvt->chancounts_dev = kzalloc(sizeof(*pvt->chancounts_dev),
|
||||
GFP_KERNEL);
|
||||
pvt->chancounts_dev = kzalloc_obj(*pvt->chancounts_dev,
|
||||
GFP_KERNEL);
|
||||
if (!pvt->chancounts_dev) {
|
||||
rc = -ENOMEM;
|
||||
goto err_del_addrmatch;
|
||||
|
||||
@@ -1549,7 +1549,7 @@ static int igen6_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||
|
||||
edac_dbg(2, "\n");
|
||||
|
||||
igen6_pvt = kzalloc(sizeof(*igen6_pvt), GFP_KERNEL);
|
||||
igen6_pvt = kzalloc_obj(*igen6_pvt, GFP_KERNEL);
|
||||
if (!igen6_pvt)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ static int __get_ddr_munits(struct res_config *cfg, struct skx_dev *d,
|
||||
d->imc[lmc].lmc = lmc;
|
||||
|
||||
/* Create the imc device instance. */
|
||||
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
|
||||
dev = kzalloc_obj(*dev, GFP_KERNEL);
|
||||
if (!dev)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -257,7 +257,7 @@ static int imh_get_all_mmio_base_h(struct res_config *cfg, struct list_head *eda
|
||||
struct skx_dev *d;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
d = kzalloc(struct_size(d, imc, imc_num), GFP_KERNEL);
|
||||
d = kzalloc_flex(*d, imc, imc_num, GFP_KERNEL);
|
||||
if (!d)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
@@ -771,13 +771,12 @@ static struct sbridge_dev *alloc_sbridge_dev(int seg, u8 bus, enum domain dom,
|
||||
{
|
||||
struct sbridge_dev *sbridge_dev;
|
||||
|
||||
sbridge_dev = kzalloc(sizeof(*sbridge_dev), GFP_KERNEL);
|
||||
sbridge_dev = kzalloc_obj(*sbridge_dev, GFP_KERNEL);
|
||||
if (!sbridge_dev)
|
||||
return NULL;
|
||||
|
||||
sbridge_dev->pdev = kcalloc(table->n_devs_per_imc,
|
||||
sizeof(*sbridge_dev->pdev),
|
||||
GFP_KERNEL);
|
||||
sbridge_dev->pdev = kzalloc_objs(*sbridge_dev->pdev,
|
||||
table->n_devs_per_imc, GFP_KERNEL);
|
||||
if (!sbridge_dev->pdev) {
|
||||
kfree(sbridge_dev);
|
||||
return NULL;
|
||||
|
||||
@@ -346,7 +346,7 @@ int skx_get_all_bus_mappings(struct res_config *cfg, struct list_head **list)
|
||||
if (!pdev)
|
||||
break;
|
||||
ndev++;
|
||||
d = kzalloc(struct_size(d, imc, imc_num), GFP_KERNEL);
|
||||
d = kzalloc_flex(*d, imc, imc_num, GFP_KERNEL);
|
||||
if (!d) {
|
||||
pci_dev_put(pdev);
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -559,7 +559,7 @@ static int setup_mcdi(struct mc_priv *mc_priv)
|
||||
struct cdx_mcdi *amd_mcdi;
|
||||
int ret, i;
|
||||
|
||||
amd_mcdi = kzalloc(sizeof(*amd_mcdi), GFP_KERNEL);
|
||||
amd_mcdi = kzalloc_obj(*amd_mcdi, GFP_KERNEL);
|
||||
if (!amd_mcdi)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -812,7 +812,7 @@ static int init_versalnet(struct mc_priv *priv, struct platform_device *pdev)
|
||||
priv->mci[i] = mci;
|
||||
priv->dwidth = dt;
|
||||
|
||||
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
|
||||
dev = kzalloc_obj(*dev, GFP_KERNEL);
|
||||
dev->release = versal_edac_release;
|
||||
name = kmalloc(32, GFP_KERNEL);
|
||||
sprintf(name, "versal-net-ddrmc5-edac-%d", i);
|
||||
|
||||
Reference in New Issue
Block a user