Module Name: src
Committed By: mlelstv
Date: Wed Sep 14 23:16:30 UTC 2016
Modified Files:
src/sys/dev: cgd.c
Log Message:
Fix error handling in cgdstrategy().
- check cgd_softc != NULL, may happen in rare memory shortage situations.
- no longer test geometry, the same check is done in dk_strategy which
knows to check for an uninitialized geometry.
To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/sys/dev/cgd.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/cgd.c
diff -u src/sys/dev/cgd.c:1.110 src/sys/dev/cgd.c:1.111
--- src/sys/dev/cgd.c:1.110 Fri Aug 5 08:24:46 2016
+++ src/sys/dev/cgd.c Wed Sep 14 23:16:30 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd.c,v 1.110 2016/08/05 08:24:46 pgoyette Exp $ */
+/* $NetBSD: cgd.c,v 1.111 2016/09/14 23:16:30 mlelstv Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.110 2016/08/05 08:24:46 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.111 2016/09/14 23:16:30 mlelstv Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -305,30 +305,32 @@ cgdclose(dev_t dev, int flags, int fmt,
static void
cgdstrategy(struct buf *bp)
{
- struct cgd_softc *cs = getcgd_softc(bp->b_dev);
- struct dk_softc *dksc = &cs->sc_dksc;
- struct disk_geom *dg = &dksc->sc_dkdev.dk_geom;
+ struct cgd_softc *cs;
DPRINTF_FOLLOW(("cgdstrategy(%p): b_bcount = %ld\n", bp,
(long)bp->b_bcount));
+ cs = getcgd_softc(bp->b_dev);
+ if (!cs) {
+ bp->b_error = ENXIO;
+ goto bail;
+ }
+
/*
- * Reject unaligned writes. We can encrypt and decrypt only
- * complete disk sectors, and we let the ciphers require their
- * buffers to be aligned to 32-bit boundaries.
+ * Reject unaligned writes.
*/
- if (bp->b_blkno < 0 ||
- (bp->b_bcount % dg->dg_secsize) != 0 ||
- ((uintptr_t)bp->b_data & 3) != 0) {
+ if (((uintptr_t)bp->b_data & 3) != 0) {
bp->b_error = EINVAL;
- bp->b_resid = bp->b_bcount;
- biodone(bp);
- return;
+ goto bail;
}
- /* XXXrcd: Should we test for (cs != NULL)? */
dk_strategy(&cs->sc_dksc, bp);
return;
+
+bail:
+ bp->b_resid = bp->b_bcount;
+ biodone(bp);
+ return;
}
static int