From daa0f471a9a7bc0f9329327fe7645ee78048b556 Mon Sep 17 00:00:00 2001 From: Chris Lew Date: Thu, 28 Jan 2021 16:59:20 -0800 Subject: [PATCH 1/2] net: neuron: channel: Move waitq init Initialize the waitq before registering with the doorbell framework to prevent uninitialized variable access. Change-Id: Icb902b829a6af52716713b18891e4e35c0c2a620 Signed-off-by: Chris Lew --- net/neuron/channel/ch_haven_recv.c | 5 ++--- net/neuron/channel/ch_haven_send.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/net/neuron/channel/ch_haven_recv.c b/net/neuron/channel/ch_haven_recv.c index 1422491b9bde..2359343fa009 100644 --- a/net/neuron/channel/ch_haven_recv.c +++ b/net/neuron/channel/ch_haven_recv.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -/* Copyright (c) 2020 The Linux Foundation. All rights reserved. */ +/* Copyright (c) 2020-2021 The Linux Foundation. All rights reserved. */ #include #include @@ -479,6 +479,7 @@ static int channel_hh_probe(struct neuron_channel *cdev) if (!priv) return -ENOMEM; priv->dev = cdev; + init_waitqueue_head(&priv->wait_q); ret = of_property_read_u32(node, "haven-label", &priv->haven_label); if (ret) { @@ -507,8 +508,6 @@ static int channel_hh_probe(struct neuron_channel *cdev) dev_err(dev, "failed to get haven rx dbl %d\n", ret); goto fail_rx_dbl; } - - init_waitqueue_head(&priv->wait_q); /* Start the thread for syncing with the sender. */ priv->sync_thread = kthread_run(channel_sync_thread, priv, "recv_sync_thread"); diff --git a/net/neuron/channel/ch_haven_send.c b/net/neuron/channel/ch_haven_send.c index 37ab21e15495..d0bd569b789b 100644 --- a/net/neuron/channel/ch_haven_send.c +++ b/net/neuron/channel/ch_haven_send.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -/* Copyright (c) 2020 The Linux Foundation. All rights reserved. */ +/* Copyright (c) 2020-2021 The Linux Foundation. All rights reserved. */ #include #include @@ -464,6 +464,7 @@ static int channel_hh_probe(struct neuron_channel *cdev) if (!priv) return -ENOMEM; priv->dev = cdev; + init_waitqueue_head(&priv->wait_q); ret = of_property_read_u32(node, "haven-label", &priv->haven_label); if (ret) { @@ -490,8 +491,6 @@ static int channel_hh_probe(struct neuron_channel *cdev) dev_err(dev, "failed to get haven rx dbl %d\n", ret); goto fail_rx_dbl; } - - init_waitqueue_head(&priv->wait_q); /* Start the thread for syncing with the receiver. */ priv->sync_thread = kthread_run(channel_sync_thread, priv, "send_sync_thread"); From 4b705a80723102adc94a8f3264723a069571df5d Mon Sep 17 00:00:00 2001 From: Chris Lew Date: Thu, 28 Jan 2021 17:10:52 -0800 Subject: [PATCH 2/2] net: qrtr: haven: Rearrange init order Doorbells can be received immediately after registering. Ensure the qrtr endpoint has been registered and initialized before enabling the rx doorbell. The tx doorbell should be done before registering the endpoint since the qrtr core logic can attempt to send immediately after registration. Change-Id: Ice332b4a053ea6e78bfded1e3625d8c527917e7b Signed-off-by: Chris Lew --- net/qrtr/haven.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/net/qrtr/haven.c b/net/qrtr/haven.c index 8065eb404865..b37e779c7e7f 100644 --- a/net/qrtr/haven.c +++ b/net/qrtr/haven.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -/* Copyright (c) 2020, The Linux Foundation. All rights reserved. */ +/* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. */ #define pr_fmt(fmt) "%s: " fmt, __func__ @@ -603,6 +603,11 @@ static int qrtr_haven_probe(struct platform_device *pdev) } INIT_WORK(&qdev->work, qrtr_haven_retry_work); + qdev->ep.xmit = qrtr_haven_send; + ret = qrtr_endpoint_register(&qdev->ep, QRTR_EP_NET_ID_AUTO, false); + if (ret) + goto register_fail; + qdev->rx_dbl = hh_dbl_rx_register(dbl_label, qrtr_haven_cb, qdev); if (IS_ERR_OR_NULL(qdev->rx_dbl)) { ret = PTR_ERR(qdev->rx_dbl); @@ -610,19 +615,14 @@ static int qrtr_haven_probe(struct platform_device *pdev) goto fail_rx_dbl; } - qdev->ep.xmit = qrtr_haven_send; - ret = qrtr_endpoint_register(&qdev->ep, QRTR_EP_NET_ID_AUTO, false); - if (ret) - goto register_fail; - if (haven_rx_avail(&qdev->rx_pipe)) qrtr_haven_read(qdev); return 0; -register_fail: - hh_dbl_rx_unregister(qdev->rx_dbl); fail_rx_dbl: + qrtr_endpoint_unregister(&qdev->ep); +register_fail: cancel_work_sync(&qdev->work); hh_dbl_tx_unregister(qdev->tx_dbl);