]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
sysfs: added __compat_only_sysfs_link_entry_to_kobj()
authorJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Wed, 22 Apr 2015 16:36:06 +0000 (19:36 +0300)
committerPeter Huewe <peterhuewe@gmx.de>
Sun, 18 Oct 2015 23:01:19 +0000 (01:01 +0200)
Added a new function __compat_only_sysfs_link_group_to_kobj() that adds
a symlink from attribute or group to a kobject. This needed for
maintaining backwards compatibility with PPI attributes in the TPM
driver.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
fs/sysfs/group.c
include/linux/sysfs.h

index 39a01993676864e56b55f8125155646f808f4f40..e1236594fffec8d50b79eada956fdaadba663aff 100644 (file)
@@ -352,3 +352,47 @@ void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
        }
 }
 EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group);
+
+/**
+ * __compat_only_sysfs_link_entry_to_kobj - add a symlink to a kobject pointing
+ * to a group or an attribute
+ * @kobj:              The kobject containing the group.
+ * @target_kobj:       The target kobject.
+ * @target_name:       The name of the target group or attribute.
+ */
+int __compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj,
+                                     struct kobject *target_kobj,
+                                     const char *target_name)
+{
+       struct kernfs_node *target;
+       struct kernfs_node *entry;
+       struct kernfs_node *link;
+
+       /*
+        * We don't own @target_kobj and it may be removed at any time.
+        * Synchronize using sysfs_symlink_target_lock. See sysfs_remove_dir()
+        * for details.
+        */
+       spin_lock(&sysfs_symlink_target_lock);
+       target = target_kobj->sd;
+       if (target)
+               kernfs_get(target);
+       spin_unlock(&sysfs_symlink_target_lock);
+       if (!target)
+               return -ENOENT;
+
+       entry = kernfs_find_and_get(target_kobj->sd, target_name);
+       if (!entry) {
+               kernfs_put(target);
+               return -ENOENT;
+       }
+
+       link = kernfs_create_link(kobj->sd, target_name, entry);
+       if (IS_ERR(link) && PTR_ERR(link) == -EEXIST)
+               sysfs_warn_dup(kobj->sd, target_name);
+
+       kernfs_put(entry);
+       kernfs_put(target);
+       return IS_ERR(link) ? PTR_ERR(link) : 0;
+}
+EXPORT_SYMBOL_GPL(__compat_only_sysfs_link_entry_to_kobj);
index 9f65758311a4efff6a325f0baeb33f86ec68e06f..ea090eaf468c6337b5ad29685b0d4919e44d2fab 100644 (file)
@@ -268,6 +268,9 @@ int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
                            struct kobject *target, const char *link_name);
 void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
                                  const char *link_name);
+int __compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj,
+                                     struct kobject *target_kobj,
+                                     const char *target_name);
 
 void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
 
@@ -451,6 +454,14 @@ static inline void sysfs_remove_link_from_group(struct kobject *kobj,
 {
 }
 
+static inline int __compat_only_sysfs_link_entry_to_kobj(
+       struct kobject *kobj,
+       struct kobject *target_kobj,
+       const char *target_name)
+{
+       return 0;
+}
+
 static inline void sysfs_notify(struct kobject *kobj, const char *dir,
                                const char *attr)
 {