Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 29 Nov 2014 09:27:18 +0000 (UTC)
From:      Takahashi Yoshihiro <nyan@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r275239 - head/sys/boot/pc98/boot2
Message-ID:  <201411290927.sAT9RII2077604@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: nyan
Date: Sat Nov 29 09:27:18 2014
New Revision: 275239
URL: https://svnweb.freebsd.org/changeset/base/275239

Log:
  MFi386: r275237 (by rdivacky)
  
    Shrink boot2 a bit more by factoring out common pattern
    of printf();return(-1);

Modified:
  head/sys/boot/pc98/boot2/boot2.c

Modified: head/sys/boot/pc98/boot2/boot2.c
==============================================================================
--- head/sys/boot/pc98/boot2/boot2.c	Sat Nov 29 09:09:54 2014	(r275238)
+++ head/sys/boot/pc98/boot2/boot2.c	Sat Nov 29 09:27:18 2014	(r275239)
@@ -639,6 +639,7 @@ dskread(void *buf, unsigned lba, unsigne
     unsigned i;
     uint8_t sl;
     u_char *p;
+    const char *reason;
 
     if (!dsk_meta) {
 	sec = dmadat->secbuf;
@@ -660,8 +661,8 @@ dskread(void *buf, unsigned lba, unsigne
 	if (sl != WHOLE_DISK_SLICE) {
 	    dp += sl - BASE_SLICE;
 	    if (dp->dp_mid != DOSMID_386BSD) {
-		printf("Invalid %s\n", "slice");
-		return -1;
+		reason = "slice";
+		goto error;
 	    }
 	    dsk.start = dp->dp_scyl * dsk.head * dsk.sec +
 		dp->dp_shd * dsk.sec + dp->dp_ssect;
@@ -671,14 +672,14 @@ dskread(void *buf, unsigned lba, unsigne
 	d = (void *)(sec + LABELOFFSET);
 	if (d->d_magic != DISKMAGIC || d->d_magic2 != DISKMAGIC) {
 	    if (dsk.part != RAW_PART) {
-		printf("Invalid %s\n", "label");
-		return -1;
+		reason = "label";
+		goto error;
 	    }
 	} else {
 	    if (dsk.part >= d->d_npartitions ||
 		!d->d_partitions[dsk.part].p_size) {
-		printf("Invalid %s\n", "partition");
-		return -1;
+		reason = "partition";
+		goto error;
 	    }
 	    dsk.start += d->d_partitions[dsk.part].p_offset;
 	    dsk.start -= d->d_partitions[RAW_PART].p_offset;
@@ -690,6 +691,9 @@ dskread(void *buf, unsigned lba, unsigne
 	    return i;
     }
     return 0;
+error:
+    printf("Invalid %s\n", reason);
+    return -1;
 }
 
 static void



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