From patchwork Thu Oct 5 03:51:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 114838 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp143801qgn; Wed, 4 Oct 2017 20:52:27 -0700 (PDT) X-Received: by 10.84.235.7 with SMTP id o7mr21254795plk.163.1507175547720; Wed, 04 Oct 2017 20:52:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507175547; cv=none; d=google.com; s=arc-20160816; b=DSYbeQIbSzZp4lWGc4mMHsujJTk22CGWWpcJgJTzwP+luTGQ6xb52XbZTS/roYrca0 vq+QFMFMhZK1XwAAHk8qtmaG+sxybgYn6PC9H0GRv2FJy9zpVIP74CSX9E7isGk9a10T wm6c72whbHcCd0NL2uEkJXDUFcqjtsfW7z5Aanwrbmz1rmipOwLy+5pXMtGmvy2uAAZr Y6OUUr9UAS/VE/XFym4aroFeW9g1GpY1NdAJ1UIgZ+/s2HT2mi2JXJ0etQ//6fscsGGZ 2fqMgpBuAFYIxSMbe770E4lmasEwjZ03HxH09fUxD+XxyNyrXPNX7ch45Cr6IrQxMkXU YdYA== 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=TP1EfqGEfPlEmtf5mJKJ8gtuotFSZnDfkpZqjCnAcug=; b=eCDtgH0tforh6uciszQzy6zhR/3TQzOLO++F2m6IlKRzm37XRylUCaHCkkZ8q6v/f0 oh2odpNkPPX2kxlKQOu2QyYSCX8ZcVCP09Q+mwcqk6Hky7raninpfxnW8hhECVONredO AUKKH2aQOuPWBKQ+HtmA7ITzoOTgjxu7FUMsnxxj+WK7NdsGwWDwUwoLGPicomKjWSRI TQbJEexHOv++ALfkOl2fpj7hfxFYHu4K7la/GVb9WvtahzI1ar3sbR5gTPPAzz+X5PFw VPuc4X9c/16zEVpfoG5DcsmOGy8ADvHsiPE4wWZGuU+spi3ORftIj7a8GWnakQR2wKds BLCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B3hHBJMt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 r12si1891704pgp.20.2017.10.04.20.52.27; Wed, 04 Oct 2017 20:52:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B3hHBJMt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752014AbdJEDw0 (ORCPT + 26 others); Wed, 4 Oct 2017 23:52:26 -0400 Received: from mail-pg0-f53.google.com ([74.125.83.53]:56415 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751880AbdJEDvQ (ORCPT ); Wed, 4 Oct 2017 23:51:16 -0400 Received: by mail-pg0-f53.google.com with SMTP id m18so1519432pgd.13 for ; Wed, 04 Oct 2017 20:51:15 -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=TP1EfqGEfPlEmtf5mJKJ8gtuotFSZnDfkpZqjCnAcug=; b=B3hHBJMtmRqVJWcgS3r20JLMORJ9p6GXxSDHZW0kEg5VsyPasfPbaH2287jhuMtCcq x23NDDXx3THASOefSrU4StHnxT7jvLMayCLhBYIMwSi03cCgg/GxUsM3A3hlyv1AcXJC HhVVeNu9xpKzJW1Qi/tqm2SqN79Rvid+Qytxc= 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=TP1EfqGEfPlEmtf5mJKJ8gtuotFSZnDfkpZqjCnAcug=; b=N9ZkBKErMNf2OU57h2llZWk/ayRUN6UNGyrlErFNERLCpAmytSF078Fpg/wQNFuIP4 3dSinRmiS49WtJXx4f3AEfpqFUHPMFY7wxD8kgVylobWWY8MC5cP9n57vwhBB9wQ60UC J9HkHU9y1BEruby+PlXO9rD+IK/0A4k3iqsk3ilLvNEJm4Zb1XHy1k65vLAGL61jEGF1 PC2oChw3UbpK9E5Ppnyz5eVlkQrL1rZpQvccXMdtvKshVzF31OA1TG5MBbCYx/I1c0Cu 2KRfNiONNlbb1DG3xTNtCj+DY2TGXeVIMQQYwnpuyL2oodUFmoX1lHu7+Bc+y68iBCeC H9UA== X-Gm-Message-State: AMCzsaVnrAVPiyQNEdMY5Kpjhs22NnDnYGseUuG+YNJoMu04Zq7A0/oG Olur6FXpeJA4D+XqZWfSSf492g== X-Google-Smtp-Source: AOwi7QB704wqjFNFfsh3gl0f4k33bzVGEszUkbiol3OfOlgZ/YK7v1h52nqahNQnQUTsCQ5QYE0qBA== X-Received: by 10.84.224.131 with SMTP id s3mr12253198plj.409.1507175475349; Wed, 04 Oct 2017 20:51:15 -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 f131sm13067035pfc.27.2017.10.04.20.51.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Oct 2017 20:51:14 -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: [RESEND PATCH 5/7] net: qrtr: Clean up control packet handling Date: Wed, 4 Oct 2017 20:51:03 -0700 Message-Id: <20171005035105.14677-6-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20171005035105.14677-1-bjorn.andersson@linaro.org> References: <20171005035105.14677-1-bjorn.andersson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index 82dc83789310..a84edba7b1ef 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);