Re: git: dfafdbdfc3e9 - main - stand: Use calloc instead of malloc for initialization of filesystem devsw
- Reply: Warner Losh : "Re: git: dfafdbdfc3e9 - main - stand: Use calloc instead of malloc for initialization of filesystem devsw"
- In reply to: Warner Losh : "git: dfafdbdfc3e9 - main - stand: Use calloc instead of malloc for initialization of filesystem devsw"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 02 Sep 2025 06:38:35 UTC
> 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=dfafdbdfc3e9db8b878283bcbef35f5d8d37dae8 > > commit dfafdbdfc3e9db8b878283bcbef35f5d8d37dae8 > Author: null <null> Hi Warner, The Author is missing. Probably by mistake of Phabricator ? 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 != '\0' && *cp != ':') > return (EINVAL); > - dev = malloc(sizeof(*dev)); > + dev = calloc(sizeof(*dev), 1); > if (dev == NULL) > return (ENOMEM); > dev->dd.d_unit = 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 = malloc(sizeof(*dev)); > + dev = calloc(sizeof(*dev), 1); > if (dev == NULL) > return (ENOMEM); > dev->d_unit = 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) == -1) > return (ENOENT); > - idev = malloc(sizeof(struct ofw_devdesc)); > + idev = calloc(sizeof(struct ofw_devdesc), 1); > if (idev == 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 = malloc(sizeof(struct devdesc)); > + idev = calloc(sizeof(struct devdesc), 1); > if (idev == 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 = spa_find_by_name(poolname); > if (!spa) > return (ENXIO); > - dev = malloc(sizeof(*dev)); > + dev = calloc(sizeof(*dev), 1); > if (dev == NULL) > return (ENOMEM); > dev->pool_guid = 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 == NULL) > return(ENOENT); > - idev = malloc(sizeof(struct uboot_devdesc)); > + idev = calloc(sizeof(struct uboot_devdesc), 1); > err = 0; > np = (devspec + strlen(dv->dv_name)); >