Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/nvmectl nvmectl(8): Ensure A divides S before aligned_a...



details:   https://anonhg.NetBSD.org/src/rev/e73117891537
branches:  trunk
changeset: 377268:e73117891537
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue Jul 04 20:40:43 2023 +0000

description:
nvmectl(8): Ensure A divides S before aligned_alloc(A, S).

Required by C11 Sec. 7.22.3.1 The aligned_alloc function, para. 2,
p. 348:

   The value of alignment shall be a valid alignment supported by the
   implementation and the value of size shall be an integral multiple
   of alignment.

XXX pullup-10

diffstat:

 sbin/nvmectl/firmware.c |  5 +++--
 sbin/nvmectl/wdc.c      |  6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diffs (53 lines):

diff -r 18e7821bbdb5 -r e73117891537 sbin/nvmectl/firmware.c
--- a/sbin/nvmectl/firmware.c   Tue Jul 04 20:40:34 2023 +0000
+++ b/sbin/nvmectl/firmware.c   Tue Jul 04 20:40:43 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: firmware.c,v 1.4 2018/04/18 10:11:44 nonaka Exp $      */
+/*     $NetBSD: firmware.c,v 1.5 2023/07/04 20:40:43 riastradh Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: firmware.c,v 1.4 2018/04/18 10:11:44 nonaka Exp $");
+__RCSID("$NetBSD: firmware.c,v 1.5 2023/07/04 20:40:43 riastradh Exp $");
 #if 0
 __FBSDID("$FreeBSD: head/sbin/nvmecontrol/firmware.c 329824 2018-02-22 13:32:31Z wma $");
 #endif
@@ -123,6 +123,7 @@ update_firmware(int fd, uint8_t *payload
        off = 0;
        resid = payload_size;
 
+       __CTASSERT((NVME_MAX_XFER_SIZE % PAGE_SIZE) == 0);
        if ((chunk = aligned_alloc(PAGE_SIZE, NVME_MAX_XFER_SIZE)) == NULL)
                errx(1, "unable to malloc %d bytes", NVME_MAX_XFER_SIZE);
 
diff -r 18e7821bbdb5 -r e73117891537 sbin/nvmectl/wdc.c
--- a/sbin/nvmectl/wdc.c        Tue Jul 04 20:40:34 2023 +0000
+++ b/sbin/nvmectl/wdc.c        Tue Jul 04 20:40:43 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wdc.c,v 1.4 2018/04/18 10:11:44 nonaka Exp $   */
+/*     $NetBSD: wdc.c,v 1.5 2023/07/04 20:40:43 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2017 Netflix, Inc
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: wdc.c,v 1.4 2018/04/18 10:11:44 nonaka Exp $");
+__RCSID("$NetBSD: wdc.c,v 1.5 2023/07/04 20:40:43 riastradh Exp $");
 #if 0
 __FBSDID("$FreeBSD: head/sbin/nvmecontrol/wdc.c 329824 2018-02-22 13:32:31Z wma $");
 #endif
@@ -125,7 +125,7 @@ wdc_do_dump(int fd, char *tmpl, const ch
        fd2 = open(tmpl, O_WRONLY | O_CREAT | O_TRUNC, 0644);
        if (fd2 < 0)
                err(1, "open %s", tmpl);
-       buf = aligned_alloc(page_size, NVME_MAX_XFER_SIZE);
+       buf = aligned_alloc(page_size, roundup(NVME_MAX_XFER_SIZE, page_size));
        if (buf == NULL)
                errx(1, "Can't get buffer to read dump");
        offset = 0;



Home | Main Index | Thread Index | Old Index