Module Name:    src
Committed By:   rin
Date:           Tue Feb 28 04:46:02 UTC 2017

Modified Files:
        src/sys/dev/dkwedge: dkwedge_rdb.c

Log Message:
determine the buffer size by roundup(9)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/dkwedge/dkwedge_rdb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/dkwedge/dkwedge_rdb.c
diff -u src/sys/dev/dkwedge/dkwedge_rdb.c:1.2 src/sys/dev/dkwedge/dkwedge_rdb.c:1.3
--- src/sys/dev/dkwedge/dkwedge_rdb.c:1.2	Tue Feb 28 04:39:58 2017
+++ src/sys/dev/dkwedge/dkwedge_rdb.c	Tue Feb 28 04:46:02 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: dkwedge_rdb.c,v 1.2 2017/02/28 04:39:58 rin Exp $	*/
+/*	$NetBSD: dkwedge_rdb.c,v 1.3 2017/02/28 04:46:02 rin Exp $	*/
 
 /*
  * Adapted from arch/amiga/amiga/disksubr.c:
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dkwedge_rdb.c,v 1.2 2017/02/28 04:39:58 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dkwedge_rdb.c,v 1.3 2017/02/28 04:46:02 rin Exp $");
 
 #include <sys/param.h>
 #include <sys/disklabel_rdb.h>
@@ -124,9 +124,8 @@ dkwedge_discover_rdb(struct disk *pdk, s
 	bool found, root, swap;
 
 	secsize = bufsize = DEV_BSIZE << pdk->dk_blkshift;
-	while (bufsize < sizeof(struct partblock) ||
-	       bufsize < sizeof(struct rdblock))
-		bufsize *= 2;
+	bufsize = roundup(MAX(sizeof(struct partblock), sizeof(struct rdblock)),
+	    secsize);
 	bp = DKW_MALLOC(bufsize);
 
 	/*
@@ -160,10 +159,9 @@ dkwedge_discover_rdb(struct disk *pdk, s
 	if (secsize != newsecsize) {
 		aprint_verbose("secsize changed from %u to %u\n",
 		    secsize, newsecsize);
-		secsize = bufsize = newsecsize;
-		while (bufsize < sizeof(struct partblock) ||
-		       bufsize < sizeof(struct rdblock))
-			bufsize *= 2;
+		secsize = newsecsize;
+		bufsize = roundup(MAX(sizeof(struct partblock),
+		    sizeof(struct rdblock)), secsize);
 		bp = DKW_REALLOC(bp, bufsize);
 	}
 

Reply via email to