All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Sean Rhodes <sean@starlabs.systems>
Cc: hansg@kernel.org, ilpo.jarvinen@linux.intel.com,
	corentin.chary@gmail.com, luke@ljones.dev,
	denis.benato@linux.dev, prasanth.ksr@dell.com,
	jorge.lopez2@hp.com, mpearson-lenovo@squebb.ca,
	derekjohn.clark@gmail.com, josh@joshuagrisham.com,
	briannorris@chromium.org, jwerner@chromium.org,
	tzimmermann@suse.de, javierm@redhat.com, kees@kernel.org,
	u.kleine-koenig@baylibre.com, mst@redhat.com,
	chenhuacai@kernel.org, wenst@chromium.org,
	florian.fainelli@broadcom.com, titouan.ameline@gmail.com,
	oliver@liuxiaozhen.dev, linux-kernel@vger.kernel.org,
	platform-driver-x86@vger.kernel.org, Dell.Client.Kernel@dell.com,
	chrome-platform@lists.linux.dev
Subject: Re: [PATCH v7 3/3] firmware: coreboot: Add CFR firmware attributes driver
Date: Mon, 20 Jul 2026 06:48:45 +0000	[thread overview]
Message-ID: <al3EzcPFCx-kL54h@google.com> (raw)
In-Reply-To: <20260717085003.369496-4-sean@starlabs.systems>

On Fri, Jul 17, 2026 at 09:50:03AM +0100, Sean Rhodes wrote:
> diff --git a/drivers/firmware/coreboot/coreboot-cfr.c b/drivers/firmware/coreboot/coreboot-cfr.c
...
> +static int coreboot_cfr_read_efi_value_locked(efi_char16_t *efi_name,
> +					      u32 *value, u32 *attrs)
> +{

There is no coreboot_cfr_read_efi_value() and the symbol isn't exported
anyway.  The "_locked" suffix here is redundant.  Instead, it can leave a
note in the comment to indicate the lock requirement.

> +static int coreboot_cfr_read_value(const struct coreboot_cfr_setting *setting,
> +				   u32 *value, u32 *attrs)
> +{
> +	efi_char16_t *efi_name;
> +	int ret;
> +
> +	efi_name = coreboot_cfr_efi_name(setting->name);
> +	if (IS_ERR(efi_name))
> +		return PTR_ERR(efi_name);
> +
> +	ret = efivar_lock();
> +	if (ret) {
> +		kfree(efi_name);
> +		return ret;

To be neat, use a goto statement to clean up.

> +static int coreboot_cfr_write_efi_value_locked(efi_char16_t *efi_name,
> +					       u32 value, u32 attrs)

Same here.  s/_locked//.

> +static int coreboot_cfr_write_value(struct coreboot_cfr_setting *setting,
> +				    u32 value)
> +{
> +	efi_char16_t *efi_name;
> +	u32 attrs;
> +	u32 old;
> +	int restore_ret;
> +	int ret;
> +	bool changed = false;

The initialization can be eliminated.  See comments below.

> +
> +	if (setting->read_only)
> +		return -EACCES;
> +
> +	efi_name = coreboot_cfr_efi_name(setting->name);
> +	if (IS_ERR(efi_name))
> +		return PTR_ERR(efi_name);
> +
> +	mutex_lock(&setting->drvdata->lock);

Since it already includes cleanup.h, how about using a guard()?

> +	ret = coreboot_cfr_write_efi_value_locked(efi_name, value, attrs);
> +	if (ret)
> +		goto out_unlock_efi;
> +	changed = true;
> +
> +	ret = coreboot_cfr_apply_runtime(setting);
> +	if (ret == -EOPNOTSUPP) {
> +		/* EFI changed; firmware will consume it after reboot. */
> +		setting->drvdata->pending_reboot = true;
> +		ret = 0;
> +	} else if (ret) {
> +		restore_ret = coreboot_cfr_write_efi_value_locked(efi_name, old, attrs);
> +		if (restore_ret) {
> +			setting->drvdata->pending_reboot = true;
> +			ret = restore_ret;
> +		} else if (coreboot_cfr_apply_runtime(setting)) {

Does it need to apply runtime again for old values?  The previous
coreboot_cfr_apply_runtime() for new values was just failed (i.e., the new
values shouldn't take effect).

> +			setting->drvdata->pending_reboot = true;
> +		} else {
> +			changed = false;
> +		}
> +	}
> +
> +out_unlock_efi:
> +	efivar_unlock();
> +out_unlock_mutex:
> +	mutex_unlock(&setting->drvdata->lock);
> +	kfree(efi_name);
> +
> +	if (changed)
> +		kobject_uevent(&setting->drvdata->class_dev->kobj, KOBJ_CHANGE);

This shouldn't be in the cleanup path.  Move it before the label
"out_unlock_efi".  `changed` only makes sense after calling
coreboot_cfr_write_efi_value_locked().

> +static bool
> +coreboot_cfr_possible_values_fit(const struct coreboot_cfr_setting *setting)

The function needs some comments to explain why and what.

> +{
> +	size_t len = 1; /* Trailing newline. */
> +	unsigned int i;
> +
> +	for (i = 0; i < setting->n_values; i++) {
> +		if (i)
> +			len++;

What is this for?  For ';'?

> +
> +		if (strlen(setting->values[i].label) >= PAGE_SIZE - len)
> +			return false;
> +
> +		len += strlen(setting->values[i].label);

A straightforward way:

    len += strlen(...);
    if (len >= PAGE_SIZE)
        ...

> +static int coreboot_cfr_add_numeric_option(struct coreboot_cfr_drvdata *data,
> +					   const struct lb_cfr_numeric_option *option,
> +					   bool parent_read_only)
> +{
...
> +	if (setting->type != COREBOOT_CFR_SETTING_NUMBER &&
> +	    !coreboot_cfr_possible_values_fit(setting)) {
> +		ret = 0;
> +		goto err_put_setting;
> +	}

Why it skips if the possible values can be truncated?  Is it seen as a
critical setting?

This needs some comments to explain why and what.

> +
> +	ret = coreboot_cfr_setting_is_usable(setting);
> +	if (ret) {
> +		if (ret == -ENOENT || ret == -EINVAL || ret == -EOPNOTSUPP ||
> +		    ret == -ENAMETOOLONG)
> +			ret = 0;

Does it check for values from coreboot table have corresponding EFI vars?
Why these errors aren't considered as failures?

This needs some comments to explain why and what.

> +		goto err_put_setting;
> +	}
> +
> +	ret = coreboot_cfr_register_setting(data, setting);
> +	if (ret)
> +		return ret;
> +
> +	return 0;

A simple way:

    return coreboot_cfr_register_setting(...);

Also it may be worth some comments to mention that after calling
coreboot_cfr_register_setting(), `coreboot_cfr_setting_ktype` takes care of
the resource release.

      reply	other threads:[~2026-07-20  6:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17  8:50 [PATCH v7 0/3] firmware: Add coreboot CFR firmware attributes driver Sean Rhodes
2026-07-17  8:50 ` [PATCH v7 1/3] firmware: Move firmware attributes class helper Sean Rhodes
2026-07-18  2:22   ` Derek J. Clark
2026-07-17  8:50 ` [PATCH v7 2/3] firmware: Rename google firmware directory to coreboot Sean Rhodes
2026-07-18  0:39   ` Julius Werner
2026-07-17  8:50 ` [PATCH v7 3/3] firmware: coreboot: Add CFR firmware attributes driver Sean Rhodes
2026-07-20  6:48   ` Tzung-Bi Shih [this message]

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=al3EzcPFCx-kL54h@google.com \
    --to=tzungbi@kernel.org \
    --cc=Dell.Client.Kernel@dell.com \
    --cc=briannorris@chromium.org \
    --cc=chenhuacai@kernel.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=corentin.chary@gmail.com \
    --cc=denis.benato@linux.dev \
    --cc=derekjohn.clark@gmail.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=javierm@redhat.com \
    --cc=jorge.lopez2@hp.com \
    --cc=josh@joshuagrisham.com \
    --cc=jwerner@chromium.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luke@ljones.dev \
    --cc=mpearson-lenovo@squebb.ca \
    --cc=mst@redhat.com \
    --cc=oliver@liuxiaozhen.dev \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=prasanth.ksr@dell.com \
    --cc=sean@starlabs.systems \
    --cc=titouan.ameline@gmail.com \
    --cc=tzimmermann@suse.de \
    --cc=u.kleine-koenig@baylibre.com \
    --cc=wenst@chromium.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.