Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Jun 2017 16:11:39 +0000 (UTC)
From:      Alan Cox <alc@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r319793 - in head/sys: kern sys
Message-ID:  <201706101611.v5AGBdqg054767@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: alc
Date: Sat Jun 10 16:11:39 2017
New Revision: 319793
URL: https://svnweb.freebsd.org/changeset/base/319793

Log:
  Remove an unnecessary field from struct blist.  (The comment describing
  what this field represented was also inaccurate.)  Suggested by: kib
  
  In r178792, blist_create() grew a malloc flag, allowing M_NOWAIT to be
  specified.  However, blist_create() was not modified to handle the
  possibility that a malloc() call failed.  Address this omission.
  
  Increase the width of the local variable "radix" to 64 bits.  (This
  matches the width of the corresponding field in struct blist.)
  
  Reviewed by:	kib
  MFC after:	6 weeks

Modified:
  head/sys/kern/subr_blist.c
  head/sys/sys/blist.h

Modified: head/sys/kern/subr_blist.c
==============================================================================
--- head/sys/kern/subr_blist.c	Sat Jun 10 14:47:01 2017	(r319792)
+++ head/sys/kern/subr_blist.c	Sat Jun 10 16:11:39 2017	(r319793)
@@ -156,7 +156,7 @@ blist_t 
 blist_create(daddr_t blocks, int flags)
 {
 	blist_t bl;
-	int radix;
+	daddr_t nodes, radix;
 	int skip = 0;
 
 	/*
@@ -170,13 +170,19 @@ blist_create(daddr_t blocks, int flags)
 	}
 
 	bl = malloc(sizeof(struct blist), M_SWAP, flags | M_ZERO);
+	if (bl == NULL)
+		return (NULL);
 
 	bl->bl_blocks = blocks;
 	bl->bl_radix = radix;
 	bl->bl_skip = skip;
-	bl->bl_rootblks = 1 +
-	    blst_radix_init(NULL, bl->bl_radix, bl->bl_skip, blocks);
-	bl->bl_root = malloc(sizeof(blmeta_t) * bl->bl_rootblks, M_SWAP, flags);
+	nodes = 1 + blst_radix_init(NULL, radix, bl->bl_skip, blocks);
+	bl->bl_root = malloc(nodes * sizeof(blmeta_t), M_SWAP, flags);
+	if (bl->bl_root == NULL) {
+		free(bl, M_SWAP);
+		return (NULL);
+	}
+	blst_radix_init(bl->bl_root, radix, bl->bl_skip, blocks);
 
 #if defined(BLIST_DEBUG)
 	printf(
@@ -184,14 +190,13 @@ blist_create(daddr_t blocks, int flags)
 		", requiring %lldK of ram\n",
 		(long long)bl->bl_blocks,
 		(long long)bl->bl_blocks * 4 / 1024,
-		(long long)(bl->bl_rootblks * sizeof(blmeta_t) + 1023) / 1024
+		(long long)(nodes * sizeof(blmeta_t) + 1023) / 1024
 	);
 	printf("BLIST raw radix tree contains %lld records\n",
-	    (long long)bl->bl_rootblks);
+	    (long long)nodes);
 #endif
-	blst_radix_init(bl->bl_root, bl->bl_radix, bl->bl_skip, blocks);
 
-	return(bl);
+	return (bl);
 }
 
 void 

Modified: head/sys/sys/blist.h
==============================================================================
--- head/sys/sys/blist.h	Sat Jun 10 14:47:01 2017	(r319792)
+++ head/sys/sys/blist.h	Sat Jun 10 16:11:39 2017	(r319793)
@@ -84,7 +84,6 @@ typedef struct blist {
 	daddr_t		bl_skip;	/* starting skip		*/
 	daddr_t		bl_free;	/* number of free blocks	*/
 	blmeta_t	*bl_root;	/* root of radix tree		*/
-	daddr_t		bl_rootblks;	/* daddr_t blks allocated for tree */
 } *blist_t;
 
 #define BLIST_META_RADIX	16



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201706101611.v5AGBdqg054767>