]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/6.0.3/rpmsg-char-avoid-double-destroy-of-default-endpoint.patch
Drop nfc patches from older trees
[thirdparty/kernel/stable-queue.git] / releases / 6.0.3 / rpmsg-char-avoid-double-destroy-of-default-endpoint.patch
CommitLineData
20d0511e
GKH
1From 467233a4ac29b215d492843d067a9f091e6bf0c5 Mon Sep 17 00:00:00 2001
2From: Shengjiu Wang <shengjiu.wang@nxp.com>
3Date: Wed, 21 Sep 2022 09:58:43 +0800
4Subject: rpmsg: char: Avoid double destroy of default endpoint
5
6From: Shengjiu Wang <shengjiu.wang@nxp.com>
7
8commit 467233a4ac29b215d492843d067a9f091e6bf0c5 upstream.
9
10The rpmsg_dev_remove() in rpmsg_core is the place for releasing
11this default endpoint.
12
13So need to avoid destroying the default endpoint in
14rpmsg_chrdev_eptdev_destroy(), this should be the same as
15rpmsg_eptdev_release(). Otherwise there will be double destroy
16issue that ept->refcount report warning:
17
18refcount_t: underflow; use-after-free.
19
20Call trace:
21 refcount_warn_saturate+0xf8/0x150
22 virtio_rpmsg_destroy_ept+0xd4/0xec
23 rpmsg_dev_remove+0x60/0x70
24
25The issue can be reproduced by stopping remoteproc before
26closing the /dev/rpmsgX.
27
28Fixes: bea9b79c2d10 ("rpmsg: char: Add possibility to use default endpoint of the rpmsg device")
29Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
30Reviewed-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
31Reviewed-by: Peng Fan <peng.fan@nxp.com>
32Cc: stable <stable@vger.kernel.org>
33Link: https://lore.kernel.org/r/1663725523-6514-1-git-send-email-shengjiu.wang@nxp.com
34Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
35Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
36---
37 drivers/rpmsg/rpmsg_char.c | 4 +++-
38 1 file changed, 3 insertions(+), 1 deletion(-)
39
40--- a/drivers/rpmsg/rpmsg_char.c
41+++ b/drivers/rpmsg/rpmsg_char.c
42@@ -76,7 +76,9 @@ int rpmsg_chrdev_eptdev_destroy(struct d
43
44 mutex_lock(&eptdev->ept_lock);
45 if (eptdev->ept) {
46- rpmsg_destroy_ept(eptdev->ept);
47+ /* The default endpoint is released by the rpmsg core */
48+ if (!eptdev->default_ept)
49+ rpmsg_destroy_ept(eptdev->ept);
50 eptdev->ept = NULL;
51 }
52 mutex_unlock(&eptdev->ept_lock);