Re: [PATCH v3 2/2] HID: lenovo-legion: Add keyboard backlight driver for Legion Gen 10
From: Ciro Pedrini
Date: Tue Dec 01 2026 - 16:57:32 EST
Hi Rong,
On Sat, 2026-11-28 at 20:01 +0800, Rong Zhang wrote:
> Since you need to serialize SET_REPORT and GET_REPORT anyway, we can use
> a preallocated buffer as v2 did. Sorry for the confusion.
No problem. v4 is back to one buffer, allocated in probe and used under
the mutex:
https://lore.kernel.org/r/20261201-legion-lighting-rfc-v4-1-b08dfda3f295@xxxxxxxxx
> > + memset(msg, 0, get_size);
>
> I am not sure why this is required.
It isn't: an answer shorter than get_size is rejected, so every byte
checked after the GET comes from the device. Dropped.
> This is very fragile. Could you serialize legion_brightness_{set,get}()
> and legion_raw_event() with kbd->lock, rather than deferring the
> serialization to legion_raw_command()? Note that in this manner you'll
> need to add a lockdep assertion to the latter.
Done as in your reply to Marco: set and get hold the mutex for the whole
exchange, legion_raw_command() asserts it, and the level is an atomic_t
that raw_event changes with xchg() and notifies only if it differed. Set
swaps in the new level before sending and on error puts the old one back
with cmpxchg(&level, new, old), i.e. the arguments the other way round
from your sketch, so that a hotkey report that came in meanwhile is kept.
Get no longer touches the level, so probe reads it once before
registering the LED. That also covers the race Sashiko reported.
Thanks,
Ciro