@@ -47,99 +47,67 @@ static void edac_device_dump_device(struct edac_device_ctl_info *edac_dev)
4747}
4848#endif /* CONFIG_EDAC_DEBUG */
4949
50- struct edac_device_ctl_info * edac_device_alloc_ctl_info (
51- unsigned sz_private ,
52- char * edac_device_name , unsigned nr_instances ,
53- char * edac_block_name , unsigned nr_blocks ,
54- unsigned offset_value , /* zero, 1, or other based offset */
55- struct edac_dev_sysfs_block_attribute * attrib_spec , unsigned nr_attrib ,
56- int device_index )
50+ /*
51+ * @off_val: zero, 1, or other based offset
52+ */
53+ struct edac_device_ctl_info *
54+ edac_device_alloc_ctl_info (unsigned pvt_sz , char * dev_name , unsigned nr_instances ,
55+ char * blk_name , unsigned nr_blocks , unsigned off_val ,
56+ struct edac_dev_sysfs_block_attribute * attrib_spec ,
57+ unsigned nr_attrib , int device_index )
5758{
58- struct edac_device_ctl_info * dev_ctl ;
59- struct edac_device_instance * dev_inst , * inst ;
60- struct edac_device_block * dev_blk , * blk_p , * blk ;
6159 struct edac_dev_sysfs_block_attribute * dev_attrib , * attrib_p , * attrib ;
62- unsigned total_size ;
63- unsigned count ;
60+ struct edac_device_block * dev_blk , * blk_p , * blk ;
61+ struct edac_device_instance * dev_inst , * inst ;
62+ struct edac_device_ctl_info * dev_ctl ;
6463 unsigned instance , block , attr ;
65- void * pvt , * p ;
64+ void * pvt ;
6665 int err ;
6766
6867 edac_dbg (4 , "instances=%d blocks=%d\n" , nr_instances , nr_blocks );
6968
70- /* Calculate the size of memory we need to allocate AND
71- * determine the offsets of the various item arrays
72- * (instance,block,attrib) from the start of an allocated structure.
73- * We want the alignment of each item (instance,block,attrib)
74- * to be at least as stringent as what the compiler would
75- * provide if we could simply hardcode everything into a single struct.
76- */
77- p = NULL ;
78- dev_ctl = edac_align_ptr (& p , sizeof (* dev_ctl ), 1 );
69+ dev_ctl = kzalloc (sizeof (struct edac_device_ctl_info ), GFP_KERNEL );
70+ if (!dev_ctl )
71+ return NULL ;
7972
80- /* Calc the 'end' offset past end of ONE ctl_info structure
81- * which will become the start of the 'instance' array
82- */
83- dev_inst = edac_align_ptr (& p , sizeof (* dev_inst ), nr_instances );
73+ dev_inst = kcalloc (nr_instances , sizeof (struct edac_device_instance ), GFP_KERNEL );
74+ if (!dev_inst )
75+ goto free ;
8476
85- /* Calc the 'end' offset past the instance array within the ctl_info
86- * which will become the start of the block array
87- */
88- count = nr_instances * nr_blocks ;
89- dev_blk = edac_align_ptr (& p , sizeof (* dev_blk ), count );
77+ dev_ctl -> instances = dev_inst ;
9078
91- /* Calc the 'end' offset past the dev_blk array
92- * which will become the start of the attrib array, if any.
93- */
94- /* calc how many nr_attrib we need */
95- if (nr_attrib > 0 )
96- count *= nr_attrib ;
97- dev_attrib = edac_align_ptr (& p , sizeof (* dev_attrib ), count );
79+ dev_blk = kcalloc (nr_instances * nr_blocks , sizeof (struct edac_device_block ), GFP_KERNEL );
80+ if (!dev_blk )
81+ goto free ;
9882
99- /* Calc the 'end' offset past the attributes array */
100- pvt = edac_align_ptr (& p , sz_private , 1 );
83+ dev_ctl -> blocks = dev_blk ;
10184
102- /* 'pvt' now points to where the private data area is.
103- * At this point 'pvt' (like dev_inst,dev_blk and dev_attrib)
104- * is baselined at ZERO
105- */
106- total_size = (( unsigned long ) pvt ) + sz_private ;
85+ if ( nr_attrib ) {
86+ dev_attrib = kcalloc ( nr_attrib , sizeof ( struct edac_dev_sysfs_block_attribute ),
87+ GFP_KERNEL );
88+ if (! dev_attrib )
89+ goto free ;
10790
108- /* Allocate the amount of memory for the set of control structures */
109- dev_ctl = kzalloc (total_size , GFP_KERNEL );
110- if (dev_ctl == NULL )
111- return NULL ;
91+ dev_ctl -> attribs = dev_attrib ;
92+ }
11293
113- /* Adjust pointers so they point within the actual memory we
114- * just allocated rather than an imaginary chunk of memory
115- * located at address 0.
116- * 'dev_ctl' points to REAL memory, while the others are
117- * ZERO based and thus need to be adjusted to point within
118- * the allocated memory.
119- */
120- dev_inst = (struct edac_device_instance * )
121- (((char * )dev_ctl ) + ((unsigned long )dev_inst ));
122- dev_blk = (struct edac_device_block * )
123- (((char * )dev_ctl ) + ((unsigned long )dev_blk ));
124- dev_attrib = (struct edac_dev_sysfs_block_attribute * )
125- (((char * )dev_ctl ) + ((unsigned long )dev_attrib ));
126- pvt = sz_private ? (((char * )dev_ctl ) + ((unsigned long )pvt )) : NULL ;
127-
128- /* Begin storing the information into the control info structure */
129- dev_ctl -> dev_idx = device_index ;
130- dev_ctl -> nr_instances = nr_instances ;
131- dev_ctl -> instances = dev_inst ;
132- dev_ctl -> pvt_info = pvt ;
94+ if (pvt_sz ) {
95+ pvt = kzalloc (pvt_sz , GFP_KERNEL );
96+ if (!pvt )
97+ goto free ;
98+
99+ dev_ctl -> pvt_info = pvt ;
100+ }
101+
102+ dev_ctl -> dev_idx = device_index ;
103+ dev_ctl -> nr_instances = nr_instances ;
133104
134105 /* Default logging of CEs and UEs */
135106 dev_ctl -> log_ce = 1 ;
136107 dev_ctl -> log_ue = 1 ;
137108
138109 /* Name of this edac device */
139- snprintf (dev_ctl -> name ,sizeof (dev_ctl -> name ),"%s" ,edac_device_name );
140-
141- edac_dbg (4 , "edac_dev=%p next after end=%p\n" ,
142- dev_ctl , pvt + sz_private );
110+ snprintf (dev_ctl -> name , sizeof (dev_ctl -> name ),"%s" , dev_name );
143111
144112 /* Initialize every Instance */
145113 for (instance = 0 ; instance < nr_instances ; instance ++ ) {
@@ -150,15 +118,14 @@ struct edac_device_ctl_info *edac_device_alloc_ctl_info(
150118 inst -> blocks = blk_p ;
151119
152120 /* name of this instance */
153- snprintf (inst -> name , sizeof (inst -> name ),
154- "%s%u" , edac_device_name , instance );
121+ snprintf (inst -> name , sizeof (inst -> name ), "%s%u" , dev_name , instance );
155122
156123 /* Initialize every block in each instance */
157124 for (block = 0 ; block < nr_blocks ; block ++ ) {
158125 blk = & blk_p [block ];
159126 blk -> instance = inst ;
160127 snprintf (blk -> name , sizeof (blk -> name ),
161- "%s%d" , edac_block_name , block + offset_value );
128+ "%s%d" , blk_name , block + off_val );
162129
163130 edac_dbg (4 , "instance=%d inst_p=%p block=#%d block_p=%p name='%s'\n" ,
164131 instance , inst , block , blk , blk -> name );
@@ -210,10 +177,8 @@ struct edac_device_ctl_info *edac_device_alloc_ctl_info(
210177 * Initialize the 'root' kobj for the edac_device controller
211178 */
212179 err = edac_device_register_sysfs_main_kobj (dev_ctl );
213- if (err ) {
214- kfree (dev_ctl );
215- return NULL ;
216- }
180+ if (err )
181+ goto free ;
217182
218183 /* at this point, the root kobj is valid, and in order to
219184 * 'free' the object, then the function:
@@ -223,6 +188,11 @@ struct edac_device_ctl_info *edac_device_alloc_ctl_info(
223188 */
224189
225190 return dev_ctl ;
191+
192+ free :
193+ __edac_device_free_ctl_info (dev_ctl );
194+
195+ return NULL ;
226196}
227197EXPORT_SYMBOL_GPL (edac_device_alloc_ctl_info );
228198
0 commit comments