Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 29 Nov 2014 08:59:27 +0000 (UTC)
From:      Roman Divacky <rdivacky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r275237 - head/sys/boot/i386/boot2
Message-ID:  <201411290859.sAT8xRte063492@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rdivacky
Date: Sat Nov 29 08:59:26 2014
New Revision: 275237
URL: https://svnweb.freebsd.org/changeset/base/275237

Log:
  Shrink boot2 a bit more by factoring out common pattern
  of printf();return(-1);
  
  This shrinks it by 8bytes using clang35 and by 12bytes using clang34.

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

Modified: head/sys/boot/i386/boot2/boot2.c
==============================================================================
--- head/sys/boot/i386/boot2/boot2.c	Sat Nov 29 08:33:54 2014	(r275236)
+++ head/sys/boot/i386/boot2/boot2.c	Sat Nov 29 08:59:26 2014	(r275237)
@@ -501,6 +501,7 @@ dskread(void *buf, unsigned lba, unsigne
     char *sec;
     unsigned i;
     uint8_t sl;
+    const char *reason;
 
     if (!dsk_meta) {
 	sec = dmadat->secbuf;
@@ -525,8 +526,8 @@ dskread(void *buf, unsigned lba, unsigne
 	    if (sl != COMPATIBILITY_SLICE)
 		dp += sl - BASE_SLICE;
 	    if (dp->dp_typ != DOSPTYP_386BSD) {
-		printf("Invalid %s\n", "slice");
-		return -1;
+		reason = "slice";
+		goto error;
 	    }
 	    dsk.start = dp->dp_start;
 	}
@@ -535,8 +536,8 @@ 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.init) {
@@ -546,14 +547,17 @@ dskread(void *buf, unsigned lba, unsigne
 	    }
 	    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;
 	}
     }
     return drvread(buf, dsk.start + lba, nblk);
+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?201411290859.sAT8xRte063492>