summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorrdivacky <rdivacky@FreeBSD.org>2014-11-29 08:59:26 +0000
committerrdivacky <rdivacky@FreeBSD.org>2014-11-29 08:59:26 +0000
commit0dd1357d8443eb73b9806788853b2a05d5d7d0fe (patch)
tree0ddde6fe84d1eaba4eba3383e18fb03513462b95 /sys
parent83a7923d50725429226bb50b1216674701fd502c (diff)
downloadFreeBSD-src-0dd1357d8443eb73b9806788853b2a05d5d7d0fe.zip
FreeBSD-src-0dd1357d8443eb73b9806788853b2a05d5d7d0fe.tar.gz
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.
Diffstat (limited to 'sys')
-rw-r--r--sys/boot/i386/boot2/boot2.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/sys/boot/i386/boot2/boot2.c b/sys/boot/i386/boot2/boot2.c
index 4e1a835..001126f 100644
--- a/sys/boot/i386/boot2/boot2.c
+++ b/sys/boot/i386/boot2/boot2.c
@@ -501,6 +501,7 @@ dskread(void *buf, unsigned lba, unsigned nblk)
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, unsigned nblk)
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, unsigned nblk)
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, unsigned nblk)
}
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
OpenPOWER on IntegriCloud