Re: Off-by-one in arch/mips/bcm47xx/time.c (was: [PATCH v6 02/19] string: Add strprefix())

From: David Laight

Date: Mon Nov 16 2026 - 06:53:19 EST


On Mon, 16 Nov 2026 13:00:57 +0200
Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:

> On Sat, Nov 14, 2026 at 08:49:21PM +0100, Alejandro Colomar wrote:
>
> [...]
>
> > > And these are all candidates for converted uses to
> > > whatever is the function name or steq:
> > >
> > > $ git grep -P '[^w]strncmp\s*\(\s*[\w\.\-\>\s]*,\s*\"\w*"\s*,\s*\d+\s*\)' -- '*.[ch]' | wc -l
> > > 946
> >
> > Looking at those, I've seen a bug in BCM47XX, introduced in 2224de9d152b
> > (2013-10-29; "MIPS: BCM47XX: Fix clock detection for BCM5354 with 200MHz
> > clock").
> >
> > Look at this line of code:
> >
> > $ grep strncmp arch/mips/bcm47xx/time.c
> > if (len >= 0 && !strncmp(buf, "200", 4))
> >
> > That strncmp(3) call is wrong, as it's really behaving as strcmp(3),
> > since the 4 is off-by-one. I'd like to know what was the intention.
> > Was it meant to be !strncmp(buf, "200", 3)? Or was it meant to be just
> > !strcmp(buf, "200")?
>
> When in doubts, preserve current behaviour over refactoring.
>

That entire function is strange...

David