[sys] cpu: handle vendor suffixes in parseRelease

4 views
Skip to first unread message

安龙 (Gerrit)

unread,
Jun 24, 2026, 10:14:16 AM (3 days ago) Jun 24
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

安龙 has uploaded the change for review

Commit message

cpu: handle vendor suffixes in parseRelease

Kernel release strings such as "3.4.35_hi3535" on some Synology devices
failed to parse because only dash and plus suffixes were stripped.
Parse the leading digits of each component instead, mirroring the Go
runtime fix.

Fixes golang/go#80094
Change-Id: I41f8fd0a1d6c012eebd5368e623b42e99220d1a3

Change diff

diff --git a/cpu/parse.go b/cpu/parse.go
index 56a7e1a..481b142 100644
--- a/cpu/parse.go
+++ b/cpu/parse.go
@@ -6,38 +6,50 @@

import "strconv"

-// parseRelease parses a dot-separated version number. It follows the semver
-// syntax, but allows the minor and patch versions to be elided.
+// parseRelease parses a dot-separated version number from the prefix
+// of rel. It returns ok=true only if at least the major and minor
+// components were successfully parsed; the patch component is
+// best-effort. Trailing vendor or build suffixes such as
+// "-generic", "+", "_hi3535", or "-rc1" are ignored.
//
// This is a copy of the Go runtime's parseRelease from
-// https://golang.org/cl/209597.
+// https://golang.org/cl/209597, updated for golang/go#79612.
func parseRelease(rel string) (major, minor, patch int, ok bool) {
- // Strip anything after a dash or plus.
- for i := range len(rel) {
- if rel[i] == '-' || rel[i] == '+' {
- rel = rel[:i]
- break
+ // next consumes a run of decimal digits from the front of rel,
+ // returning the parsed value. If the digits are followed by a
+ // '.', it is consumed and more is set so the caller knows to
+ // parse another component; otherwise scanning terminates and
+ // the rest of rel is discarded.
+ next := func() (n int, more, ok bool) {
+ i := 0
+ for i < len(rel) && rel[i] >= '0' && rel[i] <= '9' {
+ i++
}
+ if i == 0 {
+ return 0, false, false
+ }
+ n, err := strconv.Atoi(rel[:i])
+ if err != nil {
+ return 0, false, false
+ }
+ if i < len(rel) && rel[i] == '.' {
+ rel = rel[i+1:]
+ return n, true, true
+ }
+ rel = ""
+ return n, false, true
}

- next := func() (int, bool) {
- for i := range len(rel) {
- if rel[i] == '.' {
- ver, err := strconv.Atoi(rel[:i])
- rel = rel[i+1:]
- return ver, err == nil
- }
- }
- ver, err := strconv.Atoi(rel)
- rel = ""
- return ver, err == nil
+ var more bool
+ if major, more, ok = next(); !ok || !more {
+ return 0, 0, 0, false
}
- if major, ok = next(); !ok || rel == "" {
- return
+ if minor, more, ok = next(); !ok {
+ return 0, 0, 0, false
}
- if minor, ok = next(); !ok || rel == "" {
- return
+ if !more {
+ return major, minor, 0, true
}
- patch, ok = next()
- return
+ patch, _, _ = next()
+ return major, minor, patch, true
}
diff --git a/cpu/parse_test.go b/cpu/parse_test.go
index 5a35881..e12017a 100644
--- a/cpu/parse_test.go
+++ b/cpu/parse_test.go
@@ -14,12 +14,21 @@
var parseReleaseTests = []parseReleaseTest{
{"", -1, -1, -1},
{"x", -1, -1, -1},
- {"5", 5, 0, 0},
+ // A single component is not enough; major+minor are required.
+ {"5", -1, -1, -1},
+ {"5-x", -1, -1, -1},
{"5.12", 5, 12, 0},
{"5.12-x", 5, 12, 0},
{"5.12.1", 5, 12, 1},
{"5.12.1-x", 5, 12, 1},
{"5.12.1.0", 5, 12, 1},
+ {"5.15.0-91-generic", 5, 15, 0},
+ {"4.19.0+", 4, 19, 0},
+ {"6.6.0-rc1", 6, 6, 0},
+ // Synology embedded Linux appends a platform identifier after an
+ // underscore. See golang/go#79612.
+ {"3.4.35_hi3535", 3, 4, 35},
+ {"2.6.32_synology", 2, 6, 32},
{"5.20496382327982653440", -1, -1, -1},
}

Change information

Files:
  • M cpu/parse.go
  • M cpu/parse_test.go
Change size: M
Delta: 2 files changed, 47 insertions(+), 26 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: sys
Gerrit-Branch: master
Gerrit-Change-Id: I41f8fd0a1d6c012eebd5368e623b42e99220d1a3
Gerrit-Change-Number: 793760
Gerrit-PatchSet: 1
Gerrit-Owner: 安龙 <aisk...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

安龙 (Gerrit)

unread,
Jun 24, 2026, 10:28:06 AM (3 days ago) Jun 24
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

安龙 uploaded new patchset

安龙 uploaded patch set #2 to this change.
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: sys
Gerrit-Branch: master
Gerrit-Change-Id: I41f8fd0a1d6c012eebd5368e623b42e99220d1a3
Gerrit-Change-Number: 793760
Gerrit-PatchSet: 2
Gerrit-Owner: 安龙 <aisk...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Jorropo (Gerrit)

unread,
Jun 26, 2026, 3:05:26 AM (yesterday) Jun 26
to 安龙, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from 安龙

Jorropo voted and added 2 comments

Votes added by Jorropo

Code-Review+2
Commit-Queue+1

2 comments

Patchset-level comments
Commit Message
Line 15, Patchset 2 (Latest):
Jorropo . unresolved

Please add a `Co-Authored-By`, also in the description explain which CL you are copying the implementation from.

Open in Gerrit

Related details

Attention is currently required from:
  • 安龙
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sys
Gerrit-Branch: master
Gerrit-Change-Id: I41f8fd0a1d6c012eebd5368e623b42e99220d1a3
Gerrit-Change-Number: 793760
Gerrit-PatchSet: 2
Gerrit-Owner: 安龙 <aisk...@gmail.com>
Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
Gerrit-Attention: 安龙 <aisk...@gmail.com>
Gerrit-Comment-Date: Fri, 26 Jun 2026 07:05:18 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

安龙 (Gerrit)

unread,
Jun 26, 2026, 10:46:05 AM (20 hours ago) Jun 26
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from 安龙

安龙 uploaded new patchset

安龙 uploaded patch set #3 to this change.
Open in Gerrit

Related details

Attention is currently required from:
  • 安龙
Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newpatchset
    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I41f8fd0a1d6c012eebd5368e623b42e99220d1a3
    Gerrit-Change-Number: 793760
    Gerrit-PatchSet: 3
    Gerrit-Owner: 安龙 <aisk...@gmail.com>
    Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    安龙 (Gerrit)

    unread,
    Jun 26, 2026, 10:46:26 AM (20 hours ago) Jun 26
    to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Jorropo, golang-co...@googlegroups.com

    安龙 added 1 comment

    Commit Message
    Line 15, Patchset 2:
    Jorropo . resolved

    Please add a `Co-Authored-By`, also in the description explain which CL you are copying the implementation from.

    安龙

    Done

    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I41f8fd0a1d6c012eebd5368e623b42e99220d1a3
    Gerrit-Change-Number: 793760
    Gerrit-PatchSet: 3
    Gerrit-Owner: 安龙 <aisk...@gmail.com>
    Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
    Gerrit-Comment-Date: Fri, 26 Jun 2026 14:46:19 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Jorropo <jorro...@gmail.com>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Dmitri Shuralyov (Gerrit)

    unread,
    Jun 26, 2026, 8:02:46 PM (11 hours ago) Jun 26
    to 安龙, goph...@pubsubhelper.golang.org, Dmitri Shuralyov, golang...@luci-project-accounts.iam.gserviceaccount.com, Jorropo, golang-co...@googlegroups.com
    Attention needed from 安龙

    Dmitri Shuralyov voted and added 1 comment

    Votes added by Dmitri Shuralyov

    Code-Review+1

    1 comment

    Commit Message
    Line 19, Patchset 3 (Latest):Co-authored-by: Brad Fitzpatrick <brad...@golang.org
    Dmitri Shuralyov . unresolved

    ```suggestion
    Co-authored-by: Brad Fitzpatrick <brad...@golang.org>
    ```

    Open in Gerrit

    Related details

    Attention is currently required from:
    • 安龙
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I41f8fd0a1d6c012eebd5368e623b42e99220d1a3
    Gerrit-Change-Number: 793760
    Gerrit-PatchSet: 3
    Gerrit-Owner: 安龙 <aisk...@gmail.com>
    Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
    Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-Attention: 安龙 <aisk...@gmail.com>
    Gerrit-Comment-Date: Sat, 27 Jun 2026 00:02:42 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages