Re: [PATCH] cyclictest: Simplify auxiliary clock parsing
Thomas Weißschuh <[email protected]> Thu, 16 Apr 2026 14:28:17 +0200
| Newsgroups | org.kernel.vger.linux-rt-users |
|---|---|
| Message-ID | <20260416142521-9f639d90-a475-43ad-b160-24b344465d2c@linutronix.de> |
On Wed, Apr 15, 2026 at 11:42:49AM -0400, John Kacur wrote: > Replace eight individual strcmp() calls for aux0-aux7 with a single > pattern-matching implementation that extracts and validates the digit. > > Assisted-by: Claude Sonnet 4.5 <[email protected]> > Signed-off-by: John Kacur <[email protected]> > --- > src/cyclictest/cyclictest.c | 24 +++++++----------------- > 1 file changed, 7 insertions(+), 17 deletions(-) > > diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c > index afc3a8c452da..71cf5cb25c22 100644 > --- a/src/cyclictest/cyclictest.c > +++ b/src/cyclictest/cyclictest.c > @@ -1054,23 +1054,13 @@ static int handleclock(const char *clockarg) > used_clock = CLOCK_REALTIME; > else if (strcmp(clockarg, "realtime") == 0) > used_clock = CLOCK_REALTIME; > - else if (strcmp(clockarg, "aux0") == 0) > - used_clock = CLOCK_AUX + 0; > - else if (strcmp(clockarg, "aux1") == 0) > - used_clock = CLOCK_AUX + 1; > - else if (strcmp(clockarg, "aux2") == 0) > - used_clock = CLOCK_AUX + 2; > - else if (strcmp(clockarg, "aux3") == 0) > - used_clock = CLOCK_AUX + 3; > - else if (strcmp(clockarg, "aux4") == 0) > - used_clock = CLOCK_AUX + 4; > - else if (strcmp(clockarg, "aux5") == 0) > - used_clock = CLOCK_AUX + 5; > - else if (strcmp(clockarg, "aux6") == 0) > - used_clock = CLOCK_AUX + 6; > - else if (strcmp(clockarg, "aux7") == 0) > - used_clock = CLOCK_AUX + 7; > - else > + else if (strncmp(clockarg, "aux", 3) == 0 && strlen(clockarg) == 4) { > + int aux_num = clockarg[3] - '0'; > + if (aux_num >= 0 && aux_num <= 7) > + used_clock = CLOCK_AUX + aux_num; > + else > + return 1; > + } else That works, too. Reviewed-by: Thomas WeiÃschuh <[email protected]> Though if it gets cleaned up, it might as well handle potentially larger values of MAX_AUX_CLOCKS. > return 1; > > return 0; > -- > 2.53.0 >