Skip to content

Commit 1a7959c

Browse files
anderssondavem330
authored andcommitted
net: qrtr: Clean up control packet handling
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e704448 commit 1a7959c

File tree

1 file changed

+29
-64
lines changed

1 file changed

+29
-64
lines changed

net/qrtr/qrtr.c

Lines changed: 29 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -255,74 +255,26 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
255255
}
256256
EXPORT_SYMBOL_GPL(qrtr_endpoint_post);
257257

258-
static struct sk_buff *qrtr_alloc_ctrl_packet(u32 type, size_t pkt_len,
259-
u32 src_node, u32 dst_node)
258+
/**
259+
* qrtr_alloc_ctrl_packet() - allocate control packet skb
260+
* @pkt: reference to qrtr_ctrl_pkt pointer
261+
*
262+
* Returns newly allocated sk_buff, or NULL on failure
263+
*
264+
* This function allocates a sk_buff large enough to carry a qrtr_ctrl_pkt and
265+
* on success returns a reference to the control packet in @pkt.
266+
*/
267+
static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt)
260268
{
269+
const int pkt_len = sizeof(struct qrtr_ctrl_pkt);
261270
struct sk_buff *skb;
262271

263272
skb = alloc_skb(QRTR_HDR_SIZE + pkt_len, GFP_KERNEL);
264273
if (!skb)
265274
return NULL;
266275

267276
skb_reserve(skb, QRTR_HDR_SIZE);
268-
269-
return skb;
270-
}
271-
272-
/* Allocate and construct a resume-tx packet. */
273-
static struct sk_buff *qrtr_alloc_resume_tx(u32 src_node,
274-
u32 dst_node, u32 port)
275-
{
276-
const int pkt_len = 20;
277-
struct sk_buff *skb;
278-
__le32 *buf;
279-
280-
skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_RESUME_TX, pkt_len,
281-
src_node, dst_node);
282-
if (!skb)
283-
return NULL;
284-
285-
buf = skb_put_zero(skb, pkt_len);
286-
buf[0] = cpu_to_le32(QRTR_TYPE_RESUME_TX);
287-
buf[1] = cpu_to_le32(src_node);
288-
buf[2] = cpu_to_le32(port);
289-
290-
return skb;
291-
}
292-
293-
/* Allocate and construct a BYE message to signal remote termination */
294-
static struct sk_buff *qrtr_alloc_local_bye(u32 src_node)
295-
{
296-
const int pkt_len = 20;
297-
struct sk_buff *skb;
298-
__le32 *buf;
299-
300-
skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_BYE, pkt_len,
301-
src_node, qrtr_local_nid);
302-
if (!skb)
303-
return NULL;
304-
305-
buf = skb_put_zero(skb, pkt_len);
306-
buf[0] = cpu_to_le32(QRTR_TYPE_BYE);
307-
308-
return skb;
309-
}
310-
311-
static struct sk_buff *qrtr_alloc_del_client(struct sockaddr_qrtr *sq)
312-
{
313-
const int pkt_len = 20;
314-
struct sk_buff *skb;
315-
__le32 *buf;
316-
317-
skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_DEL_CLIENT, pkt_len,
318-
sq->sq_node, QRTR_NODE_BCAST);
319-
if (!skb)
320-
return NULL;
321-
322-
buf = skb_put_zero(skb, pkt_len);
323-
buf[0] = cpu_to_le32(QRTR_TYPE_DEL_CLIENT);
324-
buf[1] = cpu_to_le32(sq->sq_node);
325-
buf[2] = cpu_to_le32(sq->sq_port);
277+
*pkt = skb_put_zero(skb, pkt_len);
326278

327279
return skb;
328280
}
@@ -337,6 +289,7 @@ static void qrtr_port_put(struct qrtr_sock *ipc);
337289
static void qrtr_node_rx_work(struct work_struct *work)
338290
{
339291
struct qrtr_node *node = container_of(work, struct qrtr_node, work);
292+
struct qrtr_ctrl_pkt *pkt;
340293
struct sockaddr_qrtr dst;
341294
struct sockaddr_qrtr src;
342295
struct sk_buff *skb;
@@ -372,10 +325,14 @@ static void qrtr_node_rx_work(struct work_struct *work)
372325
}
373326

374327
if (confirm) {
375-
skb = qrtr_alloc_resume_tx(dst_node, node->nid, dst_port);
328+
skb = qrtr_alloc_ctrl_packet(&pkt);
376329
if (!skb)
377330
break;
378331

332+
pkt->cmd = cpu_to_le32(QRTR_TYPE_RESUME_TX);
333+
pkt->client.node = cpu_to_le32(dst.sq_node);
334+
pkt->client.port = cpu_to_le32(dst.sq_port);
335+
379336
if (qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX,
380337
&dst, &src))
381338
break;
@@ -429,16 +386,19 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)
429386
struct qrtr_node *node = ep->node;
430387
struct sockaddr_qrtr src = {AF_QIPCRTR, node->nid, QRTR_PORT_CTRL};
431388
struct sockaddr_qrtr dst = {AF_QIPCRTR, qrtr_local_nid, QRTR_PORT_CTRL};
389+
struct qrtr_ctrl_pkt *pkt;
432390
struct sk_buff *skb;
433391

434392
mutex_lock(&node->ep_lock);
435393
node->ep = NULL;
436394
mutex_unlock(&node->ep_lock);
437395

438396
/* Notify the local controller about the event */
439-
skb = qrtr_alloc_local_bye(node->nid);
440-
if (skb)
397+
skb = qrtr_alloc_ctrl_packet(&pkt);
398+
if (skb) {
399+
pkt->cmd = cpu_to_le32(QRTR_TYPE_BYE);
441400
qrtr_local_enqueue(NULL, skb, QRTR_TYPE_BYE, &src, &dst);
401+
}
442402

443403
qrtr_node_release(node);
444404
ep->node = NULL;
@@ -474,6 +434,7 @@ static void qrtr_port_put(struct qrtr_sock *ipc)
474434
/* Remove port assignment. */
475435
static void qrtr_port_remove(struct qrtr_sock *ipc)
476436
{
437+
struct qrtr_ctrl_pkt *pkt;
477438
struct sk_buff *skb;
478439
int port = ipc->us.sq_port;
479440
struct sockaddr_qrtr to;
@@ -482,8 +443,12 @@ static void qrtr_port_remove(struct qrtr_sock *ipc)
482443
to.sq_node = QRTR_NODE_BCAST;
483444
to.sq_port = QRTR_PORT_CTRL;
484445

485-
skb = qrtr_alloc_del_client(&ipc->us);
446+
skb = qrtr_alloc_ctrl_packet(&pkt);
486447
if (skb) {
448+
pkt->cmd = cpu_to_le32(QRTR_TYPE_DEL_CLIENT);
449+
pkt->client.node = cpu_to_le32(ipc->us.sq_node);
450+
pkt->client.port = cpu_to_le32(ipc->us.sq_port);
451+
487452
skb_set_owner_w(skb, &ipc->sk);
488453
qrtr_bcast_enqueue(NULL, skb, QRTR_TYPE_DEL_CLIENT, &ipc->us,
489454
&to);

0 commit comments

Comments
 (0)