From owner-dev-commits-src-main@freebsd.org Tue Dec 29 14:28:37 2020 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3E7F84C0B4A; Tue, 29 Dec 2020 14:28:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D4xc51Kx3z4d0B; Tue, 29 Dec 2020 14:28:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 20CAE57D4; Tue, 29 Dec 2020 14:28:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 0BTESb4E091225; Tue, 29 Dec 2020 14:28:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 0BTESbJR091224; Tue, 29 Dec 2020 14:28:37 GMT (envelope-from git) Date: Tue, 29 Dec 2020 14:28:37 GMT Message-Id: <202012291428.0BTESbJR091224@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Edward Tomasz Napierala Subject: git: 3e404b8c53db - main - libcam(3): make cam_getccb(3) zero the whole ccb, not just the header MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: trasz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3e404b8c53db56bdb0aca6a491b095266326211c Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "Commit messages for the main branch of the src repository." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Dec 2020 14:28:37 -0000 The branch main has been updated by trasz: URL: https://cgit.FreeBSD.org/src/commit/?id=3e404b8c53db56bdb0aca6a491b095266326211c commit 3e404b8c53db56bdb0aca6a491b095266326211c Author: Edward Tomasz Napierala AuthorDate: 2020-12-29 14:25:46 +0000 Commit: Edward Tomasz Napierala 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;