@@ -138,27 +138,21 @@ static void remove_sect_attrs(struct module *mod)
138
138
*/
139
139
140
140
struct module_notes_attrs {
141
- struct kobject * dir ;
142
- unsigned int notes ;
143
- struct bin_attribute attrs [] __counted_by (notes );
141
+ struct attribute_group grp ;
142
+ struct bin_attribute attrs [];
144
143
};
145
144
146
- static void free_notes_attrs (struct module_notes_attrs * notes_attrs ,
147
- unsigned int i )
145
+ static void free_notes_attrs (struct module_notes_attrs * notes_attrs )
148
146
{
149
- if (notes_attrs -> dir ) {
150
- while (i -- > 0 )
151
- sysfs_remove_bin_file (notes_attrs -> dir ,
152
- & notes_attrs -> attrs [i ]);
153
- kobject_put (notes_attrs -> dir );
154
- }
147
+ kfree (notes_attrs -> grp .bin_attrs );
155
148
kfree (notes_attrs );
156
149
}
157
150
158
151
static int add_notes_attrs (struct module * mod , const struct load_info * info )
159
152
{
160
153
unsigned int notes , loaded , i ;
161
154
struct module_notes_attrs * notes_attrs ;
155
+ struct bin_attribute * * gattr ;
162
156
struct bin_attribute * nattr ;
163
157
int ret ;
164
158
@@ -177,7 +171,15 @@ static int add_notes_attrs(struct module *mod, const struct load_info *info)
177
171
if (!notes_attrs )
178
172
return - ENOMEM ;
179
173
180
- notes_attrs -> notes = notes ;
174
+ gattr = kcalloc (notes + 1 , sizeof (* gattr ), GFP_KERNEL );
175
+ if (!gattr ) {
176
+ kfree (notes_attrs );
177
+ return - ENOMEM ;
178
+ }
179
+
180
+ notes_attrs -> grp .name = "notes" ;
181
+ notes_attrs -> grp .bin_attrs = gattr ;
182
+
181
183
nattr = & notes_attrs -> attrs [0 ];
182
184
for (loaded = i = 0 ; i < info -> hdr -> e_shnum ; ++ i ) {
183
185
if (sect_empty (& info -> sechdrs [i ]))
@@ -189,35 +191,35 @@ static int add_notes_attrs(struct module *mod, const struct load_info *info)
189
191
nattr -> size = info -> sechdrs [i ].sh_size ;
190
192
nattr -> private = (void * )info -> sechdrs [i ].sh_addr ;
191
193
nattr -> read = sysfs_bin_attr_simple_read ;
192
- ++ nattr ;
194
+ * ( gattr ++ ) = nattr ++ ;
193
195
}
194
196
++ loaded ;
195
197
}
196
198
197
- notes_attrs -> dir = kobject_create_and_add ("notes" , & mod -> mkobj .kobj );
198
- if (!notes_attrs -> dir ) {
199
- ret = - ENOMEM ;
199
+ ret = sysfs_create_group (& mod -> mkobj .kobj , & notes_attrs -> grp );
200
+ if (ret )
200
201
goto out ;
201
- }
202
-
203
- for (i = 0 ; i < notes ; ++ i ) {
204
- ret = sysfs_create_bin_file (notes_attrs -> dir , & notes_attrs -> attrs [i ]);
205
- if (ret )
206
- goto out ;
207
- }
208
202
209
203
mod -> notes_attrs = notes_attrs ;
210
204
return 0 ;
211
205
212
206
out :
213
- free_notes_attrs (notes_attrs , i );
207
+ free_notes_attrs (notes_attrs );
214
208
return ret ;
215
209
}
216
210
217
211
static void remove_notes_attrs (struct module * mod )
218
212
{
219
- if (mod -> notes_attrs )
220
- free_notes_attrs (mod -> notes_attrs , mod -> notes_attrs -> notes );
213
+ if (mod -> notes_attrs ) {
214
+ sysfs_remove_group (& mod -> mkobj .kobj ,
215
+ & mod -> notes_attrs -> grp );
216
+ /*
217
+ * We are positive that no one is using any notes attrs
218
+ * at this point. Deallocate immediately.
219
+ */
220
+ free_notes_attrs (mod -> notes_attrs );
221
+ mod -> notes_attrs = NULL ;
222
+ }
221
223
}
222
224
223
225
#else /* !CONFIG_KALLSYMS */
0 commit comments