Wed Jul 27 05:14:40 2016 UTC ()
Don't mutex_exit() if we didn't mutex_enter().

Pointed out by coypu. Thanks!


(pgoyette)
diff -r1.77 -r1.78 src/sys/dev/md.c

cvs diff -r1.77 -r1.78 src/sys/dev/md.c (expand / switch to unified diff)

--- src/sys/dev/md.c 2016/07/27 01:09:44 1.77
+++ src/sys/dev/md.c 2016/07/27 05:14:40 1.78
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: md.c,v 1.77 2016/07/27 01:09:44 pgoyette Exp $ */ 1/* $NetBSD: md.c,v 1.78 2016/07/27 05:14:40 pgoyette Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1995 Gordon W. Ross, Leo Weppelman. 4 * Copyright (c) 1995 Gordon W. Ross, Leo Weppelman.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -30,27 +30,27 @@ @@ -30,27 +30,27 @@
30 * See md.h for notes on the config types. 30 * See md.h for notes on the config types.
31 * 31 *
32 * Note that this driver provides the same functionality 32 * Note that this driver provides the same functionality
33 * as the MFS filesystem hack, but this is better because 33 * as the MFS filesystem hack, but this is better because
34 * you can use this for any filesystem type you'd like! 34 * you can use this for any filesystem type you'd like!
35 * 35 *
36 * Credit for most of the kmem ramdisk code goes to: 36 * Credit for most of the kmem ramdisk code goes to:
37 * Leo Weppelman (atari) and Phil Nelson (pc532) 37 * Leo Weppelman (atari) and Phil Nelson (pc532)
38 * Credit for the ideas behind the "user space memory" code goes 38 * Credit for the ideas behind the "user space memory" code goes
39 * to the authors of the MFS implementation. 39 * to the authors of the MFS implementation.
40 */ 40 */
41 41
42#include <sys/cdefs.h> 42#include <sys/cdefs.h>
43__KERNEL_RCSID(0, "$NetBSD: md.c,v 1.77 2016/07/27 01:09:44 pgoyette Exp $"); 43__KERNEL_RCSID(0, "$NetBSD: md.c,v 1.78 2016/07/27 05:14:40 pgoyette Exp $");
44 44
45#ifdef _KERNEL_OPT 45#ifdef _KERNEL_OPT
46#include "opt_md.h" 46#include "opt_md.h"
47#else 47#else
48#define MEMORY_DISK_SERVER 1 48#define MEMORY_DISK_SERVER 1
49#endif 49#endif
50 50
51#include <sys/param.h> 51#include <sys/param.h>
52#include <sys/kernel.h> 52#include <sys/kernel.h>
53#include <sys/malloc.h> 53#include <sys/malloc.h>
54#include <sys/systm.h> 54#include <sys/systm.h>
55#include <sys/buf.h> 55#include <sys/buf.h>
56#include <sys/bufq.h> 56#include <sys/bufq.h>
@@ -453,29 +453,29 @@ mdstrategy(struct buf *bp) @@ -453,29 +453,29 @@ mdstrategy(struct buf *bp)
453 memcpy(bp->b_data, addr, xfer); 453 memcpy(bp->b_data, addr, xfer);
454 else 454 else
455 memcpy(addr, bp->b_data, xfer); 455 memcpy(addr, bp->b_data, xfer);
456 disk_unbusy(&sc->sc_dkdev, xfer, is_read); 456 disk_unbusy(&sc->sc_dkdev, xfer, is_read);
457 bp->b_resid -= xfer; 457 bp->b_resid -= xfer;
458 break; 458 break;
459 459
460 default: 460 default:
461 bp->b_resid = bp->b_bcount; 461 bp->b_resid = bp->b_bcount;
462 set_eio: 462 set_eio:
463 bp->b_error = EIO; 463 bp->b_error = EIO;
464 break; 464 break;
465 } 465 }
 466 mutex_exit(&sc->sc_lock);
466 467
467 done: 468 done:
468 mutex_exit(&sc->sc_lock); 
469 469
470 biodone(bp); 470 biodone(bp);
471} 471}
472 472
473static int 473static int
474mdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) 474mdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
475{ 475{
476 struct md_softc *sc; 476 struct md_softc *sc;
477 struct md_conf *umd; 477 struct md_conf *umd;
478 int error; 478 int error;
479 479
480 if ((sc = device_lookup_private(&md_cd, MD_UNIT(dev))) == NULL) 480 if ((sc = device_lookup_private(&md_cd, MD_UNIT(dev))) == NULL)
481 return ENXIO; 481 return ENXIO;