mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 01:32:21 +02:00
clk: clk-max77686: kzalloc + kcalloc to kzalloc
Simplify allocation by using a flexible array member to combine allocations. Use struct_size to calculate size properly. Use __counted_by to get extra runtime analysis. Assign counting variable right after allocation as required by __counted_by. Signed-off-by: Rosen Penev <rosenp@gmail.com> Reviewed-by: Brian Masney <bmasney@redhat.com> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
This commit is contained in:
parent
4758f1354f
commit
4266035a40
|
|
@ -47,8 +47,8 @@ struct max77686_clk_init_data {
|
|||
|
||||
struct max77686_clk_driver_data {
|
||||
enum max77686_chip_name chip;
|
||||
struct max77686_clk_init_data *max_clk_data;
|
||||
size_t num_clks;
|
||||
struct max77686_clk_init_data max_clk_data[] __counted_by(num_clks);
|
||||
};
|
||||
|
||||
static const struct
|
||||
|
|
@ -168,19 +168,7 @@ static int max77686_clk_probe(struct platform_device *pdev)
|
|||
struct regmap *regmap;
|
||||
int i, ret, num_clks;
|
||||
|
||||
drv_data = devm_kzalloc(dev, sizeof(*drv_data), GFP_KERNEL);
|
||||
if (!drv_data)
|
||||
return -ENOMEM;
|
||||
|
||||
regmap = dev_get_regmap(parent, NULL);
|
||||
if (!regmap) {
|
||||
dev_err(dev, "Failed to get rtc regmap\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
drv_data->chip = id->driver_data;
|
||||
|
||||
switch (drv_data->chip) {
|
||||
switch (id->driver_data) {
|
||||
case CHIP_MAX77686:
|
||||
num_clks = MAX77686_CLKS_NUM;
|
||||
hw_clks = max77686_hw_clks_info;
|
||||
|
|
@ -201,13 +189,19 @@ static int max77686_clk_probe(struct platform_device *pdev)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
drv_data->num_clks = num_clks;
|
||||
drv_data->max_clk_data = devm_kcalloc(dev, num_clks,
|
||||
sizeof(*drv_data->max_clk_data),
|
||||
GFP_KERNEL);
|
||||
if (!drv_data->max_clk_data)
|
||||
drv_data = devm_kzalloc(dev, struct_size(drv_data, max_clk_data, num_clks), GFP_KERNEL);
|
||||
if (!drv_data)
|
||||
return -ENOMEM;
|
||||
|
||||
drv_data->num_clks = num_clks;
|
||||
drv_data->chip = id->driver_data;
|
||||
|
||||
regmap = dev_get_regmap(parent, NULL);
|
||||
if (!regmap) {
|
||||
dev_err(dev, "Failed to get rtc regmap\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
for (i = 0; i < num_clks; i++) {
|
||||
struct max77686_clk_init_data *max_clk_data;
|
||||
const char *clk_name;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user