Source-Changes-HG archive

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

[src/jdolecek-ncq]: src/sys/dev/ata Simplify wi_find() with container_of().



details:   https://anonhg.NetBSD.org/src/rev/4fb4c9abc70f
branches:  jdolecek-ncq
changeset: 822895:4fb4c9abc70f
user:      jakllsch <jakllsch%NetBSD.org@localhost>
date:      Sun Apr 23 01:21:04 2017 +0000

description:
Simplify wi_find() with container_of().

No need to search a list of wd_ioctls when the *bp is always going to be within the wd_ioctl structure.

Correctly initialize wi->wi_bp.b_dev in the non-data case anyway.

Fixes ATAIOCCOMMAND procesing on driver instances other than wd0.

diffstat:

 sys/dev/ata/wd.c    |  29 ++++-------------------------
 sys/dev/ata/wdvar.h |   4 +---
 2 files changed, 5 insertions(+), 28 deletions(-)

diffs (103 lines):

diff -r 78a639d74331 -r 4fb4c9abc70f sys/dev/ata/wd.c
--- a/sys/dev/ata/wd.c  Sat Apr 22 20:07:54 2017 +0000
+++ b/sys/dev/ata/wd.c  Sun Apr 23 01:21:04 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wd.c,v 1.428.2.10 2017/04/22 20:07:54 jakllsch Exp $ */
+/*     $NetBSD: wd.c,v 1.428.2.11 2017/04/23 01:21:04 jakllsch Exp $ */
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -54,7 +54,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.428.2.10 2017/04/22 20:07:54 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.428.2.11 2017/04/23 01:21:04 jakllsch Exp $");
 
 #include "opt_ata.h"
 
@@ -306,7 +306,6 @@
 #ifdef WD_SOFTBADSECT
        SLIST_INIT(&wd->sc_bslist);
 #endif
-       LIST_INIT(&wd->wi_head);
        STAILQ_INIT(&wd->xfer_restart);
        wd->atabus = adev->adev_bustype;
        wd->drvp = adev->adev_drv_data;
@@ -509,7 +508,6 @@
        }
        sc->sc_bscount = 0;
 #endif
-       KASSERT(LIST_EMPTY(&sc->wi_head));
 
        pmf_device_deregister(self);
 
@@ -1555,7 +1553,7 @@
                        wi->wi_bp.b_flags = 0;
                        wi->wi_bp.b_data = 0;
                        wi->wi_bp.b_bcount = 0;
-                       wi->wi_bp.b_dev = 0;
+                       wi->wi_bp.b_dev = dev;
                        wi->wi_bp.b_proc = l->l_proc;
                        wdioctlstrategy(&wi->wi_bp);
                        error1 = wi->wi_bp.b_error;
@@ -2148,10 +2146,6 @@
        wi->wi_softc = wd;
        buf_init(&wi->wi_bp);
 
-       mutex_enter(&wd->sc_lock);
-       LIST_INSERT_HEAD(&wd->wi_head, wi, wi_list);
-       mutex_exit(&wd->sc_lock);
-
        return (wi);
 }
 
@@ -2162,11 +2156,6 @@
 void
 wi_free(struct wd_ioctl *wi)
 {
-       struct wd_softc *wd = wi->wi_softc;
-
-       mutex_enter(&wd->sc_lock);
-       LIST_REMOVE(wi, wi_list);
-       mutex_exit(&wd->sc_lock);
        buf_destroy(&wi->wi_bp);
        free(wi, M_TEMP);
 }
@@ -2178,17 +2167,7 @@
 struct wd_ioctl *
 wi_find(struct buf *bp)
 {
-       struct wd_softc *wd =
-           device_lookup_private(&wd_cd, WDUNIT(bp->b_dev));
-       struct wd_ioctl *wi;
-
-       mutex_enter(&wd->sc_lock);
-       LIST_FOREACH(wi, &wd->wi_head, wi_list) {
-               if (bp == &wi->wi_bp)
-                       break;
-       }
-       mutex_exit(&wd->sc_lock);
-       return (wi);
+       return container_of(bp, struct wd_ioctl, wi_bp);
 }
 
 static uint
diff -r 78a639d74331 -r 4fb4c9abc70f sys/dev/ata/wdvar.h
--- a/sys/dev/ata/wdvar.h       Sat Apr 22 20:07:54 2017 +0000
+++ b/sys/dev/ata/wdvar.h       Sun Apr 23 01:21:04 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wdvar.h,v 1.43.4.4 2017/04/19 20:49:17 jdolecek Exp $  */
+/*     $NetBSD: wdvar.h,v 1.43.4.5 2017/04/23 01:21:04 jakllsch Exp $  */
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.
@@ -69,8 +69,6 @@
 #endif
        krndsource_t    rnd_source;
 
-       LIST_HEAD(, wd_ioctl) wi_head;
-
        STAILQ_HEAD(, ata_xfer) xfer_restart;
 };
 



Home | Main Index | Thread Index | Old Index