Skip to content

Fix PWM10+ discovery and sort order in Common.php - #10

Open
mrjacobarussell wants to merge 1 commit into
andrebrait:mainfrom
mrjacobarussell:fix-pwm10-plus-glob-and-sort
Open

mrjacobarussell wants to merge 1 commit into
andrebrait:mainfrom
mrjacobarussell:fix-pwm10-plus-glob-and-sort

Conversation

@mrjacobarussell

Copy link
Copy Markdown

What's changed

Two bugs, both hit by any hwmon device with 10+ PWM channels (found via a real ARCTIC Fan Controller, which has 10 channels):

  1. glob("pwm[0-9]") and find -iname 'pwm[0-9]' only match a single digit, so pwm10 and above are silently dropped from both build_pwm_map() and list_pwm(). Fixed by globbing broadly (pwm*) and filtering with a strict ^pwm\d+$ regex — this also avoids accidentally matching auxiliary attributes like pwm1_enable or pwm1_auto_point1_pwm that a looser pwm[0-9]* pattern would pull in.
  2. list_pwm()'s usort() used strcmp(), which sorts alphabetically ("pwm10" < "pwm2" as strings) instead of numerically. Switched to strnatcmp().

Verification

Tested against a live 10-channel ARCTIC Fan Controller on Unraid. Before the fix, channel 10 was missing from the plugin UI entirely, and once naively patched to just match pwm10, it sorted between pwm1 and pwm2 (and a looser glob pattern pulled in every per-channel attribute, not just the base PWM control file). After this fix, all 10 channels appear, in correct numeric order, with nothing extraneous.

Upgrade compatibility

No config/migration impact — this only affects which hwmon files get discovered and how they're ordered for display.

Two bugs, both hit by any hwmon device with 10+ PWM channels
(e.g. ARCTIC Fan Controller, 10 channels):

1. glob("pwm[0-9]") and find -iname 'pwm[0-9]' match exactly one
   digit, so pwm10 (and above) are silently dropped from both
   build_pwm_map() and list_pwm(). Fixed by globbing broadly
   (pwm*) and filtering with a strict ^pwm\d+$ regex, which also
   avoids matching auxiliary attributes like pwm1_enable,
   pwm1_auto_point1_pwm, etc.

2. list_pwm()'s usort() used strcmp(), which sorts alphabetically
   ("pwm10" < "pwm2" as strings) rather than numerically. Fixed
   by switching to strnatcmp().

Verified against a live 10-channel ARCTIC Fan Controller on Unraid:
before the fix, channel 10 was missing from the plugin UI entirely
and pwm10 sorted between pwm1 and pwm2; after, all 10 channels
appear in correct numeric order.
@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: c4f24917-a410-4eeb-80a0-02a27628c41f


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant