@@ -407,6 +407,50 @@ int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
407
407
}
408
408
EXPORT_SYMBOL_GPL (sysfs_chmod_file );
409
409
410
+ /**
411
+ * sysfs_break_active_protection - break "active" protection
412
+ * @kobj: The kernel object @attr is associated with.
413
+ * @attr: The attribute to break the "active" protection for.
414
+ *
415
+ * With sysfs, just like kernfs, deletion of an attribute is postponed until
416
+ * all active .show() and .store() callbacks have finished unless this function
417
+ * is called. Hence this function is useful in methods that implement self
418
+ * deletion.
419
+ */
420
+ struct kernfs_node * sysfs_break_active_protection (struct kobject * kobj ,
421
+ const struct attribute * attr )
422
+ {
423
+ struct kernfs_node * kn ;
424
+
425
+ kobject_get (kobj );
426
+ kn = kernfs_find_and_get (kobj -> sd , attr -> name );
427
+ if (kn )
428
+ kernfs_break_active_protection (kn );
429
+ return kn ;
430
+ }
431
+ EXPORT_SYMBOL_GPL (sysfs_break_active_protection );
432
+
433
+ /**
434
+ * sysfs_unbreak_active_protection - restore "active" protection
435
+ * @kn: Pointer returned by sysfs_break_active_protection().
436
+ *
437
+ * Undo the effects of sysfs_break_active_protection(). Since this function
438
+ * calls kernfs_put() on the kernfs node that corresponds to the 'attr'
439
+ * argument passed to sysfs_break_active_protection() that attribute may have
440
+ * been removed between the sysfs_break_active_protection() and
441
+ * sysfs_unbreak_active_protection() calls, it is not safe to access @kn after
442
+ * this function has returned.
443
+ */
444
+ void sysfs_unbreak_active_protection (struct kernfs_node * kn )
445
+ {
446
+ struct kobject * kobj = kn -> parent -> priv ;
447
+
448
+ kernfs_unbreak_active_protection (kn );
449
+ kernfs_put (kn );
450
+ kobject_put (kobj );
451
+ }
452
+ EXPORT_SYMBOL_GPL (sysfs_unbreak_active_protection );
453
+
410
454
/**
411
455
* sysfs_remove_file_ns - remove an object attribute with a custom ns tag
412
456
* @kobj: object we're acting for
0 commit comments