From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Gwendal Grignou <gwendal@google.com>
Cc: Gwendal Grignou <gwendal@chromium.org>, chrome-platform@lists.linux.dev
Subject: Re: [PATCH 2/2] chrome: lightbar: Add support for large sequence
Date: Tue, 27 Jan 2026 06:09:25 +0000 [thread overview]
Message-ID: <aXhWlV6SyaAAum-Q@google.com> (raw)
In-Reply-To: <CAMHSBOUN0RobxFG0SA-SgXeRa6nqObBeqaWuJaRphySM886=bg@mail.gmail.com>
On Mon, Jan 26, 2026 at 01:19:16AM -0800, Gwendal Grignou wrote:
> On Sun, Jan 25, 2026 at 11:14 PM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
> > On Sat, Jan 24, 2026 at 12:59:14AM -0800, Gwendal Grignou wrote:
> > > @@ -478,14 +484,22 @@ static ssize_t program_store(struct device *dev, struct device_attribute *attr,
> > > * and send a program that is too big for the protocol. In order
> > > * to ensure the latter, we also need to ensure we have extra bytes
> > > * to represent the rest of the packet.
> > > + * With V3, larger program can be sent, limited only by the EC.
> > > + * Only the protocol limit the payload size.
> > > */
> > > - extra_bytes = sizeof(*param) - sizeof(param->set_program.data);
> > > - max_size = min(EC_LB_PROG_LEN, ec->ec_dev->max_request - extra_bytes);
> > > - if (count > max_size) {
> > > - dev_err(dev, "Program is %u bytes, too long to send (max: %u)",
> > > - (unsigned int)count, max_size);
> > > -
> > > - return -EINVAL;
> > > + if (lb_version < 3) {
> > > + extra_bytes = sizeof(*param) - sizeof(param->set_program.data);
> > > + max_size = min(EC_LB_PROG_LEN, ec->ec_dev->max_request - extra_bytes);
> > > + if (count > max_size) {
> > > + dev_err(dev, "Program is %zu bytes, too long to send (max: %zu)",
> > > + count, max_size);
> > > +
> > > + return -EINVAL;
> > > + }
> > > + } else {
> > > + extra_bytes = sizeof(*param) - sizeof(param->set_program) +
> > > + sizeof(param->set_program_ex);
> >
> > I don't understand the code. What does `extra_bytes` want to count here?
> > Why `sizeof(param->set_program)` is involved? I thought it should be:
> >
> > extra_bytes = sizeof(*param) - sizeof(param->set_program_ex.data);
> `set_program_ex.data` is a variable array of size 0.
> `set_program.data` is a real array set to 192.
> |*param| does contain the payload array for `set_program`, so we need
> to remove it first to calculate our payload:
>
> 0 ----a ------- x --------------- 192+x -- maximal command size
> | sizeof(*param) | <<<< size of the whole command
> | | sizeof(set_program) | <<<< size of the largest subcommand
> | | .._ex |
> | extra_bytes | available for the payload |
It looks fragile as it knows `set_program` is the largest member in the
union in advance. How about something like:
extra_bytes = offsetof(typeof(*param), set_program_ex) +
sizeof(param->set_program_ex);
> > > diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h
> > > +struct lightbar_program_ex {
> > > + uint16_t offset;
> > > + uint8_t size;
> > > + uint8_t data[EC_LB_PROG_LEN];
> I see the problem: it should be [0] here. I tested with 0, I messed up
> during "cleanup" when synchronising between firmware and kernel.
Yeah, I was confused by it.
For the case, I think the content has to diverge from the firmware's header.
The flexible array member `data` should be annotated with __counted_by().
AFAIK, there is/was an on-going effort for avoiding
-Wflex-array-member-not-at-end warnings. E.g., a26c23e0d679
("KEYS: Avoid -Wflex-array-member-not-at-end warning"). Please take a look
if it needs to leverage any flex helpers.
prev parent reply other threads:[~2026-01-27 6:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-24 8:59 [PATCH 2/2] chrome: lightbar: Add support for large sequence Gwendal Grignou
2026-01-26 7:14 ` Tzung-Bi Shih
2026-01-26 9:19 ` Gwendal Grignou
2026-01-27 6:09 ` 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=aXhWlV6SyaAAum-Q@google.com \
--to=tzungbi@kernel.org \
--cc=chrome-platform@lists.linux.dev \
--cc=gwendal@chromium.org \
--cc=gwendal@google.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 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.