@@ -4198,19 +4198,26 @@ static void cgroup_exit_cftypes(struct cftype *cfts)
4198
4198
cft -> ss = NULL ;
4199
4199
4200
4200
/* revert flags set by cgroup core while adding @cfts */
4201
- cft -> flags &= ~(__CFTYPE_ONLY_ON_DFL | __CFTYPE_NOT_ON_DFL );
4201
+ cft -> flags &= ~(__CFTYPE_ONLY_ON_DFL | __CFTYPE_NOT_ON_DFL |
4202
+ __CFTYPE_ADDED );
4202
4203
}
4203
4204
}
4204
4205
4205
4206
static int cgroup_init_cftypes (struct cgroup_subsys * ss , struct cftype * cfts )
4206
4207
{
4207
4208
struct cftype * cft ;
4209
+ int ret = 0 ;
4208
4210
4209
4211
for (cft = cfts ; cft -> name [0 ] != '\0' ; cft ++ ) {
4210
4212
struct kernfs_ops * kf_ops ;
4211
4213
4212
4214
WARN_ON (cft -> ss || cft -> kf_ops );
4213
4215
4216
+ if (cft -> flags & __CFTYPE_ADDED ) {
4217
+ ret = - EBUSY ;
4218
+ break ;
4219
+ }
4220
+
4214
4221
if ((cft -> flags & CFTYPE_PRESSURE ) && !cgroup_psi_enabled ())
4215
4222
continue ;
4216
4223
@@ -4226,26 +4233,26 @@ static int cgroup_init_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
4226
4233
if (cft -> max_write_len && cft -> max_write_len != PAGE_SIZE ) {
4227
4234
kf_ops = kmemdup (kf_ops , sizeof (* kf_ops ), GFP_KERNEL );
4228
4235
if (!kf_ops ) {
4229
- cgroup_exit_cftypes ( cfts ) ;
4230
- return - ENOMEM ;
4236
+ ret = - ENOMEM ;
4237
+ break ;
4231
4238
}
4232
4239
kf_ops -> atomic_write_len = cft -> max_write_len ;
4233
4240
}
4234
4241
4235
4242
cft -> kf_ops = kf_ops ;
4236
4243
cft -> ss = ss ;
4244
+ cft -> flags |= __CFTYPE_ADDED ;
4237
4245
}
4238
4246
4239
- return 0 ;
4247
+ if (ret )
4248
+ cgroup_exit_cftypes (cfts );
4249
+ return ret ;
4240
4250
}
4241
4251
4242
4252
static int cgroup_rm_cftypes_locked (struct cftype * cfts )
4243
4253
{
4244
4254
lockdep_assert_held (& cgroup_mutex );
4245
4255
4246
- if (!cfts || !cfts [0 ].ss )
4247
- return - ENOENT ;
4248
-
4249
4256
list_del (& cfts -> node );
4250
4257
cgroup_apply_cftypes (cfts , false);
4251
4258
cgroup_exit_cftypes (cfts );
@@ -4267,6 +4274,12 @@ int cgroup_rm_cftypes(struct cftype *cfts)
4267
4274
{
4268
4275
int ret ;
4269
4276
4277
+ if (!cfts || cfts [0 ].name [0 ] == '\0' )
4278
+ return 0 ;
4279
+
4280
+ if (!(cfts [0 ].flags & __CFTYPE_ADDED ))
4281
+ return - ENOENT ;
4282
+
4270
4283
mutex_lock (& cgroup_mutex );
4271
4284
ret = cgroup_rm_cftypes_locked (cfts );
4272
4285
mutex_unlock (& cgroup_mutex );
0 commit comments