Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 Dec 2022 09:06:41 -0700
From:      Warner Losh <imp@bsdimp.com>
To:        Hans Petter Selasky <hps@selasky.org>
Cc:        Warner Losh <imp@freebsd.org>, src-committers@freebsd.org,  dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org
Subject:   Re: git: da5d0a1dbc28 - main - kboot: Use unsigned long long.
Message-ID:  <CANCZdfqi5rF1BVjvZ1mMS0=Zd3iTbgx5NUKVC8DA-LRvqmPh-Q@mail.gmail.com>
In-Reply-To: <39c15d70-4895-3b3b-cbbd-d0d7eaec0fdb@selasky.org>
References:  <202212021949.2B2JnpxT077008@gitrepo.freebsd.org> <39c15d70-4895-3b3b-cbbd-d0d7eaec0fdb@selasky.org>

next in thread | previous in thread | raw e-mail | index | archive | help
--0000000000007a0bb705eeeea4dc
Content-Type: text/plain; charset="UTF-8"

On Sat, Dec 3, 2022 at 5:31 AM Hans Petter Selasky <hps@selasky.org> wrote:

> On 12/2/22 20:49, Warner Losh wrote:
> > The branch main has been updated by imp:
> >
> > URL:
> https://cgit.FreeBSD.org/src/commit/?id=da5d0a1dbc2838eae7033254705c684d7a013fce
> >
> > commit da5d0a1dbc2838eae7033254705c684d7a013fce
> > Author:     Warner Losh <imp@FreeBSD.org>
> > AuthorDate: 2022-12-02 19:41:01 +0000
> > Commit:     Warner Losh <imp@FreeBSD.org>
> > CommitDate: 2022-12-02 19:41:01 +0000
> >
> >      kboot: Use unsigned long long.
> >
> >      For the 64-bit platforms, this is a nop. Currently kboot only
> supports
> >      64-bit platforms, though. If we support 32-bit in the future, this
> will
> >      become important.
> >
> >      Noticed by:             rpokala
> >      Sponsored by:           Netflix
> > ---
> >   stand/kboot/util.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/stand/kboot/util.c b/stand/kboot/util.c
> > index 938aad599e19..7d467a29b059 100644
> > --- a/stand/kboot/util.c
> > +++ b/stand/kboot/util.c
> > @@ -35,7 +35,7 @@ file2str(const char *fn, char *buffer, size_t buflen)
> >   bool
> >   file2u64(const char *fn, uint64_t *val)
> >   {
> > -     unsigned long v;
> > +     unsigned long long v;
> >       char buffer[80];
> >
> >       if (!file2str(fn, buffer, sizeof(buffer)))
>
> Why not include stdint.h and use uint64_t ?
>
> Instead of building on the good old assumptions, int is 32-bit and long
> long is 64-bit? It is interesting to observe the sizes of these types in
> 8-bit compilers :-) Not that it makes a big difference for us. Maybe
> _Static_assert(sizeof(long long) == 8, "Please fix this code");
>

The code was wrong because I called strtoull and assigned it to an unsigned
long,
not an unsigned long long. On 64-bit platforms, long and long long are the
same.
Long long being > 8 bytes is fine for this interface: it only returns 64
bits. And
we assume this all over the place.

Warner

--0000000000007a0bb705eeeea4dc
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">On Sat, Dec 3, 2022 at 5:31 AM Hans P=
etter Selasky &lt;<a href=3D"mailto:hps@selasky.org">hps@selasky.org</a>&gt=
; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px=
 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 12/2=
/22 20:49, Warner Losh wrote:<br>
&gt; The branch main has been updated by imp:<br>
&gt; <br>
&gt; URL: <a href=3D"https://cgit.FreeBSD.org/src/commit/?id=3Dda5d0a1dbc28=
38eae7033254705c684d7a013fce" rel=3D"noreferrer" target=3D"_blank">https://=
cgit.FreeBSD.org/src/commit/?id=3Dda5d0a1dbc2838eae7033254705c684d7a013fce<=
/a><br>
&gt; <br>
&gt; commit da5d0a1dbc2838eae7033254705c684d7a013fce<br>
&gt; Author:=C2=A0 =C2=A0 =C2=A0Warner Losh &lt;imp@FreeBSD.org&gt;<br>
&gt; AuthorDate: 2022-12-02 19:41:01 +0000<br>
&gt; Commit:=C2=A0 =C2=A0 =C2=A0Warner Losh &lt;imp@FreeBSD.org&gt;<br>
&gt; CommitDate: 2022-12-02 19:41:01 +0000<br>
&gt; <br>
&gt;=C2=A0 =C2=A0 =C2=A0 kboot: Use unsigned long long.<br>
&gt;=C2=A0 =C2=A0 =C2=A0 <br>
&gt;=C2=A0 =C2=A0 =C2=A0 For the 64-bit platforms, this is a nop. Currently=
 kboot only supports<br>
&gt;=C2=A0 =C2=A0 =C2=A0 64-bit platforms, though. If we support 32-bit in =
the future, this will<br>
&gt;=C2=A0 =C2=A0 =C2=A0 become important.<br>
&gt;=C2=A0 =C2=A0 =C2=A0 <br>
&gt;=C2=A0 =C2=A0 =C2=A0 Noticed by:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0rpokala<br>
&gt;=C2=A0 =C2=A0 =C2=A0 Sponsored by:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0Netflix<br>
&gt; ---<br>
&gt;=C2=A0 =C2=A0stand/kboot/util.c | 2 +-<br>
&gt;=C2=A0 =C2=A01 file changed, 1 insertion(+), 1 deletion(-)<br>
&gt; <br>
&gt; diff --git a/stand/kboot/util.c b/stand/kboot/util.c<br>
&gt; index 938aad599e19..7d467a29b059 100644<br>
&gt; --- a/stand/kboot/util.c<br>
&gt; +++ b/stand/kboot/util.c<br>
&gt; @@ -35,7 +35,7 @@ file2str(const char *fn, char *buffer, size_t buflen=
)<br>
&gt;=C2=A0 =C2=A0bool<br>
&gt;=C2=A0 =C2=A0file2u64(const char *fn, uint64_t *val)<br>
&gt;=C2=A0 =C2=A0{<br>
&gt; -=C2=A0 =C2=A0 =C2=A0unsigned long v;<br>
&gt; +=C2=A0 =C2=A0 =C2=A0unsigned long long v;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0char buffer[80];<br>
&gt;=C2=A0 =C2=A0<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!file2str(fn, buffer, sizeof(buffer)))<b=
r>
<br>
Why not include stdint.h and use uint64_t ?<br>
<br>
Instead of building on the good old assumptions, int is 32-bit and long <br=
>
long is 64-bit? It is interesting to observe the sizes of these types in <b=
r>
8-bit compilers :-) Not that it makes a big difference for us. Maybe <br>
_Static_assert(sizeof(long long) =3D=3D 8, &quot;Please fix this code&quot;=
);<br></blockquote><div><br></div><div>The code was wrong because I called =
strtoull and assigned it to an unsigned long,</div><div>not an unsigned lon=
g long. On 64-bit platforms, long and long long are the same.</div><div>Lon=
g long being &gt; 8 bytes is fine for this interface: it only returns 64 bi=
ts. And</div><div>we assume this all over the place.</div><div><br></div><d=
iv>Warner</div></div></div>

--0000000000007a0bb705eeeea4dc--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfqi5rF1BVjvZ1mMS0=Zd3iTbgx5NUKVC8DA-LRvqmPh-Q>