mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2025-01-05 21:35:04 +08:00
platform/mellanox: Add null pointer checks for devm_kasprintf()
[ Upstream commit2c7c857f5f
] devm_kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Compile-tested only. Fixes:1a218d312e
("platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver") Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Suggested-by: Vadim Pasternak <vadimp@nvidia.com> Signed-off-by: Kunwu Chan <chentao@kylinos.cn> Reviewed-by: Vadim Pasternak <vadimp@nvidia.com> Link: https://lore.kernel.org/r/20231201055447.2356001-1-chentao@kylinos.cn [ij: split the change into two] Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
45171e5eb7
commit
a24071448e
@ -1202,6 +1202,8 @@ static int mlxbf_pmc_init_perftype_counter(struct device *dev, int blk_num)
|
||||
attr->dev_attr.show = mlxbf_pmc_event_list_show;
|
||||
attr->nr = blk_num;
|
||||
attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, "event_list");
|
||||
if (!attr->dev_attr.attr.name)
|
||||
return -ENOMEM;
|
||||
pmc->block[blk_num].block_attr[i] = &attr->dev_attr.attr;
|
||||
attr = NULL;
|
||||
|
||||
@ -1214,6 +1216,8 @@ static int mlxbf_pmc_init_perftype_counter(struct device *dev, int blk_num)
|
||||
attr->nr = blk_num;
|
||||
attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL,
|
||||
"enable");
|
||||
if (!attr->dev_attr.attr.name)
|
||||
return -ENOMEM;
|
||||
pmc->block[blk_num].block_attr[++i] = &attr->dev_attr.attr;
|
||||
attr = NULL;
|
||||
}
|
||||
@ -1240,6 +1244,8 @@ static int mlxbf_pmc_init_perftype_counter(struct device *dev, int blk_num)
|
||||
attr->nr = blk_num;
|
||||
attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL,
|
||||
"counter%d", j);
|
||||
if (!attr->dev_attr.attr.name)
|
||||
return -ENOMEM;
|
||||
pmc->block[blk_num].block_attr[++i] = &attr->dev_attr.attr;
|
||||
attr = NULL;
|
||||
|
||||
@ -1251,6 +1257,8 @@ static int mlxbf_pmc_init_perftype_counter(struct device *dev, int blk_num)
|
||||
attr->nr = blk_num;
|
||||
attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL,
|
||||
"event%d", j);
|
||||
if (!attr->dev_attr.attr.name)
|
||||
return -ENOMEM;
|
||||
pmc->block[blk_num].block_attr[++i] = &attr->dev_attr.attr;
|
||||
attr = NULL;
|
||||
}
|
||||
@ -1283,6 +1291,8 @@ static int mlxbf_pmc_init_perftype_reg(struct device *dev, int blk_num)
|
||||
attr->nr = blk_num;
|
||||
attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL,
|
||||
events[j].evt_name);
|
||||
if (!attr->dev_attr.attr.name)
|
||||
return -ENOMEM;
|
||||
pmc->block[blk_num].block_attr[i] = &attr->dev_attr.attr;
|
||||
attr = NULL;
|
||||
i++;
|
||||
@ -1311,6 +1321,8 @@ static int mlxbf_pmc_create_groups(struct device *dev, int blk_num)
|
||||
pmc->block[blk_num].block_attr_grp.attrs = pmc->block[blk_num].block_attr;
|
||||
pmc->block[blk_num].block_attr_grp.name = devm_kasprintf(
|
||||
dev, GFP_KERNEL, pmc->block_name[blk_num]);
|
||||
if (!pmc->block[blk_num].block_attr_grp.name)
|
||||
return -ENOMEM;
|
||||
pmc->groups[blk_num] = &pmc->block[blk_num].block_attr_grp;
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user