Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ata chuq does not like insomniac allocations so unlo...



details:   https://anonhg.NetBSD.org/src/rev/d53c926b7e3c
branches:  trunk
changeset: 460408:d53c926b7e3c
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Oct 21 18:58:57 2019 +0000

description:
chuq does not like insomniac allocations so unlock-alloc-lock instead.

diffstat:

 sys/dev/ata/ata.c |  20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diffs (41 lines):

diff -r ecb9be120bb6 -r d53c926b7e3c sys/dev/ata/ata.c
--- a/sys/dev/ata/ata.c Mon Oct 21 18:37:47 2019 +0000
+++ b/sys/dev/ata/ata.c Mon Oct 21 18:58:57 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ata.c,v 1.152 2019/10/21 18:37:47 christos Exp $       */
+/*     $NetBSD: ata.c,v 1.153 2019/10/21 18:58:57 christos Exp $       */
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.152 2019/10/21 18:37:47 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.153 2019/10/21 18:58:57 christos Exp $");
 
 #include "opt_ata.h"
 
@@ -749,10 +749,18 @@
        if (chp->ch_ndrives != ndrives)
                atabus_free_drives(chp);
        if (chp->ch_drive == NULL) {
-               chp->ch_drive = kmem_zalloc(
-                   sizeof(struct ata_drive_datas) * ndrives, KM_NOSLEEP);
-               if (chp->ch_drive == NULL)
-                       return ENOMEM;
+               void *drv;
+
+               ata_channel_unlock(chp);
+               drv = kmem_zalloc(sizeof(*chp->ch_drive) * ndrives, KM_SLEEP);
+               ata_channel_lock(chp);
+
+               if (chp->ch_drive != NULL) {
+                       /* lost the race */
+                       kmem_free(drv, sizeof(*chp->ch_drive) * ndrives);
+                       return 0;
+               }
+               chp->ch_drive = drv;
        }
        for (i = 0; i < ndrives; i++) {
                chp->ch_drive[i].chnl_softc = chp;



Home | Main Index | Thread Index | Old Index