Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5162840pxb; Mon, 28 Mar 2022 08:48:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxENT2zmo6/Z1mnsaJCrv9V5U902rstA3iWYinve0Jsu+TjRlpmLBzCHOk4xoGta9PW/JlP X-Received: by 2002:a17:907:e87:b0:6df:6a26:e17c with SMTP id ho7-20020a1709070e8700b006df6a26e17cmr28460868ejc.666.1648482531627; Mon, 28 Mar 2022 08:48:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648482531; cv=none; d=google.com; s=arc-20160816; b=KQRkUIefx+GTgj5IZ0Vh2gSrNRXtkKimOq5/IINYXbaZHZ0pGAINYbExN8ZDXxmWdS tl9oFH4NOT3sVaQWXNyPUvvqaAmTAHOldISkgF/BbeIpj3iT9Iri7dLE3WHFG/IwFCxP F1o5JH1Y+DTyguZ1zbIyA0NJPhFHMBUdSAmobp4RNzfOTKiQHNe3XvD6/q8WDE6Eiu4b kXGAz8s3avdCxLq7x6QfNTM/3NL1LTAZdfh2vZcRo1xEz6l2NOnBT+Jpp+lWbL5nau/+ y+rzTkyvSP2UV702jW0jLygwXJa2Cd/pefNAm0IbOAh40qgE1zD4B9PBF39U3k/DIrsw u3Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=E+KxZQ752BVd2ImfGUChNoORANDur5uOtyX9U318ZBU=; b=CKPMqA9W1YPCyAKqd8g9fNtPzMfak8tkz4mU6qtfVZt7sovADRb/Wto/0GY33cZ9ms 7E9nWNXIHGPUaN7wZhxYG7X4LiRztlmRiJqAufta6Ezp5GRxNZsfSnpzEZ+cQkoh1Fb1 b1S/22UdFx/DxCbF5hVHuiVkLgJJw5AIO/r5yzTLKV07HvWuterFZJFAKxqWcEK6K4us hWlq/Wss7lFycpk3cIiJtfOgvx0PyiqqmVhA/n1N2HLR0tcuVT3Yfnv0ZAdOG44swJUc u/7sPRCD3MCnYAGUT9f+nHMtxiEBX79yHvMcR7PxHNDJqFXSldWNlHxQr3MAtNdirTg2 nvhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dk28-20020a0564021d9c00b00418c2b5bd8dsi13238281edb.111.2022.03.28.08.48.24; Mon, 28 Mar 2022 08:48:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238535AbiC1Gmx (ORCPT + 99 others); Mon, 28 Mar 2022 02:42:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238525AbiC1Gmw (ORCPT ); Mon, 28 Mar 2022 02:42:52 -0400 Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCF1A4ECC9; Sun, 27 Mar 2022 23:41:12 -0700 (PDT) Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 6C9991A02A8; Mon, 28 Mar 2022 08:41:11 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 356711A18DB; Mon, 28 Mar 2022 08:41:11 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 6F049183F0C8; Mon, 28 Mar 2022 14:41:10 +0800 (+08) From: Shengjiu Wang To: bjorn.andersson@linaro.org, mathieu.poirier@linaro.org Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, shengjiu.wang@gmail.com Subject: [PATCH] rpmsg: char: Add mutex protection for rpmsg_eptdev_open() Date: Mon, 28 Mar 2022 14:31:11 +0800 Message-Id: <1648449071-16959-1-git-send-email-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no mutex protection for rpmsg_eptdev_open(), especially for eptdev->ept read and write operation. It may cause issues when multiple instances call rpmsg_eptdev_open() in parallel, Signed-off-by: Shengjiu Wang --- drivers/rpmsg/rpmsg_char.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c index b6183d4f62a2..4f2189111494 100644 --- a/drivers/rpmsg/rpmsg_char.c +++ b/drivers/rpmsg/rpmsg_char.c @@ -120,8 +120,11 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp) struct rpmsg_device *rpdev = eptdev->rpdev; struct device *dev = &eptdev->dev; - if (eptdev->ept) + mutex_lock(&eptdev->ept_lock); + if (eptdev->ept) { + mutex_unlock(&eptdev->ept_lock); return -EBUSY; + } get_device(dev); @@ -137,11 +140,13 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp) if (!ept) { dev_err(dev, "failed to open %s\n", eptdev->chinfo.name); put_device(dev); + mutex_unlock(&eptdev->ept_lock); return -EINVAL; } eptdev->ept = ept; filp->private_data = eptdev; + mutex_unlock(&eptdev->ept_lock); return 0; } -- 2.17.1