From: Cody P Schafer <cody@linux.vnet.ibm.com>
Subject: sysfs: create bin_attributes under the requested group
Git-commit: e1ed9bc0ee204ea839dac33ef6bd6c813188d75e
Patch-mainline: v3.15-rc1
References: bnc#870365,fate#315738 

[tonyj: backported to SLE12 due to missing kernfs]
    
    bin_attributes created/updated in create_files() (such as those listed
    via (struct device).attribute_groups) were not placed under the
    specified group, and instead appeared in the base kobj directory.
    
    Fix this by making bin_attributes use creating code similar to normal
    attributes.
    
    A quick grep shows that no one is using bin_attrs in a named attribute
    group yet, so we can do this without breaking anything in usespace.
    
    Note that I do not add is_visible() support to
    bin_attributes, though that could be done as well.
    
    This is a copy of the patch already merged in Greg's tree.
    
Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Torsten Duwe <duwe@suse.de>

 fs/sysfs/group.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 6b57938..aa04068 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -70,8 +70,11 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj,
 	if (grp->bin_attrs) {
 		for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) {
 			if (update)
-				sysfs_remove_bin_file(kobj, *bin_attr);
-			error = sysfs_create_bin_file(kobj, *bin_attr);
+				sysfs_hash_and_remove(dir_sd, NULL,
+						(*bin_attr)->attr.name);
+			error = sysfs_add_file_mode(dir_sd, &(*bin_attr)->attr,
+					SYSFS_KOBJ_BIN_ATTR,
+					(*bin_attr)->attr.mode);
 			if (error)
 				break;
 		}
