Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Jan 2021 12:01:18 -0700
From:      Ian Lepore <ian@freebsd.org>
To:        Hans Petter Selasky <hps@selasky.org>, Jakob Alvermark <jakob@alvermark.net>, FreeBSD Current <freebsd-current@freebsd.org>
Subject:   Re: Panic after updating
Message-ID:  <a248b47f4fd34d52263fd1ef540a57d841263c35.camel@freebsd.org>
In-Reply-To: <63efc8ee-cd5b-bf99-bcdd-a49a62c48a63@selasky.org>
References:  <87512669-f0b9-eb2f-1103-170a29384ea8@alvermark.net> <ad969a6e-4029-b85c-f304-1198b05ad725@selasky.org> <34a9dafd-9690-1b33-abf8-017ad31cf2ab@alvermark.net> <e407413b-730a-d60d-f50d-0b6f490da74a@selasky.org> <60e4db60-c816-463e-0e08-a33c674ad4da@alvermark.net> <af76d2fc-cc6f-4ca4-c293-ae1ff8f2a51d@alvermark.net> <75784796-b513-5573-abc4-8c445d03c007@selasky.org> <cdc94c54-6f21-d452-87fd-9b0e5d7cbe95@alvermark.net> <5724744d-7710-4c3c-416b-01314cb196d4@selasky.org> <1bab5b76-eb56-671f-d52d-db1812c9be22@alvermark.net> <f3e0ceb9-07ea-0118-645b-47a93085883f@selasky.org> <e72200ec-3c33-0b8a-90fe-66a969eb8f4a@selasky.org> <7fee78a371dad15e1a7b66eecfa5190e510d930f.camel@freebsd.org> <63efc8ee-cd5b-bf99-bcdd-a49a62c48a63@selasky.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 2021-01-12 at 19:56 +0100, Hans Petter Selasky wrote:
> On 1/12/21 7:45 PM, Ian Lepore wrote:
> > > > -       for (int i = 0; i <= sc->sc_npins; i++) {
> > > > +       for (int i = 0; i != sc->sc_npins; i++) {
> > > >                  mtx_destroy(&sc->sc_pin_intr[i].mtx);
> > > >                  free(&sc->sc_pin_intr[i].pin, M_GPIOC);
> > > >          }
> > > 
> > > --HPS
> > > 
> > 
> > If that is the problem, I'd rather see it fixed by using the
> > idiomatic
> > i < sc->sc_npins rather than the non-standard != test.  (But I
> > don't
> > feel strongly enough about it to learn how to use git and commit
> > the
> > fix myself.)
> 
> Hi Ian,
> 
> I think it is more serious that the iteration variable is declared 
> inside the for-loop :-)
> 
> At least it is pretty obvious that the array written is one element
> too 
> small. I've always used != instead of <= in for-loops. But if there
> is a 
> certain style in there, I'm good with < too, though I've always seen
> < 
> as an overhead compared to != , because to implement < you need a 
> subtraction, while != is just a comparison ...
> 
> --HPS

I thought we recently changed (or at least discussed changing) style(9)
to allow for that sort of loop-iter-var declaration.

On most of the chips I know assembly language for (mostly risc chips),
there is no difference between a comparison and a subtraction at the
chip-instruction level.  That is, at the chip level, comparision
instructions are typically implemented as a subtraction that sets
condition code bits but doesn't store the result back to a register.

-- Ian





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a248b47f4fd34d52263fd1ef540a57d841263c35.camel>