@@ -69,12 +69,13 @@ static void free_sect_attrs(struct module_sect_attrs *sect_attrs)
69
69
kfree (sect_attrs );
70
70
}
71
71
72
- static void add_sect_attrs (struct module * mod , const struct load_info * info )
72
+ static int add_sect_attrs (struct module * mod , const struct load_info * info )
73
73
{
74
74
unsigned int nloaded = 0 , i , size [2 ];
75
75
struct module_sect_attrs * sect_attrs ;
76
76
struct module_sect_attr * sattr ;
77
77
struct bin_attribute * * gattr ;
78
+ int ret ;
78
79
79
80
/* Count loaded sections and allocate structures */
80
81
for (i = 0 ; i < info -> hdr -> e_shnum ; i ++ )
@@ -85,7 +86,7 @@ static void add_sect_attrs(struct module *mod, const struct load_info *info)
85
86
size [1 ] = (nloaded + 1 ) * sizeof (sect_attrs -> grp .bin_attrs [0 ]);
86
87
sect_attrs = kzalloc (size [0 ] + size [1 ], GFP_KERNEL );
87
88
if (!sect_attrs )
88
- return ;
89
+ return - ENOMEM ;
89
90
90
91
/* Setup section attributes. */
91
92
sect_attrs -> grp .name = "sections" ;
@@ -103,8 +104,10 @@ static void add_sect_attrs(struct module *mod, const struct load_info *info)
103
104
sattr -> address = sec -> sh_addr ;
104
105
sattr -> battr .attr .name =
105
106
kstrdup (info -> secstrings + sec -> sh_name , GFP_KERNEL );
106
- if (!sattr -> battr .attr .name )
107
+ if (!sattr -> battr .attr .name ) {
108
+ ret = - ENOMEM ;
107
109
goto out ;
110
+ }
108
111
sect_attrs -> nsections ++ ;
109
112
sattr -> battr .read = module_sect_read ;
110
113
sattr -> battr .size = MODULE_SECT_READ_SIZE ;
@@ -113,13 +116,15 @@ static void add_sect_attrs(struct module *mod, const struct load_info *info)
113
116
}
114
117
* gattr = NULL ;
115
118
116
- if (sysfs_create_group (& mod -> mkobj .kobj , & sect_attrs -> grp ))
119
+ ret = sysfs_create_group (& mod -> mkobj .kobj , & sect_attrs -> grp );
120
+ if (ret )
117
121
goto out ;
118
122
119
123
mod -> sect_attrs = sect_attrs ;
120
- return ;
124
+ return 0 ;
121
125
out :
122
126
free_sect_attrs (sect_attrs );
127
+ return ret ;
123
128
}
124
129
125
130
static void remove_sect_attrs (struct module * mod )
@@ -158,15 +163,12 @@ static void free_notes_attrs(struct module_notes_attrs *notes_attrs,
158
163
kfree (notes_attrs );
159
164
}
160
165
161
- static void add_notes_attrs (struct module * mod , const struct load_info * info )
166
+ static int add_notes_attrs (struct module * mod , const struct load_info * info )
162
167
{
163
168
unsigned int notes , loaded , i ;
164
169
struct module_notes_attrs * notes_attrs ;
165
170
struct bin_attribute * nattr ;
166
-
167
- /* failed to create section attributes, so can't create notes */
168
- if (!mod -> sect_attrs )
169
- return ;
171
+ int ret ;
170
172
171
173
/* Count notes sections and allocate structures. */
172
174
notes = 0 ;
@@ -176,12 +178,12 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
176
178
++ notes ;
177
179
178
180
if (notes == 0 )
179
- return ;
181
+ return 0 ;
180
182
181
183
notes_attrs = kzalloc (struct_size (notes_attrs , attrs , notes ),
182
184
GFP_KERNEL );
183
185
if (!notes_attrs )
184
- return ;
186
+ return - ENOMEM ;
185
187
186
188
notes_attrs -> notes = notes ;
187
189
nattr = & notes_attrs -> attrs [0 ];
@@ -201,19 +203,23 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
201
203
}
202
204
203
205
notes_attrs -> dir = kobject_create_and_add ("notes" , & mod -> mkobj .kobj );
204
- if (!notes_attrs -> dir )
206
+ if (!notes_attrs -> dir ) {
207
+ ret = - ENOMEM ;
205
208
goto out ;
209
+ }
206
210
207
- for (i = 0 ; i < notes ; ++ i )
208
- if ( sysfs_create_bin_file (notes_attrs -> dir ,
209
- & notes_attrs -> attrs [ i ]) )
211
+ for (i = 0 ; i < notes ; ++ i ) {
212
+ ret = sysfs_create_bin_file (notes_attrs -> dir , & notes_attrs -> attrs [ i ]);
213
+ if ( ret )
210
214
goto out ;
215
+ }
211
216
212
217
mod -> notes_attrs = notes_attrs ;
213
- return ;
218
+ return 0 ;
214
219
215
220
out :
216
221
free_notes_attrs (notes_attrs , i );
222
+ return ret ;
217
223
}
218
224
219
225
static void remove_notes_attrs (struct module * mod )
@@ -223,9 +229,15 @@ static void remove_notes_attrs(struct module *mod)
223
229
}
224
230
225
231
#else /* !CONFIG_KALLSYMS */
226
- static inline void add_sect_attrs (struct module * mod , const struct load_info * info ) { }
232
+ static inline int add_sect_attrs (struct module * mod , const struct load_info * info )
233
+ {
234
+ return 0 ;
235
+ }
227
236
static inline void remove_sect_attrs (struct module * mod ) { }
228
- static inline void add_notes_attrs (struct module * mod , const struct load_info * info ) { }
237
+ static inline int add_notes_attrs (struct module * mod , const struct load_info * info )
238
+ {
239
+ return 0 ;
240
+ }
229
241
static inline void remove_notes_attrs (struct module * mod ) { }
230
242
#endif /* CONFIG_KALLSYMS */
231
243
@@ -385,11 +397,20 @@ int mod_sysfs_setup(struct module *mod,
385
397
if (err )
386
398
goto out_unreg_modinfo_attrs ;
387
399
388
- add_sect_attrs (mod , info );
389
- add_notes_attrs (mod , info );
400
+ err = add_sect_attrs (mod , info );
401
+ if (err )
402
+ goto out_del_usage_links ;
403
+
404
+ err = add_notes_attrs (mod , info );
405
+ if (err )
406
+ goto out_unreg_sect_attrs ;
390
407
391
408
return 0 ;
392
409
410
+ out_unreg_sect_attrs :
411
+ remove_sect_attrs (mod );
412
+ out_del_usage_links :
413
+ del_usage_links (mod );
393
414
out_unreg_modinfo_attrs :
394
415
module_remove_modinfo_attrs (mod , -1 );
395
416
out_unreg_param :
0 commit comments