EDAC/device: simplify allocation
cover EDAC/device: simplify allocation
Use a single allocation to remove a bunch of kfree calls.
Rosen Penev (2):
EDAC/device: simplify info allocation EDAC/device: 3 to 1 allocations in edac_dev_feat_ctx
drivers/edac/edac_device.c | 63 +++++++++++++------------------------- drivers/edac/edac_device.h | 4 +-- include/linux/edac.h | 2 +- 3 files changed, 24 insertions(+), 45 deletions(-)
--
2.54.0
PATCH 1/2 EDAC/device: simplify info allocation
Use a flexible array member to combine info and instance allocations. Simplifies allocation slightly.
Add __counted_by for extra runtime analysis. Move counting variable assignment to after allocation as kzalloc_flex already does with GCC >= 15.
--- drivers/edac/edac_device.c | 23 ++++++++--------------- drivers/edac/edac_device.h | 4 +--- 2 files changed, 9 insertions(+), 18 deletions(-)
drivers/edac/edac_device.c +8 -15
@@ -58,31 +58,25 @@ edac_device_alloc_ctl_info(unsigned pvt_sz, char *dev_name, unsigned nr_instance char *blk_name, unsigned nr_blocks, unsigned off_val, int device_index) { - struct edac_device_block *dev_blk, *blk_p, *blk; + struct edac_device_block *blk_p, *blk;struct edac_device_instance *dev_inst, *inst;struct edac_device_ctl_info *dev_ctl;unsigned instance, block; +size_t alloc_size;void *pvt;int err;edac_dbg (4 ,"instances=%d blocks=%d\n" , nr_instances, nr_blocks); - dev_ctl = kzalloc_obj(struct edac_device_ctl_info); + alloc_size =struct_size (dev_ctl, instances, nr_instances); + alloc_size +=sizeof (*dev_ctl->blocks) * nr_instances * nr_blocks; + dev_ctl =kzalloc (alloc_size,GFP_KERNEL );if (!dev_ctl)return NULL ; - dev_inst = kzalloc_objs(struct edac_device_instance, nr_instances); -if (!dev_inst) - goto free; - - dev_ctl->instances = dev_inst; - - dev_blk = kzalloc_objs(struct edac_device_block, - nr_instances * nr_blocks); -if (!dev_blk) - goto free; + dev_ctl->nr_instances = nr_instances; - dev_ctl->blocks = dev_blk; + dev_ctl->blocks = (struct edac_device_block *)(dev_ctl->instances + nr_instances);if (pvt_sz) { pvt =kzalloc (pvt_sz,GFP_KERNEL );
@@ -93,7 +87,6 @@ edac_device_alloc_ctl_info(unsigned pvt_sz, char *dev_name, unsigned nr_instance } dev_ctl->dev_idx = device_index; - dev_ctl->nr_instances = nr_instances;/* Default logging of CEs and UEs */ dev_ctl->log_ce =1 ;
@@ -107,7 +100,7 @@ edac_device_alloc_ctl_info(unsigned pvt_sz, char *dev_name, unsigned nr_instance inst = &dev_inst[instance]; inst->ctl = dev_ctl; inst->nr_blocks = nr_blocks; - blk_p = &dev_blk[instance * nr_blocks]; + blk_p = &dev_ctl->blocks[instance * nr_blocks]; inst->blocks = blk_p;/* name of this instance */
drivers/edac/edac_device.h +1 -3
@@ -203,7 +203,6 @@ struct edac_device_ctl_info {* and the array of those instances */ u32 nr_instances; -struct edac_device_instance *instances;struct edac_device_block *blocks;/* Event counters for the this whole EDAC Device */
@@ -213,6 +212,7 @@ struct edac_device_ctl_info {* device this structure controls */ struct kobject kobj; + struct edac_device_instance instances[] __counted_by(nr_instances); };/* To get from the instance's wq to the beginning of the ctl structure */
@@ -341,8 +341,6 @@ static inline void __edac_device_free_ctl_info(struct edac_device_ctl_info *ci) {if (ci) {kfree (ci->pvt_info); -kfree (ci->blocks); -kfree (ci->instances);kfree (ci); } }
Signature · 1 line
2.54.0
RE: [PATCH 1/2] EDAC/device: simplify info allocation
Quoted 10 lines
From: Rosen Penev <[email protected]>
Sent: Friday, May 1, 2026 6:01 AM
To: [email protected]
Cc: Borislav Petkov <[email protected]>; Luck, Tony <[email protected]>; Kees Cook <[email protected]>; Gustavo A. R. Silva <[email protected]>; open list <[email protected]>; open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b <linux- [email protected]>
Subject: [PATCH 1/2] EDAC/device: simplify info allocation
Quoted 5 lines
Use a flexible array member to combine info and instance allocations. Simplifies allocation slightly.
Add
__counted_byfor extra runtime analysis. Move counting variable assignment to after allocation askzalloc_flexalready does with GCC >= 15.
I'm confused - I don't see kzalloc_flex()used in this patch.
Quoted 41 lines
Signed-off-by Rosen Penev <[email protected]>--- drivers/edac/edac_device.c | 23 ++++++++--------------- drivers/edac/edac_device.h | 4 +--- 2 files changed, 9 insertions(+), 18 deletions(-)drivers/edac/edac_device.c index renamed from drivers/edac/edac_device.c +0
-0
cf0d3c2dfc04..9c21997a50e0100644drivers/edac/edac_device.c +5
-7@@ -58,31 +58,25 @@ edac_device_alloc_ctl_info(unsigned pvt_sz, char *dev_name, unsigned nr_instance char *blk_name, unsigned nr_blocks, unsigned off_val, int device_index) { -struct edac_device_block *dev_blk, *blk_p, *blk; +struct edac_device_block *blk_p, *blk;struct edac_device_instance *dev_inst, *inst;struct edac_device_ctl_info *dev_ctl;unsigned instance, block; +size_t alloc_size;void *pvt;int err;edac_dbg (4 ,"instances=%d blocks=%d\n" , nr_instances, nr_blocks); - dev_ctl = kzalloc_obj(struct edac_device_ctl_info); + alloc_size =struct_size (dev_ctl, instances, nr_instances); + alloc_size +=sizeof (*dev_ctl->blocks) * nr_instances * nr_blocks; + dev_ctl =kzalloc (alloc_size,GFP_KERNEL );if (!dev_ctl)return NULL ; - dev_inst = kzalloc_objs(struct edac_device_instance, nr_instances); -if (!dev_inst) - goto free; - - dev_ctl->instances = dev_inst;
drivers/edac/edac_device.c edac_device_alloc_ctl_info(unsigned pvt_sz, char · line 82
Quoted 10 lines
drivers/edac/edac_device.c +3
-6- - dev_blk = kzalloc_objs(struct edac_device_block, - nr_instances * nr_blocks); -if (!dev_blk) - goto free; + dev_ctl->nr_instances = nr_instances; - dev_ctl->blocks = dev_blk; + dev_ctl->blocks = (struct edac_device_block *)(dev_ctl->instances + +nr_instances);
1. This assumes that the address
'dev_ctl->instances +nr_instances' is properly aligned for struct edac_device_block, but that is not guaranteed.
2. Using a flexible array member for a single structure member can be reasonable and easy to read. But this patch effectively turns two members into flexible arrays and requires manual address calculation for one of them (and there is alignment risk). This makes code less readable to me.
I'd prefer old code, as it's easier to follow ownership and no pointer alignment risk.
Quoted 12 lines
drivers/edac/edac_device.c +0
-1if (pvt_sz) { pvt =kzalloc (pvt_sz,GFP_KERNEL );@@ -93,7 +87,6 @@ edac_device_alloc_ctl_info(unsigned pvt_sz, char *dev_name, unsigned nr_instance } dev_ctl->dev_idx = device_index; - dev_ctl->nr_instances = nr_instances;/* Default logging of CEs and UEs */ drivers/edac/edac_device.c +0
-0dev_ctl->log_ce =1 ;
drivers/edac/edac_device.c edac_device_alloc_ctl_info(unsigned pvt_sz, char · line 101
Quoted 2 lines
drivers/edac/edac_device.c +0
-0@@ -107,7 +100,7 @@ edac_device_alloc_ctl_info(unsigned pvt_sz, char *dev_name, unsigned nr_instance inst = &dev_inst[instance];
BUG: 'dev_inst' is used w/o initialization.
[...]
PATCH 2/2 EDAC/device: 3 to 1 allocations in edac_dev_feat_ctx
In reply to Rosen PenevSimplifies memory handling slightly by using a flexible array member.
--- drivers/edac/edac_device.c | 40 +++++++++++++------------------------- include/linux/edac.h | 2 +- 2 files changed, 15 insertions(+), 27 deletions(-)
drivers/edac/edac_device.c +14 -26
@@ -569,8 +569,6 @@ static void edac_dev_release(struct device *dev) { struct edac_dev_feat_ctx *ctx = container_of(dev, struct edac_dev_feat_ctx, dev); -kfree (ctx->mem_repair); -kfree (ctx->scrub);kfree (ctx->dev.groups);kfree (ctx); }
@@ -612,6 +610,7 @@ int edac_dev_register(struct device *parent, char *name,int attr_gcnt =0 ;int ret = -ENOMEM ;int scrub_cnt =0 ; +size_t alloc_size;int feat;if (!parent || !name || !num_features || !ras_features)
@@ -636,26 +635,18 @@ int edac_dev_register(struct device *parent, char *name, } } - ctx =kzalloc_obj (*ctx); + alloc_size =struct_size (ctx, scrub, scrub_cnt); + alloc_size +=sizeof (*ctx->mem_repair) * mem_repair_cnt; + ctx =kzalloc (alloc_size,GFP_KERNEL );if (!ctx)return -ENOMEM ; + ctx->mem_repair = ctx->scrub + scrub_cnt; + ras_attr_groups =kzalloc_objs (*ras_attr_groups, attr_gcnt +1 );if (!ras_attr_groups) goto ctx_free; -if (scrub_cnt) { - ctx->scrub =kzalloc_objs (*ctx->scrub, scrub_cnt); -if (!ctx->scrub) - goto groups_free; - } - -if (mem_repair_cnt) { - ctx->mem_repair =kzalloc_objs (*ctx->mem_repair, mem_repair_cnt); -if (!ctx->mem_repair) - goto data_mem_free; - } - attr_gcnt =0 ; scrub_cnt =0 ; mem_repair_cnt =0 ;
@@ -664,7 +655,7 @@ int edac_dev_register(struct device *parent, char *name,case RAS_FEAT_SCRUB :if (!ras_features->scrub_ops || scrub_cnt != ras_features->instance) { ret = -EINVAL ; - goto data_mem_free; + goto groups_free; } dev_data = &ctx->scrub[scrub_cnt];
@@ -674,7 +665,7 @@ int edac_dev_register(struct device *parent, char *name, ret =edac_scrub_get_desc (parent, &ras_attr_groups[attr_gcnt], ras_features->instance);if (ret) - goto data_mem_free; + goto groups_free; scrub_cnt++; attr_gcnt++;
@@ -682,7 +673,7 @@ int edac_dev_register(struct device *parent, char *name,case RAS_FEAT_ECS :if (!ras_features->ecs_ops) { ret = -EINVAL ; - goto data_mem_free; + goto groups_free; } dev_data = &ctx->ecs;
@@ -691,7 +682,7 @@ int edac_dev_register(struct device *parent, char *name, ret =edac_ecs_get_desc (parent, &ras_attr_groups[attr_gcnt], ras_features->ecs_info.num_media_frus);if (ret) - goto data_mem_free; + goto groups_free; attr_gcnt += ras_features->ecs_info.num_media_frus;break ;
@@ -699,7 +690,7 @@ int edac_dev_register(struct device *parent, char *name,if (!ras_features->mem_repair_ops || mem_repair_cnt != ras_features->instance) { ret = -EINVAL ; - goto data_mem_free; + goto groups_free; } dev_data = &ctx->mem_repair[mem_repair_cnt];
@@ -709,14 +700,14 @@ int edac_dev_register(struct device *parent, char *name, ret =edac_mem_repair_get_desc (parent, &ras_attr_groups[attr_gcnt], ras_features->instance);if (ret) - goto data_mem_free; + goto groups_free; mem_repair_cnt++; attr_gcnt++;break ;default : ret = -EINVAL ; - goto data_mem_free; + goto groups_free; } }
@@ -729,7 +720,7 @@ int edac_dev_register(struct device *parent, char *name, ret =dev_set_name (&ctx->dev,"%s" , name);if (ret) - goto data_mem_free; + goto groups_free; ret =device_register (&ctx->dev);if (ret) {
@@ -739,9 +730,6 @@ int edac_dev_register(struct device *parent, char *name,return devm_add_action_or_reset (parent, edac_dev_unreg, &ctx->dev); -data_mem_free: -kfree (ctx->mem_repair); -kfree (ctx->scrub); groups_free:kfree (ras_attr_groups); ctx_free:
include/linux/edac.h +1 -1
@@ -864,9 +864,9 @@ struct edac_dev_data {struct edac_dev_feat_ctx {struct device dev;void *private; -struct edac_dev_data *scrub;struct edac_dev_data ecs;struct edac_dev_data *mem_repair; +struct edac_dev_data scrub[]; };struct edac_dev_feature {
Signature · 1 line
2.54.0
RE: [PATCH 2/2] EDAC/device: 3 to 1 allocations in edac_dev_feat_ctx
Quoted 42 lines
From: Rosen Penev <[email protected]>
Sent: Friday, May 1, 2026 6:01 AM
To: [email protected]
Cc: Borislav Petkov <[email protected]>; Luck, Tony <[email protected]>; Kees Cook <[email protected]>; Gustavo A. R. Silva <[email protected]>; open list <[email protected]>; open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b <linux- [email protected]>
Subject: [PATCH 2/2] EDAC/device: 3 to 1 allocations inedac_dev_feat_ctxSimplifies memory handling slightly by using a flexible array member.
Signed-off-by Rosen Penev <[email protected]>--- drivers/edac/edac_device.c | 40 +++++++++++++------------------------- include/linux/edac.h | 2 +- 2 files changed, 15 insertions(+), 27 deletions(-)drivers/edac/edac_device.c index renamed from drivers/edac/edac_device.c +0
-0
9c21997a50e0..a6c41ce68f13100644drivers/edac/edac_device.c +1
-2@@ -569,8 +569,6 @@ static void edac_dev_release(struct device *dev) { struct edac_dev_feat_ctx *ctx = container_of(dev, struct edac_dev_feat_ctx, dev); -kfree (ctx->mem_repair); -kfree (ctx->scrub);kfree (ctx->dev.groups);kfree (ctx); }@@ -612,6 +610,7 @@ int edac_dev_register(struct device *parent, char *name, int attr_gcnt = 0;int ret = -ENOMEM ;int scrub_cnt =0 ; +size_t alloc_size;int feat;drivers/edac/edac_device.c +1
-0if (!parent || !name || !num_features || !ras_features) @@ -636,26 +635,18 @@ int edac_dev_register(struct device *parent, char *name, }
drivers/edac/edac_device.c int edac_dev_register(struct device *parent, char *name, · line 644
Quoted 10 lines
drivers/edac/edac_device.c +4
-1} - ctx =kzalloc_obj (*ctx); + alloc_size =struct_size (ctx, scrub, scrub_cnt); + alloc_size +=sizeof (*ctx->mem_repair) * mem_repair_cnt; + ctx =kzalloc (alloc_size,GFP_KERNEL );if (!ctx)return -ENOMEM ; + ctx->mem_repair = ctx->scrub + scrub_cnt;
The same concerns about pointer alignment risk and code readability as in:
https://lore.kernel.org/all/CY8PR11MB7134BF3800324EFA1B3172AA89322@CY8PR11MB7134.namprd11.prod.outlook.com/
-Qiuxu
kernel test robot
build botRe: [PATCH 2/2] EDAC/device: 3 to 1 allocations in edac_dev_feat_ctx
In reply to Rosen Penevkernel test robot noticed the following build warnings:
Hi Rosen,
kernel test robot noticed the following build warnings:
[auto build test WARNING on ras/edac-for-next]
[also build test WARNING on kees/for-next/pstore kees/for-next/kspp linus/master v7.1-rc3 next-20260508] [cannot apply to bp/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Rosen-Penev/EDAC-device-simplify-info-allocation/20260501-182310 base: https://git.kernel.org/pub/scm/linux/kernel/git/ras/ras.git edac-for-next patch link: https://lore.kernel.org/r/20260430220046.72371-3-rosenp%40gmail.com patch subject: [PATCH 2/2] EDAC/device: 3 to 1 allocations in edac_dev_feat_ctx config: x86_64-rhel-9.4-rust (https://download.01.org/0day-ci/archive/20260512/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) rustc: rustc 1.88.0 (6b00bc388 2025-06-23) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260512/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/edac/edac_device.c:100:11: warning: variable 'dev_inst' is uninitialized when used here [-Wuninitialized]
100 | inst = &dev_inst[instance];
| ^~~~~~~~
drivers/edac/edac_device.c:62:39: note: initialize the variable 'dev_inst' to silence this warning
62 | struct edac_device_instance *dev_inst, *inst;
| ^
| = NULL1 warning generated.
vim +/dev_inst +100 drivers/edac/edac_device.c
e27e3dac651771 Douglas Thompson 2007-07-19 52
0d24a49e88b563 Borislav Petkov 2022-03-08 53 /*
0d24a49e88b563 Borislav Petkov 2022-03-08 54 * @off_val: zero, 1, or other based offset
0d24a49e88b563 Borislav Petkov 2022-03-08 55 */
0d24a49e88b563 Borislav Petkov 2022-03-08 56 struct edac_device_ctl_info *
0d24a49e88b563 Borislav Petkov 2022-03-08 57 edac_device_alloc_ctl_info(unsigned pvt_sz, char *dev_name, unsigned nr_instances,
0d24a49e88b563 Borislav Petkov 2022-03-08 58 char *blk_name, unsigned nr_blocks, unsigned off_val,
48bc8869c5ddb0 Jiri Slaby (SUSE 2024-02-13 59) int device_index)
e27e3dac651771 Douglas Thompson 2007-07-19 60 {
3856ba23b1d621 Rosen Penev 2026-04-30 61 struct edac_device_block *blk_p, *blk;
0d24a49e88b563 Borislav Petkov 2022-03-08 62 struct edac_device_instance *dev_inst, *inst;
0d24a49e88b563 Borislav Petkov 2022-03-08 63 struct edac_device_ctl_info *dev_ctl;
48bc8869c5ddb0 Jiri Slaby (SUSE 2024-02-13 64) unsigned instance, block;
3856ba23b1d621 Rosen Penev 2026-04-30 65 size_t alloc_size;
9fb9ce392aae0c Borislav Petkov 2022-03-08 66 void *pvt;
1c3631ff1f805c Douglas Thompson 2007-07-19 67 int err;
e27e3dac651771 Douglas Thompson 2007-07-19 68
956b9ba156dbfd Joe Perches 2012-04-29 69 edac_dbg(4, "instances=%d blocks=%d\n", nr_instances, nr_blocks);
e27e3dac651771 Douglas Thompson 2007-07-19 70
3856ba23b1d621 Rosen Penev 2026-04-30 71 alloc_size = struct_size(dev_ctl, instances, nr_instances);
3856ba23b1d621 Rosen Penev 2026-04-30 72 alloc_size += sizeof(*dev_ctl->blocks) * nr_instances * nr_blocks;
3856ba23b1d621 Rosen Penev 2026-04-30 73 dev_ctl = kzalloc(alloc_size, GFP_KERNEL);
9fb9ce392aae0c Borislav Petkov 2022-03-08 74 if (!dev_ctl)
9fb9ce392aae0c Borislav Petkov 2022-03-08 75 return NULL;
e27e3dac651771 Douglas Thompson 2007-07-19 76
3856ba23b1d621 Rosen Penev 2026-04-30 77 dev_ctl->nr_instances = nr_instances;
e27e3dac651771 Douglas Thompson 2007-07-19 78
3856ba23b1d621 Rosen Penev 2026-04-30 79 dev_ctl->blocks = (struct edac_device_block *)(dev_ctl->instances + nr_instances);
fd309a9d8e63e9 Douglas Thompson 2007-07-19 80
0d24a49e88b563 Borislav Petkov 2022-03-08 81 if (pvt_sz) {
0d24a49e88b563 Borislav Petkov 2022-03-08 82 pvt = kzalloc(pvt_sz, GFP_KERNEL);
9fb9ce392aae0c Borislav Petkov 2022-03-08 83 if (!pvt)
9fb9ce392aae0c Borislav Petkov 2022-03-08 84 goto free;
9fb9ce392aae0c Borislav Petkov 2022-03-08 85
9fb9ce392aae0c Borislav Petkov 2022-03-08 86 dev_ctl->pvt_info = pvt;
9fb9ce392aae0c Borislav Petkov 2022-03-08 87 }
e27e3dac651771 Douglas Thompson 2007-07-19 88
d45e7823baf655 Doug Thompson 2007-07-19 89 dev_ctl->dev_idx = device_index;
e27e3dac651771 Douglas Thompson 2007-07-19 90
56e61a9c5fe7b7 Doug Thompson 2008-02-07 91 /* Default logging of CEs and UEs */
56e61a9c5fe7b7 Doug Thompson 2008-02-07 92 dev_ctl->log_ce = 1;
56e61a9c5fe7b7 Doug Thompson 2008-02-07 93 dev_ctl->log_ue = 1;
56e61a9c5fe7b7 Doug Thompson 2008-02-07 94
52490c8d07680a Douglas Thompson 2007-07-19 95 /* Name of this edac device */
0d24a49e88b563 Borislav Petkov 2022-03-08 96 snprintf(dev_ctl->name, sizeof(dev_ctl->name),"%s", dev_name);
e27e3dac651771 Douglas Thompson 2007-07-19 97
e27e3dac651771 Douglas Thompson 2007-07-19 98 /* Initialize every Instance */
e27e3dac651771 Douglas Thompson 2007-07-19 99 for (instance = 0; instance < nr_instances; instance++) {
e27e3dac651771 Douglas Thompson 2007-07-19 @100 inst = &dev_inst[instance];
e27e3dac651771 Douglas Thompson 2007-07-19 101 inst->ctl = dev_ctl;
e27e3dac651771 Douglas Thompson 2007-07-19 102 inst->nr_blocks = nr_blocks;
3856ba23b1d621 Rosen Penev 2026-04-30 103 blk_p = &dev_ctl->blocks[instance * nr_blocks];
e27e3dac651771 Douglas Thompson 2007-07-19 104 inst->blocks = blk_p;
e27e3dac651771 Douglas Thompson 2007-07-19 105
e27e3dac651771 Douglas Thompson 2007-07-19 106 /* name of this instance */
0d24a49e88b563 Borislav Petkov 2022-03-08 107 snprintf(inst->name, sizeof(inst->name), "%s%u", dev_name, instance);
e27e3dac651771 Douglas Thompson 2007-07-19 108
e27e3dac651771 Douglas Thompson 2007-07-19 109 /* Initialize every block in each instance */
079708b9173595 Douglas Thompson 2007-07-19 110 for (block = 0; block < nr_blocks; block++) {
e27e3dac651771 Douglas Thompson 2007-07-19 111 blk = &blk_p[block];
e27e3dac651771 Douglas Thompson 2007-07-19 112 blk->instance = inst;
e27e3dac651771 Douglas Thompson 2007-07-19 113 snprintf(blk->name, sizeof(blk->name),
0d24a49e88b563 Borislav Petkov 2022-03-08 114 "%s%d", blk_name, block + off_val);
e27e3dac651771 Douglas Thompson 2007-07-19 115
956b9ba156dbfd Joe Perches 2012-04-29 116 edac_dbg(4, "instance=%d inst_p=%p block=#%d block_p=%p name='%s'\n",
956b9ba156dbfd Joe Perches 2012-04-29 117 instance, inst, block, blk, blk->name);
e27e3dac651771 Douglas Thompson 2007-07-19 118 }
e27e3dac651771 Douglas Thompson 2007-07-19 119 }
e27e3dac651771 Douglas Thompson 2007-07-19 120
e27e3dac651771 Douglas Thompson 2007-07-19 121 /* Mark this instance as merely ALLOCATED */
e27e3dac651771 Douglas Thompson 2007-07-19 122 dev_ctl->op_state = OP_ALLOC;
e27e3dac651771 Douglas Thompson 2007-07-19 123
1c3631ff1f805c Douglas Thompson 2007-07-19 124 /*
1c3631ff1f805c Douglas Thompson 2007-07-19 125 * Initialize the 'root' kobj for the edac_device controller
1c3631ff1f805c Douglas Thompson 2007-07-19 126 */
1c3631ff1f805c Douglas Thompson 2007-07-19 127 err = edac_device_register_sysfs_main_kobj(dev_ctl);
9fb9ce392aae0c Borislav Petkov 2022-03-08 128 if (err)
9fb9ce392aae0c Borislav Petkov 2022-03-08 129 goto free;
1c3631ff1f805c Douglas Thompson 2007-07-19 130
1c3631ff1f805c Douglas Thompson 2007-07-19 131 /* at this point, the root kobj is valid, and in order to
1c3631ff1f805c Douglas Thompson 2007-07-19 132 * 'free' the object, then the function:
1c3631ff1f805c Douglas Thompson 2007-07-19 133 * edac_device_unregister_sysfs_main_kobj() must be called
1c3631ff1f805c Douglas Thompson 2007-07-19 134 * which will perform kobj unregistration and the actual free
1c3631ff1f805c Douglas Thompson 2007-07-19 135 * will occur during the kobject callback operation
1c3631ff1f805c Douglas Thompson 2007-07-19 136 */
1c3631ff1f805c Douglas Thompson 2007-07-19 137
e27e3dac651771 Douglas Thompson 2007-07-19 138 return dev_ctl;
9fb9ce392aae0c Borislav Petkov 2022-03-08 139
9fb9ce392aae0c Borislav Petkov 2022-03-08 140 free:
9fb9ce392aae0c Borislav Petkov 2022-03-08 141 __edac_device_free_ctl_info(dev_ctl);
9fb9ce392aae0c Borislav Petkov 2022-03-08 142
9fb9ce392aae0c Borislav Petkov 2022-03-08 143 return NULL;
e27e3dac651771 Douglas Thompson 2007-07-19 144 }
e27e3dac651771 Douglas Thompson 2007-07-19 145 EXPORT_SYMBOL_GPL(edac_device_alloc_ctl_info);
e27e3dac651771 Douglas Thompson 2007-07-19 146 --
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki