Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Aug 2018 19:17:07 +0000 (UTC)
From:      Toomas Soome <tsoome@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r337356 - head/stand/i386/libi386
Message-ID:  <201808051917.w75JH706012780@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tsoome
Date: Sun Aug  5 19:17:07 2018
New Revision: 337356
URL: https://svnweb.freebsd.org/changeset/base/337356

Log:
  loader: bd_open() should cleanup from disk_open() error
  
  Since bd_open() does early increment for reference counter and bcache
  allocation, it also should undo those in case of the error.
  
  Also remove unused variables rdev, g_err.

Modified:
  head/stand/i386/libi386/biosdisk.c

Modified: head/stand/i386/libi386/biosdisk.c
==============================================================================
--- head/stand/i386/libi386/biosdisk.c	Sun Aug  5 18:27:36 2018	(r337355)
+++ head/stand/i386/libi386/biosdisk.c	Sun Aug  5 19:17:07 2018	(r337356)
@@ -337,11 +337,11 @@ bd_print(int verbose)
 static int
 bd_open(struct open_file *f, ...)
 {
-	struct disk_devdesc *dev, rdev;
+	struct disk_devdesc *dev;
 	struct disk_devdesc disk;
-	int err, g_err;
 	va_list ap;
 	uint64_t size;
+	int rc;
 
 	va_start(ap, f);
 	dev = va_arg(ap, struct disk_devdesc *);
@@ -365,6 +365,7 @@ bd_open(struct open_file *f, ...)
 	disk.d_slice = -1;
 	disk.d_partition = -1;
 	disk.d_offset = 0;
+
 	if (disk_open(&disk, BD(dev).bd_sectors * BD(dev).bd_sectorsize,
 	    BD(dev).bd_sectorsize) == 0) {
 
@@ -376,10 +377,17 @@ bd_open(struct open_file *f, ...)
 		disk_close(&disk);
 	}
 
-	err = disk_open(dev, BD(dev).bd_sectors * BD(dev).bd_sectorsize,
+	rc = disk_open(dev, BD(dev).bd_sectors * BD(dev).bd_sectorsize,
 	    BD(dev).bd_sectorsize);
+	if (rc != 0) {
+		BD(dev).bd_open--;
+		if (BD(dev).bd_open == 0) {
+			bcache_free(BD(dev).bd_bcache);
+			BD(dev).bd_bcache = NULL;
+		}
+	}
 
-	return (err);
+	return (rc);
 }
 
 static int



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