Mon Jul 2 21:11:50 2012 UTC ()
Pull up revision 1.86 (requested by riastradh in ticket #373).

Take the kernel lock in atapibusdetach just like atapibuschilddet.

Fixes kassert in scsipi_lookup_periph when I press the power button
on one of my laptops (and maybe another one) to power it off.

ok mrg


(jdc)
diff -r1.83.14.2 -r1.83.14.3 src/sys/dev/scsipi/atapiconf.c

cvs diff -r1.83.14.2 -r1.83.14.3 src/sys/dev/scsipi/atapiconf.c (expand / switch to unified diff)

--- src/sys/dev/scsipi/atapiconf.c 2012/04/23 16:28:30 1.83.14.2
+++ src/sys/dev/scsipi/atapiconf.c 2012/07/02 21:11:50 1.83.14.3
@@ -1,41 +1,41 @@ @@ -1,41 +1,41 @@
1/* $NetBSD: atapiconf.c,v 1.83.14.2 2012/04/23 16:28:30 riz Exp $ */ 1/* $NetBSD: atapiconf.c,v 1.83.14.3 2012/07/02 21:11:50 jdc Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, 2001 Manuel Bouyer. All rights reserved. 4 * Copyright (c) 1996, 2001 Manuel Bouyer. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27#include <sys/cdefs.h> 27#include <sys/cdefs.h>
28__KERNEL_RCSID(0, "$NetBSD: atapiconf.c,v 1.83.14.2 2012/04/23 16:28:30 riz Exp $"); 28__KERNEL_RCSID(0, "$NetBSD: atapiconf.c,v 1.83.14.3 2012/07/02 21:11:50 jdc Exp $");
29 29
30#include <sys/param.h> 30#include <sys/param.h>
31#include <sys/systm.h> 31#include <sys/systm.h>
32#include <sys/malloc.h> 32#include <sys/malloc.h>
33#include <sys/device.h> 33#include <sys/device.h>
34#include <sys/buf.h> 34#include <sys/buf.h>
35#include <sys/proc.h> 35#include <sys/proc.h>
36#include <sys/kthread.h> 36#include <sys/kthread.h>
37 37
38#include <dev/scsipi/scsipi_all.h> 38#include <dev/scsipi/scsipi_all.h>
39#include <dev/scsipi/scsipiconf.h> 39#include <dev/scsipi/scsipiconf.h>
40#include <dev/scsipi/atapiconf.h> 40#include <dev/scsipi/atapiconf.h>
41 41
@@ -184,46 +184,53 @@ atapibuschilddet(device_t self, device_t @@ -184,46 +184,53 @@ atapibuschilddet(device_t self, device_t
184 break; 184 break;
185 } 185 }
186 186
187 /* XXXSMP scsipi */ 187 /* XXXSMP scsipi */
188 KERNEL_UNLOCK_ONE(curlwp); 188 KERNEL_UNLOCK_ONE(curlwp);
189} 189}
190 190
191static int 191static int
192atapibusdetach(device_t self, int flags) 192atapibusdetach(device_t self, int flags)
193{ 193{
194 struct atapibus_softc *sc = device_private(self); 194 struct atapibus_softc *sc = device_private(self);
195 struct scsipi_channel *chan = sc->sc_channel; 195 struct scsipi_channel *chan = sc->sc_channel;
196 struct scsipi_periph *periph; 196 struct scsipi_periph *periph;
197 int target, error; 197 int target, error = 0;
198 198
199 /* 199 /*
200 * Shut down the channel. 200 * Shut down the channel.
201 */ 201 */
202 scsipi_channel_shutdown(chan); 202 scsipi_channel_shutdown(chan);
203 203
 204 /* XXXSMP scsipi */
 205 KERNEL_LOCK(1, curlwp);
 206
204 /* 207 /*
205 * Now detach all of the periphs. 208 * Now detach all of the periphs.
206 */ 209 */
207 for (target = 0; target < chan->chan_ntargets; target++) { 210 for (target = 0; target < chan->chan_ntargets; target++) {
208 periph = scsipi_lookup_periph(chan, target, 0); 211 periph = scsipi_lookup_periph(chan, target, 0);
209 if (periph == NULL) 212 if (periph == NULL)
210 continue; 213 continue;
211 error = config_detach(periph->periph_dev, flags); 214 error = config_detach(periph->periph_dev, flags);
212 if (error) 215 if (error)
213 return (error); 216 goto out;
214 KASSERT(scsipi_lookup_periph(chan, target, 0) == NULL); 217 KASSERT(scsipi_lookup_periph(chan, target, 0) == NULL);
215 } 218 }
216 return (0); 219
 220out:
 221 /* XXXSMP scsipi */
 222 KERNEL_UNLOCK_ONE(curlwp);
 223 return error;
217} 224}
218 225
219static int 226static int
220atapi_probe_bus(struct atapibus_softc *sc, int target) 227atapi_probe_bus(struct atapibus_softc *sc, int target)
221{ 228{
222 struct scsipi_channel *chan = sc->sc_channel; 229 struct scsipi_channel *chan = sc->sc_channel;
223 int maxtarget, mintarget; 230 int maxtarget, mintarget;
224 int error; 231 int error;
225 struct atapi_adapter *atapi_adapter; 232 struct atapi_adapter *atapi_adapter;
226 233
227 if (target == -1) { 234 if (target == -1) {
228 maxtarget = 1; 235 maxtarget = 1;
229 mintarget = 0; 236 mintarget = 0;