Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Jan 2021 19:56:17 +0100
From:      Hans Petter Selasky <hps@selasky.org>
To:        Ian Lepore <ian@freebsd.org>, Jakob Alvermark <jakob@alvermark.net>, FreeBSD Current <freebsd-current@freebsd.org>
Subject:   Re: Panic after updating
Message-ID:  <63efc8ee-cd5b-bf99-bcdd-a49a62c48a63@selasky.org>
In-Reply-To: <7fee78a371dad15e1a7b66eecfa5190e510d930f.camel@freebsd.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>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?63efc8ee-cd5b-bf99-bcdd-a49a62c48a63>