Date: Tue, 29 Dec 2020 14:28:37 GMT From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 3e404b8c53db - main - libcam(3): make cam_getccb(3) zero the whole ccb, not just the header Message-ID: <202012291428.0BTESbJR091224@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by trasz: URL: https://cgit.FreeBSD.org/src/commit/?id=3e404b8c53db56bdb0aca6a491b095266326211c commit 3e404b8c53db56bdb0aca6a491b095266326211c Author: Edward Tomasz Napierala <trasz@FreeBSD.org> AuthorDate: 2020-12-29 14:25:46 +0000 Commit: Edward Tomasz Napierala <trasz@FreeBSD.org> CommitDate: 2020-12-29 14:26:06 +0000 libcam(3): make cam_getccb(3) zero the whole ccb, not just the header Leaving zeroing to the clients leads to error-prone pointer tricks (zeroing needs to preserve the CCB header), and this code is not performance-critical, so there's really no reason to not do it. Reviewed By: imp, rpokala (manpages) Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D27333 --- lib/libcam/cam.3 | 6 +++--- lib/libcam/camlib.c | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/libcam/cam.3 b/lib/libcam/cam.3 index a13b580f847e..5e8eb61698c4 100644 --- a/lib/libcam/cam.3 +++ b/lib/libcam/cam.3 @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 6, 2020 +.Dd November 23, 2020 .Dt CAM 3 .Os .Sh NAME @@ -285,9 +285,9 @@ This function should be called when the structure was allocated by the caller, rather than the CAM library. .Pp .Fn cam_getccb -allocates a CCB +allocates a prezeroed CCB using -.Xr malloc 3 +.Xr calloc 3 and sets fields in the CCB header using values from the .Va cam_device structure. diff --git a/lib/libcam/camlib.c b/lib/libcam/camlib.c index 40242958bfaf..438b0e502fe0 100644 --- a/lib/libcam/camlib.c +++ b/lib/libcam/camlib.c @@ -79,9 +79,8 @@ cam_getccb(struct cam_device *dev) { union ccb *ccb; - ccb = (union ccb *)malloc(sizeof(union ccb)); + ccb = calloc(1, sizeof(*ccb)); if (ccb != NULL) { - bzero(&ccb->ccb_h, sizeof(struct ccb_hdr)); ccb->ccb_h.path_id = dev->path_id; ccb->ccb_h.target_id = dev->target_id; ccb->ccb_h.target_lun = dev->target_lun;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202012291428.0BTESbJR091224>