Source-Changes-HG archive

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

[src/trunk]: src/sys/sys Tweak m_get_rcvif



details:   https://anonhg.NetBSD.org/src/rev/1caf79b18d5e
branches:  trunk
changeset: 351209:1caf79b18d5e
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Tue Feb 07 02:36:48 2017 +0000

description:
Tweak m_get_rcvif

Call pserialize_read_exit if if_byindex returns NULL in m_get_rcvif.
By changing so, callers need to call m_put_rcvif only if m_get_rcvif
returns non-NULL.

Old m_get_rcvif/m_put_rcvif could forget to call pserialize_read_exit,
which is pointed out by maxv@. The change fixes it.

diffstat:

 sys/sys/mbuf.h |  18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diffs (38 lines):

diff -r c74f6dea9a45 -r 1caf79b18d5e sys/sys/mbuf.h
--- a/sys/sys/mbuf.h    Tue Feb 07 02:33:54 2017 +0000
+++ b/sys/sys/mbuf.h    Tue Feb 07 02:36:48 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mbuf.h,v 1.167 2016/10/04 14:13:21 christos Exp $      */
+/*     $NetBSD: mbuf.h,v 1.168 2017/02/07 02:36:48 ozaki-r Exp $       */
 
 /*-
  * Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
@@ -1006,16 +1006,24 @@
 /*
  * Get rcvif of a mbuf.
  *
- * The caller must call m_put_rcvif after using rcvif. The caller cannot
- * block or sleep during using rcvif. Insofar as the constraint is satisfied,
- * the API ensures a got rcvif isn't be freed until m_put_rcvif is called.
+ * The caller must call m_put_rcvif after using rcvif if the returned rcvif
+ * isn't NULL. If the returned rcvif is NULL, the caller doesn't need to call
+ * m_put_rcvif (although calling it is safe).
+ *
+ * The caller must not block or sleep while using rcvif. The API ensures a
+ * returned rcvif isn't freed until m_put_rcvif is called.
  */
 static __inline struct ifnet *
 m_get_rcvif(const struct mbuf *m, int *s)
 {
+       struct ifnet *ifp;
 
        *s = pserialize_read_enter();
-       return if_byindex(m->m_pkthdr.rcvif_index);
+       ifp = if_byindex(m->m_pkthdr.rcvif_index);
+       if (__predict_false(ifp == NULL))
+               pserialize_read_exit(*s);
+
+       return ifp;
 }
 
 static __inline void



Home | Main Index | Thread Index | Old Index