From: Greg KH <gregkh@linuxfoundation.org>
To: Oleksij Rempel <o.rempel@pengutronix.de>,
Sebastian Reichel <sre@kernel.org>,
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Benson Leung <bleung@chromium.org>,
Tzung-Bi Shih <tzungbi@kernel.org>,
Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: "Oleksij Rempel" <o.rempel@pengutronix.de>,
kernel@pengutronix.de, linux-kernel@vger.kernel.org,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Zhang Rui" <rui.zhang@intel.com>,
"Lukasz Luba" <lukasz.luba@arm.com>,
linux-pm@vger.kernel.org, "Søren Andersen" <san@skov.dk>,
"Guenter Roeck" <groeck@chromium.org>,
"Matti Vaittinen" <mazziesaccount@gmail.com>,
"Ahmad Fatoum" <a.fatoum@pengutronix.de>,
"Andrew Morton" <akpm@linux-foundation.org>,
chrome-platform@lists.linux.dev
Subject: Re: [PATCH v11 3/7] power: reset: Introduce PSCR Recording Framework for Non-Volatile Storage
Date: Wed, 16 Jul 2025 14:43:47 +0200 [thread overview]
Message-ID: <2025071645-panoramic-pyromania-2f8c@gregkh> (raw)
In-Reply-To: <20250618120255.3141862-4-o.rempel@pengutronix.de>
Overall, no real issues, just some very minor ones:
On Wed, Jun 18, 2025 at 02:02:51PM +0200, Oleksij Rempel wrote:
> + * Sysfs Interface:
> + * ----------------
> + * /sys/kernel/pscrr/reason - Read/write current power state change
> + * reason
> + * /sys/kernel/pscrr/reason_boot - Read-only last recorded reason from
> + * previous boot
The sysfs documentation is in the ABI file, so it's not needed here.
> +static int pscrr_reboot_notifier(struct notifier_block *nb,
> + unsigned long action, void *unused)
> +{
> + struct pscrr_backend *backend;
> + int ret;
> +
> + guard(g_pscrr)(&g_pscrr);
> +
> + backend = g_pscrr.backend;
> +
> + if (!backend || !backend->ops || !backend->ops->write_reason)
> + return NOTIFY_DONE;
> +
> + ret = backend->ops->write_reason(get_psc_reason());
> + if (ret) {
> + pr_err("PSCRR: Failed to store reason %d (%s) at reboot, err=%pe\n",
> + get_psc_reason(), psc_reason_to_str(get_psc_reason()),
> + ERR_PTR(ret));
> + } else {
> + pr_info("PSCRR: Stored reason %d (%s) at reboot.\n",
> + get_psc_reason(), psc_reason_to_str(get_psc_reason()));
Why print anything? If this works properly, it should be quiet, right?
> +static ssize_t reason_show(struct kobject *kobj, struct kobj_attribute *attr,
> + char *buf)
> +{
> + struct pscrr_backend *backend;
> + enum psc_reason r;
> +
> + guard(g_pscrr)(&g_pscrr);
> +
> + backend = g_pscrr.backend;
> +
> + if (!backend || !backend->ops)
> + return scnprintf(buf, PAGE_SIZE, "No backend registered\n");
So a string, or an int will be returned? That's crazy, just return an
error here, -ENODEV?
> +
> + /* If the backend can read from hardware, do so. Otherwise, use our cached value. */
> + if (backend->ops->read_reason) {
> + if (backend->ops->read_reason(&r) == 0) {
> + /* Also update our cached value for consistency */
> + set_psc_reason(r);
> + } else {
> + /* If read fails, fallback to cached. */
> + r = get_psc_reason();
> + }
> + } else {
> + r = get_psc_reason();
> + }
> +
> + return scnprintf(buf, PAGE_SIZE, "%d\n", r);
sysfs files should use sysfs_emit() so you don't get people sending you
patches later on to convert it :)
> +static ssize_t reason_store(struct kobject *kobj, struct kobj_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct pscrr_backend *backend;
> + long val;
> + int ret;
> +
> + guard(g_pscrr)(&g_pscrr);
> +
> + backend = g_pscrr.backend;
> +
> + if (!backend || !backend->ops || !backend->ops->write_reason)
> + return -ENODEV;
> +
> + ret = kstrtol(buf, 10, &val);
> + if (ret)
> + return ret;
> +
> + if (val > U32_MAX)
> + return -ERANGE;
> +
> + if (val < PSCR_UNKNOWN || val > PSCR_MAX_REASON)
> + /*
> + * Log a warning, but still attempt to write the value. In
> + * case the backend can handle it, we don't want to block it.
> + */
> + pr_warn("PSCRR: writing unknown reason %ld (out of range)\n",
> + val);
Do not let userspace cause a DoS of kernel log messages just because it
sent you an invalid data range.
> +static struct kobj_attribute reason_attr = __ATTR(reason, 0644, reason_show,
> + reason_store);
__ATTR_RW(), right? If not, why not?
> +static struct kobj_attribute reason_boot_attr =
> + __ATTR(reason_boot, 0444, reason_boot_show, NULL); /* Read-only */
__ATTR_RO(), right? Then no comment is needed :)
> +int pscrr_core_init(const struct pscrr_backend_ops *ops)
> +{
> + enum psc_reason stored_val = PSCR_UNKNOWN;
> + struct pscrr_backend *backend;
> + int ret;
> +
> + guard(g_pscrr)(&g_pscrr);
> +
> + backend = g_pscrr.backend;
> +
> + if (backend) {
> + pr_err("PSCRR: Core is already initialized!\n");
All of the "PSCRR:" stuff should just be set with pr_fmt being defined
at the top of this file, don't put it everywhere manually.
> + return -EBUSY;
> + }
> +
> + if (!ops->read_reason) {
> + pr_err("PSCRR: Backend must provide read callbacks\n");
> + return -EINVAL;
> + }
> +
> + backend = kzalloc(sizeof(*backend), GFP_KERNEL);
> + if (!backend)
> + return -ENOMEM;
> +
> + backend->ops = ops;
> + backend->last_boot_reason = PSCR_UNKNOWN;
> + g_pscrr.backend = backend;
> +
> + ret = ops->read_reason(&stored_val);
> + if (!ret) {
> + backend->last_boot_reason = stored_val;
> + pr_info("PSCRR: Initial read_reason: %d (%s)\n",
> + stored_val, psc_reason_to_str(stored_val));
When code works properly, it should be quiet. Don't spam the boot log
please.
> + ret = sysfs_create_group(g_pscrr.kobj, &pscrr_attr_group);
> + if (ret) {
> + pr_err("PSCRR: Failed to create sysfs group, err=%pe\n",
> + ERR_PTR(ret));
> + goto err_kobj_put;
> + }
> +
> + pr_info("PSCRR: initialized successfully.\n");
Same here, be quiet.
> +void pscrr_core_exit(void)
> +{
> + guard(g_pscrr)(&g_pscrr);
> +
> + if (!g_pscrr.backend)
> + return;
> +
> + if (g_pscrr.kobj) {
> + sysfs_remove_group(g_pscrr.kobj, &pscrr_attr_group);
> + kobject_put(g_pscrr.kobj);
> + }
> +
> + unregister_reboot_notifier(&g_pscrr.reboot_nb);
> +
> + kfree(g_pscrr.backend);
> + g_pscrr.backend = NULL;
> +
> + pr_info("PSCRR: exited.\n");
Same here, please be quiet.
thanks,
greg k-h
next prev parent reply other threads:[~2025-07-16 12:43 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-18 12:02 [PATCH v11 0/7] Introduction of PSCR Framework and Related Components Oleksij Rempel
2025-06-18 12:02 ` [PATCH v11 1/7] power: Extend power_on_reason.h for upcoming PSCRR framework Oleksij Rempel
2025-06-18 12:02 ` [PATCH v11 2/7] reboot: hw_protection_trigger: use standardized numeric shutdown/reboot reasons instead of strings Oleksij Rempel
2025-06-18 12:02 ` [PATCH v11 3/7] power: reset: Introduce PSCR Recording Framework for Non-Volatile Storage Oleksij Rempel
2025-07-16 12:43 ` Greg KH [this message]
2025-06-18 12:02 ` [PATCH v11 4/7] nvmem: provide consumer access to cell size metrics Oleksij Rempel
2025-06-18 12:02 ` [PATCH v11 5/7] nvmem: add support for device and sysfs-based cell lookups Oleksij Rempel
2025-07-16 12:48 ` Greg KH
2025-06-18 12:02 ` [PATCH v11 6/7] power: reset: add PSCR NVMEM Driver for Recording Power State Change Reasons Oleksij Rempel
2025-06-20 15:56 ` Francesco Valla
2025-07-16 12:51 ` Greg KH
2026-06-25 11:52 ` Faruque Ansari
2025-06-18 12:02 ` [PATCH v11 7/7] Documentation: Add sysfs documentation for PSCRR reboot reason tracking Oleksij Rempel
2025-07-14 10:17 ` [PATCH v11 0/7] Introduction of PSCR Framework and Related Components Oleksij Rempel
2025-07-16 12:34 ` Greg Kroah-Hartman
2025-10-02 12:00 ` RFC: Selecting an NVMEM cell for Power State Change Reason (PSCR) recording Oleksij Rempel
2025-10-02 16:07 ` Kees Cook
2026-03-10 9:29 ` [PR 174] dt-bindings: chosen: Add "power-state-change-reason" nvmem property Oleksij Rempel
[not found] ` <3309e88e-e189-42ea-b74e-346aec1b4b5f@oss.qualcomm.com>
2026-06-29 11:14 ` [PATCH v11 0/7] Introduction of PSCR Framework and Related Components Faruque Ansari
2026-06-29 11:41 ` Oleksij Rempel
2026-07-01 12:56 ` Faruque Ansari
2026-07-02 4:21 ` Oleksij Rempel
2026-07-06 9:36 ` Faruque Ansari
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=2025071645-panoramic-pyromania-2f8c@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=a.fatoum@pengutronix.de \
--cc=akpm@linux-foundation.org \
--cc=bleung@chromium.org \
--cc=broonie@kernel.org \
--cc=chrome-platform@lists.linux.dev \
--cc=daniel.lezcano@linaro.org \
--cc=groeck@chromium.org \
--cc=kernel@pengutronix.de \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=mazziesaccount@gmail.com \
--cc=o.rempel@pengutronix.de \
--cc=rafael@kernel.org \
--cc=rui.zhang@intel.com \
--cc=san@skov.dk \
--cc=sre@kernel.org \
--cc=srinivas.kandagatla@linaro.org \
--cc=tzungbi@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.