Skip to content

Harden LED configuration and color packing#94

Open
mjc wants to merge 2 commits into
lukash:mainfrom
mjc:refloat-fix-led-driver-encoding
Open

Harden LED configuration and color packing#94
mjc wants to merge 2 commits into
lukash:mainfrom
mjc:refloat-fix-led-driver-encoding

Conversation

@mjc

@mjc mjc commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Validate LED strip color order before allocating DMA storage and report which strip is invalid.

The paint path also rejects unexpected encodings, and channel values are widened before bit packing. Valid GRB, GRBW, RGB, and WRGB output is unchanged.

Copilot AI review requested due to automatic review settings July 15, 2026 17:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the LED driver’s handling of LED strip color order/encoding by validating configuration earlier and making color packing/shifting behavior well-defined for 32-bit output values.

Changes:

  • Reject invalid LedColorOrder values during led_driver_setup() before calculating/allocating the DMA bitbuffer, with an error that identifies the offending strip index.
  • Make color channel bit packing explicitly use uint32_t widening before shifts to avoid undefined behavior on 32-bit targets.
  • Reject unexpected color_order encodings in the paint path (added a default case in the switch).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/led_driver.c Outdated
Comment thread src/led_driver.c Outdated
Comment thread src/led_driver.c Outdated
@mjc
mjc force-pushed the refloat-fix-led-driver-encoding branch 2 times, most recently from 8ae1c33 to 00062b3 Compare July 24, 2026 16:32
Comment thread src/leds.c
if (!leds->rear_strip.color_conv) {
log_error("Invalid rear LED color order: %u.", hw_cfg->rear.color_order);
return;
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplication is not good. It's about architecturally putting the code to the correct place. Looks like the whole color_order handling could be moved into the led_strip module, storing the bit number and the converter in the LedStrip struct. They are not really LedStrip related by nature, they should probably technically go into their own module (e.g. led_color_order.{c,h} or just make a directory for the led code at this stage). But I'd accept it if the functions were cleanly placed into led_strip.c too. More structural work and I don't really wanna spend the time iterating on this (so to be blunt if you can do it right please do, if not, let's not spend the time 😅 ).

A straightforward fix of the uninitialized pointer dereference would be to initialize it and early-return if it's NULL.

@mjc
mjc force-pushed the refloat-fix-led-driver-encoding branch from 00062b3 to 8dd3311 Compare July 25, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants