Module Name: src Committed By: ozaki-r Date: Tue Feb 7 02:36:48 UTC 2017
Modified Files: src/sys/sys: mbuf.h Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.167 -r1.168 src/sys/sys/mbuf.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/sys/mbuf.h diff -u src/sys/sys/mbuf.h:1.167 src/sys/sys/mbuf.h:1.168 --- src/sys/sys/mbuf.h:1.167 Tue Oct 4 14:13:21 2016 +++ src/sys/sys/mbuf.h Tue Feb 7 02:36:48 2017 @@ -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 @@ void m_print(const struct mbuf *, const /* * 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