From owner-svn-src-all@FreeBSD.ORG Mon Jan 19 22:06:35 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 71BC41065674; Mon, 19 Jan 2009 22:06:35 +0000 (UTC) (envelope-from emax@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5E9268FC26; Mon, 19 Jan 2009 22:06:35 +0000 (UTC) (envelope-from emax@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n0JM6Z1C023097; Mon, 19 Jan 2009 22:06:35 GMT (envelope-from emax@svn.freebsd.org) Received: (from emax@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n0JM6Znx023096; Mon, 19 Jan 2009 22:06:35 GMT (envelope-from emax@svn.freebsd.org) Message-Id: <200901192206.n0JM6Znx023096@svn.freebsd.org> From: Maksim Yevmenkin Date: Mon, 19 Jan 2009 22:06:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r187454 - head/sys/netgraph/bluetooth/l2cap X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Jan 2009 22:06:36 -0000 Author: emax Date: Mon Jan 19 22:06:35 2009 New Revision: 187454 URL: http://svn.freebsd.org/changeset/base/187454 Log: Properly return error code to the caller. This should fix the following panic in ng_l2cap(4). panic: ng_l2cap_l2ca_con_req: ubt0l2cap - could not find connection! While i'm here get rid of few goto's. MFC after: 1 week Modified: head/sys/netgraph/bluetooth/l2cap/ng_l2cap_llpi.c Modified: head/sys/netgraph/bluetooth/l2cap/ng_l2cap_llpi.c ============================================================================== --- head/sys/netgraph/bluetooth/l2cap/ng_l2cap_llpi.c Mon Jan 19 21:49:46 2009 (r187453) +++ head/sys/netgraph/bluetooth/l2cap/ng_l2cap_llpi.c Mon Jan 19 22:06:35 2009 (r187454) @@ -116,10 +116,14 @@ ng_l2cap_lp_con_req(ng_l2cap_p l2cap, bd NG_SEND_MSG_HOOK(error, l2cap->node, msg, l2cap->hci, 0); if (error != 0) { - if ((error = ng_l2cap_lp_untimeout(con)) != 0) - return (error); + if (ng_l2cap_lp_untimeout(con) == 0) + ng_l2cap_free_con(con); - ng_l2cap_free_con(con); + /* + * Do not free connection if ng_l2cap_lp_untimeout() failed + * let timeout handler deal with it. Always return error to + * the caller. + */ } return (error); @@ -213,8 +217,8 @@ ng_l2cap_lp_con_ind(ng_l2cap_p l2cap, st NG_L2CAP_ALERT( "%s: %s - invalid LP_ConnectInd message size\n", __func__, NG_NODE_NAME(l2cap->node)); - error = EMSGSIZE; - goto out; + + return (EMSGSIZE); } ep = (ng_hci_lp_con_ind_ep *) (msg->data); @@ -227,8 +231,8 @@ ng_l2cap_lp_con_ind(ng_l2cap_p l2cap, st "Connection already exists, state=%d, con_handle=%d\n", __func__, NG_NODE_NAME(l2cap->node), con->state, con->con_handle); - error = EEXIST; - goto out; + + return (EEXIST); } /* Check if lower layer protocol is still connected */ @@ -236,24 +240,22 @@ ng_l2cap_lp_con_ind(ng_l2cap_p l2cap, st NG_L2CAP_ERR( "%s: %s - hook \"%s\" is not connected or valid", __func__, NG_NODE_NAME(l2cap->node), NG_L2CAP_HOOK_HCI); - error = ENOTCONN; - goto out; + + return (ENOTCONN); } /* Create and intialize new connection descriptor */ con = ng_l2cap_new_con(l2cap, &ep->bdaddr); - if (con == NULL) { - error = ENOMEM; - goto out; - } + if (con == NULL) + return (ENOMEM); /* Create and send LP_ConnectRsp event */ NG_MKMESSAGE(rsp, NGM_HCI_COOKIE, NGM_HCI_LP_CON_RSP, sizeof(*rp), M_NOWAIT); if (rsp == NULL) { ng_l2cap_free_con(con); - error = ENOMEM; - goto out; + + return (ENOMEM); } rp = (ng_hci_lp_con_rsp_ep *)(rsp->data); @@ -266,14 +268,18 @@ ng_l2cap_lp_con_ind(ng_l2cap_p l2cap, st NG_SEND_MSG_HOOK(error, l2cap->node, rsp, l2cap->hci, 0); if (error != 0) { - if ((error = ng_l2cap_lp_untimeout(con)) != 0) - goto out; + if (ng_l2cap_lp_untimeout(con) == 0) + ng_l2cap_free_con(con); - ng_l2cap_free_con(con); + /* + * Do not free connection if ng_l2cap_lp_untimeout() failed + * let timeout handler deal with it. Always return error to + * the caller. + */ } -out: + return (error); -} /* ng_hci_lp_con_ind */ +} /* ng_l2cap_lp_con_ind */ /* * Process LP_DisconnectInd event from the lower layer protocol. We have been