Module Name:    src
Committed By:   thorpej
Date:           Sat Feb  1 20:56:17 UTC 2020

Modified Files:
        src/sys/net: if_media.c if_media.h

Log Message:
- 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.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/net/if_media.c
cvs rdiff -u -r1.68 -r1.69 src/sys/net/if_media.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_media.c
diff -u src/sys/net/if_media.c:1.50 src/sys/net/if_media.c:1.51
--- src/sys/net/if_media.c:1.50	Fri Jan 31 00:49:18 2020
+++ src/sys/net/if_media.c	Sat Feb  1 20:56:16 2020
@@ -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 @@ ifmedia_init(struct ifmedia *ifm, int do
 	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 @@ ifmedia_delete_instance(struct ifmedia *
 	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

Index: src/sys/net/if_media.h
diff -u src/sys/net/if_media.h:1.68 src/sys/net/if_media.h:1.69
--- src/sys/net/if_media.h:1.68	Thu Dec  5 05:29:27 2019
+++ src/sys/net/if_media.h	Sat Feb  1 20:56:16 2020
@@ -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 @@ struct ifmedia {
 /* 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. */

Reply via email to