Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp1000891img; Fri, 22 Mar 2019 13:17:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqx1+l1/JM3b8xQhd1lH3H5epn3XsLK18gs18rpK2oYyWW5A0p4iQKMZwbjipxA2ZvUKjkZ2 X-Received: by 2002:a62:ee03:: with SMTP id e3mr11234862pfi.241.1553285830140; Fri, 22 Mar 2019 13:17:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553285830; cv=none; d=google.com; s=arc-20160816; b=rG2l+BHYEzXKeLrAX+bq4vhlHQfFA10mD8indaw8FL0g1JQRQIsJ7GyY3c3Fp7AAB2 9tQVJU2rtJzd9jH5LlcjBcV1DW2yA7B0PRRIFAzL47sJ2jeeJ4kHEuGVOZxS24MGXtCa Rf5Cd2usWQyGNsRpGy3sdRyxhNPOSzcBfcAFx+oxi61mdrS160cswS0j3VXDT04sCIdE puWgvmxkhWeL+0HlfI+OVqsNeiv+FhRAj3v5ubVEr1AGopa2P5o1rAI/PI28DqksCX5r igHhl/zTENxWcZSiOIA56KFdCZwUf00BzZpRMDq64iFLDxdg3TmrGB/OrkWJlXwC/J7M yMSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-transfer-encoding :content-disposition:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=lhbKbOmtHpV/pF1JUjV1D5/KDzGY4a07jsH4EYtOhaY=; b=E/JHIMBEAQJAVfQAPjbqMehcX1YiNZPfdS9nNvgPN6iuIiaQuaonw5XhWz8gsuSVKQ ijC0go6rmpT9il0iHLJKyZHhW19ExVrXqhTrXWqH9uqeHgHl5NkmVTtjfSgUkzlRdtRU Vkm7LcBF0OJkxZysYDLrY8LMmh+U1zO/k6FEdyHB5U2TdYq0rnnLzoEZhKC4IVKFHbu8 vzvKyB8HVrkyK3mqs/tvqt5UpJ1YE7KAml929qemUgEd21SH/2E/nVJEux3dm3RcY4xe iynelLEcS8osax26cCx2QBICx749TM6lN9Fh6oEnDiJMKiw2fEXAGMdWTT9ZO9plNjnH zNrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=To7dCAIl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2si7212544pgw.161.2019.03.22.13.16.54; Fri, 22 Mar 2019 13:17:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=To7dCAIl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727227AbfCVUOo (ORCPT + 99 others); Fri, 22 Mar 2019 16:14:44 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:34998 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726091AbfCVUOo (ORCPT ); Fri, 22 Mar 2019 16:14:44 -0400 Received: by mail-it1-f194.google.com with SMTP id w15so5351323itc.0 for ; Fri, 22 Mar 2019 13:14:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:user-agent; bh=lhbKbOmtHpV/pF1JUjV1D5/KDzGY4a07jsH4EYtOhaY=; b=To7dCAIleFEZoS6UaisSRXnAS0gRXeUSYLWQY4tYwzzEDfnMqpen+mdTuUtRcTQwgO 23EkKPHUN+NjlRGQnLJ2TGFaSMlNJSGVE3DVCzeL4OKJ2LYt9lWPjQloqZR3Evvgo/Sl bMm3KBfw6hDfu+LtHjwfuPPjvJgYEXntrT/FIjlVpZLiEEfcCkJJDG+FVKAejEwhho+n X49IXGeJJE2Zf5Efj7O/dL8S1KPVZKs2+1CiUUTeimRhsy0myxpbtwyTf+jvIOAVLdj+ YJ7OTwvzjxvQlkUCOOoGuXEdtT/ZzPUvSn6mnGuBRScfIznV+O4u5I6atPojpd46VVdm TSSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:user-agent; bh=lhbKbOmtHpV/pF1JUjV1D5/KDzGY4a07jsH4EYtOhaY=; b=KfBgYHWcHtzk9AQc6PNkKZVZpGv0KmTI43f1wheQpsYsicBSRpV+TuVDgTHJBIDUnl 0J9eZiBlhtpjxfEPGuWpHxyexU5tmeDSV1rpiDDQ01+cg1lKNqE0W43f/MnSdqS9/dkv gGIVfiYkxB2rGMuv0kBmeFOAJNLMIIcRtXH/E1SP8egV7IqjMgXtDwQ1/p6ab4nCQ6hV 5k/mHMtgkTfqfN4DuZcWR2UM+aeygwX3ts1ILPZju9UkiiYZoKhA+ZzAUxxLa6MSnyxK 4hSc5aZASl3F1o8wGdDUpO4Hs39Ej+v25c33C7vsRLQGdmIXrsKP4tEQMK73Kdh3pwRT oQXw== X-Gm-Message-State: APjAAAUjBElPFZR1l2BDCQZC0tUcznqHk47J7DBtbyyq0RRwn4bs8DvH 49MI7oPGwurVFZ7loXm+EM4= X-Received: by 2002:a05:660c:50:: with SMTP id p16mr2743494itk.139.1553285683152; Fri, 22 Mar 2019 13:14:43 -0700 (PDT) Received: from ubu-Virtual-Machine (66-188-57-61.dhcp.bycy.mi.charter.com. [66.188.57.61]) by smtp.gmail.com with ESMTPSA id v10sm2154563itv.8.2019.03.22.13.14.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Mar 2019 13:14:42 -0700 (PDT) Date: Fri, 22 Mar 2019 16:14:40 -0400 From: Kimberly Brown To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: linux-kernel@vger.kernel.org Subject: [PATCH] kobject: Add support for default attribute groups to kobj_type Message-ID: <20190322201440.GA30814@ubu-Virtual-Machine> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kobj_type currently uses a list of individual attributes to store default attributes. Attribute groups are more flexible than a list of attributes because groups provide support for attribute visibility. So, add support for default attribute groups to kobj_type. In future patches, the existing uses of kobj_type’s attribute list will be converted to attribute groups. When that is complete, kobj_type’s attribute list, “default_attrs”, will be removed. Signed-off-by: Kimberly Brown --- include/linux/kobject.h | 3 ++- lib/kobject.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/linux/kobject.h b/include/linux/kobject.h index 1ab0d624fb36..e2ca0a292e21 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -139,7 +139,8 @@ static inline bool kobject_has_children(struct kobject *kobj) struct kobj_type { void (*release)(struct kobject *kobj); const struct sysfs_ops *sysfs_ops; - struct attribute **default_attrs; + struct attribute **default_attrs; /* use default_groups instead */ + const struct attribute_group **default_groups; const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj); const void *(*namespace)(struct kobject *kobj); void (*get_ownership)(struct kobject *kobj, kuid_t *uid, kgid_t *gid); diff --git a/lib/kobject.c b/lib/kobject.c index b72e00fd7d09..67789f34951d 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -82,6 +82,7 @@ static int populate_dir(struct kobject *kobj) static int create_dir(struct kobject *kobj) { + const struct kobj_type *ktype = get_ktype(kobj); const struct kobj_ns_type_operations *ops; int error; @@ -95,6 +96,14 @@ static int create_dir(struct kobject *kobj) return error; } + if (ktype) { + error = sysfs_create_groups(kobj, ktype->default_groups); + if (error) { + sysfs_remove_dir(kobj); + return error; + } + } + /* * @kobj->sd may be deleted by an ancestor going away. Hold an * extra reference so that it stays until @kobj is gone. @@ -584,11 +593,16 @@ EXPORT_SYMBOL_GPL(kobject_move); void kobject_del(struct kobject *kobj) { struct kernfs_node *sd; + const struct kobj_type *ktype = get_ktype(kobj); if (!kobj) return; sd = kobj->sd; + + if (ktype) + sysfs_remove_groups(kobj, ktype->default_groups); + sysfs_remove_dir(kobj); sysfs_put(sd); -- 2.17.1