Source-Changes-HG archive

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

[src/trunk]: src/sys/net - Add an ifmedia_fini() routine, to free resources a...



details:   https://anonhg.NetBSD.org/src/rev/72fcb9042659
branches:  trunk
changeset: 744452:72fcb9042659
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Feb 01 20:56:16 2020 +0000

description:
- Add an ifmedia_fini() routine, to free resources assocated with
  an ifmedia.  Currently calls ifmedia_removeall().  All drivers
  that call ifmedia_init() and support detach should call this
  routine.
- In ifmedia_delete_instance(), set ifm->ifm_cur to NULL and
  ifm->ifm_media to IFM_NONE when removing / freeing that entry,
  not simply when we've been asked to delete every media instance.

diffstat:

 sys/net/if_media.c |  22 ++++++++++++++++------
 sys/net/if_media.h |   5 ++++-
 2 files changed, 20 insertions(+), 7 deletions(-)

diffs (73 lines):

diff -r 8d49395b98e3 -r 72fcb9042659 sys/net/if_media.c
--- a/sys/net/if_media.c        Sat Feb 01 20:11:24 2020 +0000
+++ b/sys/net/if_media.c        Sat Feb 01 20:56:16 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_media.c,v 1.50 2020/01/31 00:49:18 thorpej Exp $    */
+/*     $NetBSD: if_media.c,v 1.51 2020/02/01 20:56:16 thorpej Exp $    */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.50 2020/01/31 00:49:18 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.51 2020/02/01 20:56:16 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -122,6 +122,16 @@
        ifm->ifm_status = status_callback;
 }
 
+/*
+ * Free resources associated with an ifmedia.
+ */
+void
+ifmedia_fini(struct ifmedia *ifm)
+{
+
+       ifmedia_removeall(ifm);
+}
+
 int
 ifmedia_change(struct ifmedia *ifm, struct ifnet *ifp)
 {
@@ -423,14 +433,14 @@
        TAILQ_FOREACH_SAFE(ife, &ifm->ifm_list, ifm_list, nife) {
                if (inst == IFM_INST_ANY ||
                    inst == IFM_INST(ife->ifm_media)) {
+                       if (ifm->ifm_cur == ife) {
+                               ifm->ifm_cur = NULL;
+                               ifm->ifm_media = IFM_NONE;
+                       }
                        TAILQ_REMOVE(&ifm->ifm_list, ife, ifm_list);
                        kmem_free(ife, sizeof(*ife));
                }
        }
-       if (inst == IFM_INST_ANY) {
-               ifm->ifm_cur = NULL;
-               ifm->ifm_media = IFM_NONE;
-       }
 }
 
 void
diff -r 8d49395b98e3 -r 72fcb9042659 sys/net/if_media.h
--- a/sys/net/if_media.h        Sat Feb 01 20:11:24 2020 +0000
+++ b/sys/net/if_media.h        Sat Feb 01 20:56:16 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_media.h,v 1.68 2019/12/05 05:29:27 msaitoh Exp $    */
+/*     $NetBSD: if_media.h,v 1.69 2020/02/01 20:56:16 thorpej Exp $    */
 
 /*-
  * Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
@@ -900,6 +900,9 @@
 /* Initialize an interface's struct if_media field. */
 void   ifmedia_init(struct ifmedia *, int, ifm_change_cb_t, ifm_stat_cb_t);
 
+/* Release resourecs associated with an ifmedia. */
+void   ifmedia_fini(struct ifmedia *);
+
 int    ifmedia_change(struct ifmedia *, struct ifnet *);
 
 /* Add one supported medium to a struct ifmedia. */



Home | Main Index | Thread Index | Old Index