From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Kurt Borja <kuurtb@gmail.com>
Cc: "Hans de Goede" <hdegoede@redhat.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Joshua Grisham" <josh@joshuagrisham.com>,
"Mark Pearson" <mpearson-lenovo@squebb.ca>,
"Armin Wolf" <W_Armin@gmx.de>,
"Mario Limonciello" <mario.limonciello@amd.com>,
"Antheas Kapenekakis" <lkml@antheas.dev>,
"Derek J. Clark" <derekjohn.clark@gmail.com>,
"Prasanth Ksr" <prasanth.ksr@dell.com>,
"Jorge Lopez" <jorge.lopez2@hp.com>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org, Dell.Client.Kernel@dell.com
Subject: Re: [PATCH v5 1/6] platform/x86: firmware_attributes_class: Add device initialization methods
Date: Sun, 6 Jul 2025 08:42:01 +0200 [thread overview]
Message-ID: <05563b0c-861f-4046-9d50-87296d1bf6a2@t-8ch.de> (raw)
In-Reply-To: <20250705-fw-attrs-api-v5-1-60b6d51d93eb@gmail.com>
On 2025-07-05 00:33:56-0300, Kurt Borja wrote:
> From: Thomas Weißschuh <linux@weissschuh.net>
>
> Currently each user of firmware_attributes_class has to manually set up
> kobjects, devices, etc.
>
> Provide this infrastructure out-of-the-box through the newly introduced
> fwat_device_register().
>
> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> Co-developed-by: Kurt Borja <kuurtb@gmail.com>
> Signed-off-by: Kurt Borja <kuurtb@gmail.com>
> ---
> drivers/platform/x86/firmware_attributes_class.c | 125 +++++++++++++++++++++++
> drivers/platform/x86/firmware_attributes_class.h | 28 +++++
> 2 files changed, 153 insertions(+)
>
> diff --git a/drivers/platform/x86/firmware_attributes_class.c b/drivers/platform/x86/firmware_attributes_class.c
> index 736e96c186d9dc6d945517f090e9af903e93bbf4..290364202cce64bb0e9046e0b2bbb8d85e2cbc6f 100644
> --- a/drivers/platform/x86/firmware_attributes_class.c
> +++ b/drivers/platform/x86/firmware_attributes_class.c
> @@ -2,7 +2,14 @@
>
> /* Firmware attributes class helper module */
>
> +#include <linux/cleanup.h>
> +#include <linux/device.h>
> +#include <linux/device/class.h>
> +#include <linux/kdev_t.h>
> +#include <linux/kobject.h>
> #include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/types.h>
> #include "firmware_attributes_class.h"
>
> const struct class firmware_attributes_class = {
> @@ -10,6 +17,122 @@ const struct class firmware_attributes_class = {
> };
> EXPORT_SYMBOL_GPL(firmware_attributes_class);
>
> +static void fwat_device_release(struct device *dev)
> +{
> + struct fwat_device *fadev = to_fwat_device(dev);
> +
> + kfree(fadev);
> +}
> +
> +/**
> + * fwat_device_register - Create and register a firmware-attributes class
> + * device
> + * @parent: Parent device
> + * @name: Name of the class device
> + * @drvdata: Drvdata of the class device
> + * @groups: Extra groups for the "attributes" directory
> + *
> + * Return: pointer to the new fwat_device on success, ERR_PTR on failure
> + */
> +struct fwat_device *
> +fwat_device_register(struct device *parent, const char *name, void *drvdata,
> + const struct attribute_group **groups)
> +{
> + struct fwat_device *fadev;
> + int ret;
> +
> + if (!parent || !name)
> + return ERR_PTR(-EINVAL);
> +
> + fadev = kzalloc(sizeof(*fadev), GFP_KERNEL);
> + if (!fadev)
> + return ERR_PTR(-ENOMEM);
> +
> + fadev->groups = groups;
> + fadev->dev.class = &firmware_attributes_class;
> + fadev->dev.parent = parent;
> + fadev->dev.release = fwat_device_release;
> + dev_set_drvdata(&fadev->dev, drvdata);
> + ret = dev_set_name(&fadev->dev, "%s", name);
> + if (ret) {
> + kfree(fadev);
> + return ERR_PTR(ret);
> + }
> + ret = device_register(&fadev->dev);
> + if (ret)
> + return ERR_PTR(ret);
I think we need a put_device() here.
> +
> + fadev->attrs_kset = kset_create_and_add("attributes", NULL, &fadev->dev.kobj);
> + if (!fadev->attrs_kset) {
> + ret = -ENOMEM;
> + goto out_device_unregister;
> + }
> +
> + ret = sysfs_create_groups(&fadev->attrs_kset->kobj, groups);
> + if (ret)
> + goto out_kset_unregister;
It would be nicer for userspace to add the device to the hierarchy
only when it is set up fully.
Replacing device_register() with a device_initialize() above and
device_add() down here.
> +
> + return fadev;
> +
> +out_kset_unregister:
> + kset_unregister(fadev->attrs_kset);
I *think* the driver core should clean up any child objects
automatically, so this is unnecessary.
> +
> +out_device_unregister:
> + device_unregister(&fadev->dev);
> +
> + return ERR_PTR(ret);
> +}
> +EXPORT_SYMBOL_GPL(fwat_device_register);
> +
> +void fwat_device_unregister(struct fwat_device *fadev)
> +{
> + if (!fadev)
> + return;
> +
> + sysfs_remove_groups(&fadev->attrs_kset->kobj, fadev->groups);
> + kset_unregister(fadev->attrs_kset);
The also the two lines above would be unnecessary.
> + device_unregister(&fadev->dev);
> +}
> +EXPORT_SYMBOL_GPL(fwat_device_unregister);
> +
> +static void devm_fwat_device_release(void *data)
> +{
> + struct fwat_device *fadev = data;
> +
> + fwat_device_unregister(fadev);
> +}
> +
> +/**
> + * devm_fwat_device_register - Create and register a firmware-attributes class
> + * device
> + * @parent: Parent device
> + * @name: Name of the class device
> + * @data: Drvdata of the class device
> + * @groups: Extra groups for the class device (Optional)
> + *
> + * Device managed version of fwat_device_register().
> + *
> + * Return: pointer to the new fwat_device on success, ERR_PTR on failure
> + */
> +struct fwat_device *
> +devm_fwat_device_register(struct device *parent, const char *name, void *data,
> + const struct attribute_group **groups)
> +{
> + struct fwat_device *fadev;
> + int ret;
> +
> + fadev = fwat_device_register(parent, name, data, groups);
> + if (IS_ERR(fadev))
> + return fadev;
> +
> + ret = devm_add_action_or_reset(parent, devm_fwat_device_release, fadev);
> + if (ret)
> + return ERR_PTR(ret);
> +
> + return fadev;
> +}
> +EXPORT_SYMBOL_GPL(devm_fwat_device_register);
... and also all of the devm stuff.
> +
> static __init int fw_attributes_class_init(void)
> {
> return class_register(&firmware_attributes_class);
> @@ -23,5 +146,7 @@ static __exit void fw_attributes_class_exit(void)
> module_exit(fw_attributes_class_exit);
>
> MODULE_AUTHOR("Mark Pearson <markpearson@lenovo.com>");
> +MODULE_AUTHOR("Thomas Weißschuh <linux@weissschuh.net>");
> +MODULE_AUTHOR("Kurt Borja <kuurtb@gmail.com>");
> MODULE_DESCRIPTION("Firmware attributes class helper module");
> MODULE_LICENSE("GPL");
<snip>
next prev parent reply other threads:[~2025-07-06 6:42 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-05 3:33 [PATCH v5 0/6] platform/x86: firmware_attributes_class: Add a high level API Kurt Borja
2025-07-05 3:33 ` [PATCH v5 1/6] platform/x86: firmware_attributes_class: Add device initialization methods Kurt Borja
2025-07-06 6:42 ` Thomas Weißschuh [this message]
2025-07-06 7:12 ` Kurt Borja
2025-07-05 3:33 ` [PATCH v5 2/6] platform/x86: firmware_attributes_class: Add high level API for the attributes interface Kurt Borja
2025-07-06 7:40 ` Thomas Weißschuh
2025-07-06 20:17 ` Kurt Borja
2025-07-06 9:28 ` ALOK TIWARI
2025-07-06 20:18 ` Kurt Borja
2025-07-05 3:33 ` [PATCH v5 3/6] platform/x86: firmware_attributes_class: Move header to include directory Kurt Borja
2025-07-05 3:33 ` [PATCH v5 4/6] platform/x86: samsung-galaxybook: Transition new firmware_attributes API Kurt Borja
2025-07-06 8:28 ` Thomas Weißschuh
2025-07-05 3:34 ` [PATCH v5 5/6] Documentation: ABI: Update sysfs-class-firmware-attributes documentation Kurt Borja
2025-07-05 3:34 ` [PATCH v5 6/6] MAINTAINERS: Add FIRMWARE ATTRIBUTES CLASS entry Kurt Borja
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=05563b0c-861f-4046-9d50-87296d1bf6a2@t-8ch.de \
--to=linux@weissschuh.net \
--cc=Dell.Client.Kernel@dell.com \
--cc=W_Armin@gmx.de \
--cc=derekjohn.clark@gmail.com \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jorge.lopez2@hp.com \
--cc=josh@joshuagrisham.com \
--cc=kuurtb@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lkml@antheas.dev \
--cc=mario.limonciello@amd.com \
--cc=mpearson-lenovo@squebb.ca \
--cc=platform-driver-x86@vger.kernel.org \
--cc=prasanth.ksr@dell.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®