From patchwork Thu Sep 7 06:03:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 111856 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp356765qge; Wed, 6 Sep 2017 23:03:46 -0700 (PDT) X-Received: by 10.99.100.4 with SMTP id y4mr1594890pgb.147.1504764226669; Wed, 06 Sep 2017 23:03:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504764226; cv=none; d=google.com; s=arc-20160816; b=CwN5o7NG6j4Y054rJQRZXMWakv+jKgfYJtUpKSMzj8hNYtUU6Y4lq0+qnaHQnaI8uG IxlD4s+cs4dk6LUAeAZxANbB8/1GONj6km4rvyX2YP2m+iiVSSObMNOECXEJnaRWlQMP N1AwW2SzsxAOmVEV5LOSEAMXpBToYZRaCQADLgIRdl+3/ZGD1ookUis5pDKfcYRFNXTA xTfYY5N50KjWCaypmQF5Wgxveq29QiitdC66sAnjL0WkgnrD1IJRFI0dDWFlBzpMpeiP K6eAvr4ohXOQEVDFujY2IywljKPqjlGGOMcVp+0gnip0Q28wQD8nEbSIqpKSviqvo8FQ 3/+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=M5LNnd2dxJDJRxZCLUuOEe3ps2Ag9SoXuQay1gipq6w=; b=y512+J5b3gUP+T2Aw3BEV50NiqysJyPxESFYSrj5vcupYSMMzlrkXc/mfNwpnxOHBy zThgjmJsy/btXFEus4wPwEXMkjrQBeHFy4bcvFHViZzigt3g9MQ7clGzOfyCnru/gYcF mbZcgzj2BGw8CIYLgAwSk9H39DfFV3+iQRJCxEx1pltDUMdWH2LAbZKf7sBeNK6LuPM6 vT690Mq1KeJ84LgGWLpL7FQafjgGUBkPRFQwiYk6rpWiBkuMUvdDO3Tv+UR8npuo0rDz s7JsbjxFGHPclRbamlMVRBpI4tyvuuXkrC6SkBJT5pov5gDSH7BVTailwKwXq+XjBJFr zIUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KL99S8ED; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u189si1293523pgb.161.2017.09.06.23.03.46; Wed, 06 Sep 2017 23:03:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KL99S8ED; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754024AbdIGGDl (ORCPT + 9 others); Thu, 7 Sep 2017 02:03:41 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:34607 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754018AbdIGGDk (ORCPT ); Thu, 7 Sep 2017 02:03:40 -0400 Received: by mail-pg0-f54.google.com with SMTP id q68so3394527pgq.1 for ; Wed, 06 Sep 2017 23:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PArY59lIP4ZSAJXU+tDGGdjXKm4RhjsqdGDEnt3VAhk=; b=KL99S8EDl1wGZcF2OyCFdwc2e/S0mkD5wCfsVIAO39HeZbz+Zmw3MKIiGLidJl9gKi VwuOs44McIZ2t8ZoweBpVDtWzMv4hFtxHa1D3MUExFLXgw/MWvspHx7id5HOfN4S+rrZ y3I2XTSqk1zKG1rUN6lQDqF87zbN4gZYCRpkA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PArY59lIP4ZSAJXU+tDGGdjXKm4RhjsqdGDEnt3VAhk=; b=NcsnwIr4Tmaolu5MSEsDl8qgcoo8MclE5YeaYRvBXX4ejCSYsGLQShQ/XxVW/iwHt4 ppX5F4Kq8m0pOiJ6i1EouTfQ9n0u5y0RyrCAQv5iLGAEureppnEUnWNKKrOaeconvLc2 f+e9zwt53sidy8mm472dGFTn0TTISqeAzIbKfkByLTvVstqmW6VYftnfXJltqtaOTSEq b+cTLjShElatK1r784sBfIi2TObLIoj3q9KbpZUnKpLHy7noZm7Aa6mcqdY0K2sLTNua ehRDIl3/f9IOpPtPFp4AvTamRHBLKffv0LqV8w+kmkyIfQKf/GcdZF8w3V8tkbmLN88E +5pw== X-Gm-Message-State: AHPjjUhJhmc+JYwqz7/WFqV4+VuwCuLfKjL3X5K87Mt1iBMjeVwaHN4G qanYC5K6BATIVP5g X-Google-Smtp-Source: ADKCNb4i8uxLGBJJrW12oYYHdKO5pUZNkOFquw/cyaFOLRuWBPAxHBVWXR20Yvw3/gRF2mWxGkggPQ== X-Received: by 10.98.208.69 with SMTP id p66mr1665105pfg.6.1504764219466; Wed, 06 Sep 2017 23:03:39 -0700 (PDT) Received: from localhost.localdomain (ip68-111-217-79.sd.sd.cox.net. [68.111.217.79]) by smtp.gmail.com with ESMTPSA id s1sm2186650pfk.27.2017.09.06.23.03.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Sep 2017 23:03:38 -0700 (PDT) From: Bjorn Andersson To: "David S. Miller" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Chris Lew Subject: [PATCH 5/7] net: qrtr: Clean up control packet handling Date: Wed, 6 Sep 2017 23:03:27 -0700 Message-Id: <20170907060329.32402-6-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170907060329.32402-1-bjorn.andersson@linaro.org> References: <20170907060329.32402-1-bjorn.andersson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org As the message header generation is deferred the internal functions for generating control packets can be simplified. This patch modifies qrtr_alloc_ctrl_packet() to, in addition to the sk_buff, return a reference to a struct qrtr_ctrl_pkt, which clarifies and simplifies the helpers to the point that these functions can be folded back into the callers. Signed-off-by: Bjorn Andersson --- net/qrtr/qrtr.c | 93 ++++++++++++++++++--------------------------------------- 1 file changed, 29 insertions(+), 64 deletions(-) -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index bcec2432b833..f28ecd7d735b 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -255,9 +255,18 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) } EXPORT_SYMBOL_GPL(qrtr_endpoint_post); -static struct sk_buff *qrtr_alloc_ctrl_packet(u32 type, size_t pkt_len, - u32 src_node, u32 dst_node) +/** + * qrtr_alloc_ctrl_packet() - allocate control packet skb + * @pkt: reference to qrtr_ctrl_pkt pointer + * + * Returns newly allocated sk_buff, or NULL on failure + * + * This function allocates a sk_buff large enough to carry a qrtr_ctrl_pkt and + * on success returns a reference to the control packet in @pkt. + */ +static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt) { + const int pkt_len = sizeof(struct qrtr_ctrl_pkt); struct sk_buff *skb; skb = alloc_skb(QRTR_HDR_SIZE + pkt_len, GFP_KERNEL); @@ -265,64 +274,7 @@ static struct sk_buff *qrtr_alloc_ctrl_packet(u32 type, size_t pkt_len, return NULL; skb_reserve(skb, QRTR_HDR_SIZE); - - return skb; -} - -/* Allocate and construct a resume-tx packet. */ -static struct sk_buff *qrtr_alloc_resume_tx(u32 src_node, - u32 dst_node, u32 port) -{ - const int pkt_len = 20; - struct sk_buff *skb; - __le32 *buf; - - skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_RESUME_TX, pkt_len, - src_node, dst_node); - if (!skb) - return NULL; - - buf = skb_put_zero(skb, pkt_len); - buf[0] = cpu_to_le32(QRTR_TYPE_RESUME_TX); - buf[1] = cpu_to_le32(src_node); - buf[2] = cpu_to_le32(port); - - return skb; -} - -/* Allocate and construct a BYE message to signal remote termination */ -static struct sk_buff *qrtr_alloc_local_bye(u32 src_node) -{ - const int pkt_len = 20; - struct sk_buff *skb; - __le32 *buf; - - skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_BYE, pkt_len, - src_node, qrtr_local_nid); - if (!skb) - return NULL; - - buf = skb_put_zero(skb, pkt_len); - buf[0] = cpu_to_le32(QRTR_TYPE_BYE); - - return skb; -} - -static struct sk_buff *qrtr_alloc_del_client(struct sockaddr_qrtr *sq) -{ - const int pkt_len = 20; - struct sk_buff *skb; - __le32 *buf; - - skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_DEL_CLIENT, pkt_len, - sq->sq_node, QRTR_NODE_BCAST); - if (!skb) - return NULL; - - buf = skb_put_zero(skb, pkt_len); - buf[0] = cpu_to_le32(QRTR_TYPE_DEL_CLIENT); - buf[1] = cpu_to_le32(sq->sq_node); - buf[2] = cpu_to_le32(sq->sq_port); + *pkt = skb_put_zero(skb, pkt_len); return skb; } @@ -337,6 +289,7 @@ static void qrtr_port_put(struct qrtr_sock *ipc); static void qrtr_node_rx_work(struct work_struct *work) { struct qrtr_node *node = container_of(work, struct qrtr_node, work); + struct qrtr_ctrl_pkt *pkt; struct sockaddr_qrtr dst; struct sockaddr_qrtr src; struct sk_buff *skb; @@ -372,10 +325,14 @@ static void qrtr_node_rx_work(struct work_struct *work) } if (confirm) { - skb = qrtr_alloc_resume_tx(dst_node, node->nid, dst_port); + skb = qrtr_alloc_ctrl_packet(&pkt); if (!skb) break; + pkt->cmd = cpu_to_le32(QRTR_TYPE_RESUME_TX); + pkt->client.node = cpu_to_le32(dst.sq_node); + pkt->client.port = cpu_to_le32(dst.sq_port); + if (qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX, &dst, &src)) break; @@ -429,6 +386,7 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep) struct qrtr_node *node = ep->node; struct sockaddr_qrtr src = {AF_QIPCRTR, node->nid, QRTR_PORT_CTRL}; struct sockaddr_qrtr dst = {AF_QIPCRTR, qrtr_local_nid, QRTR_PORT_CTRL}; + struct qrtr_ctrl_pkt *pkt; struct sk_buff *skb; mutex_lock(&node->ep_lock); @@ -436,9 +394,11 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep) mutex_unlock(&node->ep_lock); /* Notify the local controller about the event */ - skb = qrtr_alloc_local_bye(node->nid); - if (skb) + skb = qrtr_alloc_ctrl_packet(&pkt); + if (skb) { + pkt->cmd = cpu_to_le32(QRTR_TYPE_BYE); qrtr_local_enqueue(NULL, skb, QRTR_TYPE_BYE, &src, &dst); + } qrtr_node_release(node); ep->node = NULL; @@ -474,6 +434,7 @@ static void qrtr_port_put(struct qrtr_sock *ipc) /* Remove port assignment. */ static void qrtr_port_remove(struct qrtr_sock *ipc) { + struct qrtr_ctrl_pkt *pkt; struct sk_buff *skb; int port = ipc->us.sq_port; struct sockaddr_qrtr to; @@ -482,8 +443,12 @@ static void qrtr_port_remove(struct qrtr_sock *ipc) to.sq_node = QRTR_NODE_BCAST; to.sq_port = QRTR_PORT_CTRL; - skb = qrtr_alloc_del_client(&ipc->us); + skb = qrtr_alloc_ctrl_packet(&pkt); if (skb) { + pkt->cmd = cpu_to_le32(QRTR_TYPE_DEL_CLIENT); + pkt->client.node = cpu_to_le32(ipc->us.sq_node); + pkt->client.port = cpu_to_le32(ipc->us.sq_port); + skb_set_owner_w(skb, &ipc->sk); qrtr_bcast_enqueue(NULL, skb, QRTR_TYPE_DEL_CLIENT, &ipc->us, &to);