Date: Tue, 2 Sep 2025 09:41:35 -0600 From: Warner Losh <imp@bsdimp.com> To: Zhenlei Huang <zlei@freebsd.org> Cc: Warner Losh <imp@freebsd.org>, "src-committers@freebsd.org" <src-committers@freebsd.org>, "dev-commits-src-all@freebsd.org" <dev-commits-src-all@freebsd.org>, "dev-commits-src-main@freebsd.org" <dev-commits-src-main@freebsd.org> Subject: Re: git: dfafdbdfc3e9 - main - stand: Use calloc instead of malloc for initialization of filesystem devsw Message-ID: <CANCZdfr4oPQNEnLHFnv8HP5XE36dYtrvxbRqZvLuZP92Q1iw5g@mail.gmail.com> In-Reply-To: <B0F452F3-34D5-4F20-9009-69DA2C25F9D3@FreeBSD.org> References: <202509012201.581M18tv010659@gitrepo.freebsd.org> <B0F452F3-34D5-4F20-9009-69DA2C25F9D3@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--00000000000065f309063dd3535f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Sep 2, 2025 at 12:38=E2=80=AFAM Zhenlei Huang <zlei@freebsd.org> wr= ote: > > > > On Sep 2, 2025, at 6:01 AM, Warner Losh <imp@freebsd.org> wrote: > > > > The branch main has been updated by imp: > > > > URL: > https://cgit.FreeBSD.org/src/commit/?id=3Ddfafdbdfc3e9db8b878283bcbef35f5= d8d37dae8 > > > > commit dfafdbdfc3e9db8b878283bcbef35f5d8d37dae8 > > Author: null <null> > > Hi Warner, > > The Author is missing. Probably by mistake of Phabricator ? > Doh! Yes. I've reverted. I'll redo. The args are backwards. It's part of another change I was going to look into next... Warner > Best regards, > Zhenlei > > > AuthorDate: 2025-09-01 21:57:06 +0000 > > Commit: Warner Losh <imp@FreeBSD.org> > > CommitDate: 2025-09-01 21:57:14 +0000 > > > > stand: Use calloc instead of malloc for initialization of filesystem > devsw > > > > This change is required for https://reviews.freebsd.org/D49355, so > that > > we can check if d_dev is uninitialized by checking if it's NULL. > > > > Reviewed by: imp > > Differential Revision: https://reviews.freebsd.org/D49705 > > --- > > stand/common/disk.c | 2 +- > > stand/kboot/kboot/hostdisk.c | 2 +- > > stand/libofw/devicename.c | 2 +- > > stand/libsa/dev.c | 2 +- > > stand/libsa/zfs/zfs.c | 2 +- > > stand/uboot/devicename.c | 2 +- > > 6 files changed, 6 insertions(+), 6 deletions(-) > > > > diff --git a/stand/common/disk.c b/stand/common/disk.c > > index c1650f0fa1ec..1baf91efaa49 100644 > > --- a/stand/common/disk.c > > +++ b/stand/common/disk.c > > @@ -468,7 +468,7 @@ disk_parsedev(struct devdesc **idev, const char > *devspec, const char **path) > > > > if (*cp !=3D '\0' && *cp !=3D ':') > > return (EINVAL); > > - dev =3D malloc(sizeof(*dev)); > > + dev =3D calloc(sizeof(*dev), 1); > > if (dev =3D=3D NULL) > > return (ENOMEM); > > dev->dd.d_unit =3D unit; > > diff --git a/stand/kboot/kboot/hostdisk.c b/stand/kboot/kboot/hostdisk.= c > > index a9117d4c1c9d..fc98bf534519 100644 > > --- a/stand/kboot/kboot/hostdisk.c > > +++ b/stand/kboot/kboot/hostdisk.c > > @@ -465,7 +465,7 @@ hostdisk_parsedev(struct devdesc **idev, const char > *devspec, const char **path) > > return (EINVAL); > > } > > free(fn); > > - dev =3D malloc(sizeof(*dev)); > > + dev =3D calloc(sizeof(*dev), 1); > > if (dev =3D=3D NULL) > > return (ENOMEM); > > dev->d_unit =3D 0; > > diff --git a/stand/libofw/devicename.c b/stand/libofw/devicename.c > > index f6419632c6bc..46a9717fdda5 100644 > > --- a/stand/libofw/devicename.c > > +++ b/stand/libofw/devicename.c > > @@ -98,7 +98,7 @@ ofw_common_parsedev(struct devdesc **dev, const char > *devspec, const char **path > > > > if (ofw_path_to_handle(devspec, ofwtype, &rem_path) =3D=3D -1) > > return (ENOENT); > > - idev =3D malloc(sizeof(struct ofw_devdesc)); > > + idev =3D calloc(sizeof(struct ofw_devdesc), 1); > > if (idev =3D=3D NULL) { > > printf("ofw_parsedev: malloc failed\n"); > > return (ENOMEM); > > diff --git a/stand/libsa/dev.c b/stand/libsa/dev.c > > index 1edc843d508c..4f6932e96c48 100644 > > --- a/stand/libsa/dev.c > > +++ b/stand/libsa/dev.c > > @@ -72,7 +72,7 @@ default_parsedev(struct devdesc **dev, const char > *devspec, > > int unit, err; > > char *cp; > > > > - idev =3D malloc(sizeof(struct devdesc)); > > + idev =3D calloc(sizeof(struct devdesc), 1); > > if (idev =3D=3D NULL) > > return (ENOMEM); > > > > diff --git a/stand/libsa/zfs/zfs.c b/stand/libsa/zfs/zfs.c > > index 70a102f6425d..2f7c1caaa4b5 100644 > > --- a/stand/libsa/zfs/zfs.c > > +++ b/stand/libsa/zfs/zfs.c > > @@ -1643,7 +1643,7 @@ zfs_parsedev(struct devdesc **idev, const char > *devspec, const char **path) > > spa =3D spa_find_by_name(poolname); > > if (!spa) > > return (ENXIO); > > - dev =3D malloc(sizeof(*dev)); > > + dev =3D calloc(sizeof(*dev), 1); > > if (dev =3D=3D NULL) > > return (ENOMEM); > > dev->pool_guid =3D spa->spa_guid; > > diff --git a/stand/uboot/devicename.c b/stand/uboot/devicename.c > > index 4ee9c7fd72c4..23670d7593a2 100644 > > --- a/stand/uboot/devicename.c > > +++ b/stand/uboot/devicename.c > > @@ -102,7 +102,7 @@ uboot_parsedev(struct uboot_devdesc **dev, const > char *devspec, > > } > > if (dv =3D=3D NULL) > > return(ENOENT); > > - idev =3D malloc(sizeof(struct uboot_devdesc)); > > + idev =3D calloc(sizeof(struct uboot_devdesc), 1); > > err =3D 0; > > np =3D (devspec + strlen(dv->dv_name)); > > > > > > --00000000000065f309063dd3535f 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 g= mail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Tue, Sep 2, = 2025 at 12:38=E2=80=AFAM Zhenlei Huang <<a href=3D"mailto:zlei@freebsd.o= rg">zlei@freebsd.org</a>> wrote:<br></div><blockquote class=3D"gmail_quo= te" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204= );padding-left:1ex"><br> <br> > On Sep 2, 2025, at 6:01 AM, Warner Losh <<a href=3D"mailto:imp@free= bsd.org" target=3D"_blank">imp@freebsd.org</a>> wrote:<br> > <br> > The branch main has been updated by imp:<br> > <br> > URL: <a href=3D"https://cgit.FreeBSD.org/src/commit/?id=3Ddfafdbdfc3e9= db8b878283bcbef35f5d8d37dae8" rel=3D"noreferrer" target=3D"_blank">https://= cgit.FreeBSD.org/src/commit/?id=3Ddfafdbdfc3e9db8b878283bcbef35f5d8d37dae8<= /a><br> > <br> > commit dfafdbdfc3e9db8b878283bcbef35f5d8d37dae8<br> > Author:=C2=A0 =C2=A0 =C2=A0null <null> <br> <br> Hi Warner,<br> <br> The Author is missing. Probably by mistake of Phabricator ?<br></blockquote= ><div><br></div><div>Doh! Yes. I've reverted. I'll redo. The args a= re backwards. It's part of another change I was going to look into next= ...</div><div><br></div><div>Warner</div><div><br></div><div>=C2=A0</div><b= lockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-le= ft:1px solid rgb(204,204,204);padding-left:1ex">Best regards,<br> Zhenlei<br> <br> > AuthorDate: 2025-09-01 21:57:06 +0000<br> > Commit:=C2=A0 =C2=A0 =C2=A0Warner Losh <imp@FreeBSD.org><br> > CommitDate: 2025-09-01 21:57:14 +0000<br> > <br> >=C2=A0 =C2=A0 stand: Use calloc instead of malloc for initialization of= filesystem devsw<br> > <br> >=C2=A0 =C2=A0 This change is required for <a href=3D"https://reviews.fr= eebsd.org/D49355" rel=3D"noreferrer" target=3D"_blank">https://reviews.free= bsd.org/D49355</a>, so that<br> >=C2=A0 =C2=A0 we can check if d_dev is uninitialized by checking if it&= #39;s NULL.<br> > <br> >=C2=A0 =C2=A0 Reviewed by:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 imp= <br> >=C2=A0 =C2=A0 Differential Revision:=C2=A0 <a href=3D"https://reviews.f= reebsd.org/D49705" rel=3D"noreferrer" target=3D"_blank">https://reviews.fre= ebsd.org/D49705</a><br> > ---<br> > stand/common/disk.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | 2 +-<br> > stand/kboot/kboot/hostdisk.c | 2 +-<br> > stand/libofw/devicename.c=C2=A0 =C2=A0 | 2 +-<br> > stand/libsa/dev.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | 2 +-<br> > stand/libsa/zfs/zfs.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 | 2 +-<br> > stand/uboot/devicename.c=C2=A0 =C2=A0 =C2=A0| 2 +-<br> > 6 files changed, 6 insertions(+), 6 deletions(-)<br> > <br> > diff --git a/stand/common/disk.c b/stand/common/disk.c<br> > index c1650f0fa1ec..1baf91efaa49 100644<br> > --- a/stand/common/disk.c<br> > +++ b/stand/common/disk.c<br> > @@ -468,7 +468,7 @@ disk_parsedev(struct devdesc **idev, const char *d= evspec, const char **path)<br> > <br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0if (*cp !=3D '\0' && *cp != =3D ':')<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (EINVAL);= <br> > -=C2=A0 =C2=A0 =C2=A0dev =3D malloc(sizeof(*dev));<br> > +=C2=A0 =C2=A0 =C2=A0dev =3D calloc(sizeof(*dev), 1);<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0if (dev =3D=3D NULL)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (ENOMEM);= <br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0dev->dd.d_unit =3D unit;<br> > diff --git a/stand/kboot/kboot/hostdisk.c b/stand/kboot/kboot/hostdisk= .c<br> > index a9117d4c1c9d..fc98bf534519 100644<br> > --- a/stand/kboot/kboot/hostdisk.c<br> > +++ b/stand/kboot/kboot/hostdisk.c<br> > @@ -465,7 +465,7 @@ hostdisk_parsedev(struct devdesc **idev, const cha= r *devspec, const char **path)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (EINVAL);= <br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0}<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0free(fn);<br> > -=C2=A0 =C2=A0 =C2=A0dev =3D malloc(sizeof(*dev));<br> > +=C2=A0 =C2=A0 =C2=A0dev =3D calloc(sizeof(*dev), 1);<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0if (dev =3D=3D NULL)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (ENOMEM);= <br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0dev->d_unit =3D 0;<br> > diff --git a/stand/libofw/devicename.c b/stand/libofw/devicename.c<br> > index f6419632c6bc..46a9717fdda5 100644<br> > --- a/stand/libofw/devicename.c<br> > +++ b/stand/libofw/devicename.c<br> > @@ -98,7 +98,7 @@ ofw_common_parsedev(struct devdesc **dev, const char= *devspec, const char **path<br> > <br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0if (ofw_path_to_handle(devspec, ofwtype, &am= p;rem_path) =3D=3D -1)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (ENOENT);= <br> > -=C2=A0 =C2=A0 =C2=A0idev =3D malloc(sizeof(struct ofw_devdesc));<br> > +=C2=A0 =C2=A0 =C2=A0idev =3D calloc(sizeof(struct ofw_devdesc), 1);<b= r> >=C2=A0 =C2=A0 =C2=A0 =C2=A0if (idev =3D=3D NULL) {<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0printf("ofw= _parsedev: malloc failed\n");<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (ENOMEM);= <br> > diff --git a/stand/libsa/dev.c b/stand/libsa/dev.c<br> > index 1edc843d508c..4f6932e96c48 100644<br> > --- a/stand/libsa/dev.c<br> > +++ b/stand/libsa/dev.c<br> > @@ -72,7 +72,7 @@ default_parsedev(struct devdesc **dev, const char *d= evspec,<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0int unit, err;<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0char *cp;<br> > <br> > -=C2=A0 =C2=A0 =C2=A0idev =3D malloc(sizeof(struct devdesc));<br> > +=C2=A0 =C2=A0 =C2=A0idev =3D calloc(sizeof(struct devdesc), 1);<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0if (idev =3D=3D NULL)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (ENOMEM);= <br> > <br> > diff --git a/stand/libsa/zfs/zfs.c b/stand/libsa/zfs/zfs.c<br> > index 70a102f6425d..2f7c1caaa4b5 100644<br> > --- a/stand/libsa/zfs/zfs.c<br> > +++ b/stand/libsa/zfs/zfs.c<br> > @@ -1643,7 +1643,7 @@ zfs_parsedev(struct devdesc **idev, const char *= devspec, const char **path)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0spa =3D spa_find_by_name(poolname);<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!spa)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (ENXIO);<= br> > -=C2=A0 =C2=A0 =C2=A0dev =3D malloc(sizeof(*dev));<br> > +=C2=A0 =C2=A0 =C2=A0dev =3D calloc(sizeof(*dev), 1);<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0if (dev =3D=3D NULL)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (ENOMEM);= <br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0dev->pool_guid =3D spa->spa_guid;<br> > diff --git a/stand/uboot/devicename.c b/stand/uboot/devicename.c<br> > index 4ee9c7fd72c4..23670d7593a2 100644<br> > --- a/stand/uboot/devicename.c<br> > +++ b/stand/uboot/devicename.c<br> > @@ -102,7 +102,7 @@ uboot_parsedev(struct uboot_devdesc **dev, const c= har *devspec,<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0}<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0if (dv =3D=3D NULL)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return(ENOENT);<= br> > -=C2=A0 =C2=A0 =C2=A0idev =3D malloc(sizeof(struct uboot_devdesc));<br= > > +=C2=A0 =C2=A0 =C2=A0idev =3D calloc(sizeof(struct uboot_devdesc), 1);= <br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0err =3D 0;<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0np =3D (devspec + strlen(dv->dv_name));<b= r> > <br> <br> <br> <br> </blockquote></div></div> --00000000000065f309063dd3535f--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfr4oPQNEnLHFnv8HP5XE36dYtrvxbRqZvLuZP92Q1iw5g>