Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1648005ioo; Sun, 22 May 2022 22:57:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/IYsG45W////rr22l2Mg0g/CS9dj8WNW0SQunC3r3awTXf9+X+2LcPQ0GsQjAR1ru6Rxz X-Received: by 2002:a17:902:74cc:b0:161:8f4d:17b8 with SMTP id f12-20020a17090274cc00b001618f4d17b8mr21663403plt.96.1653285457465; Sun, 22 May 2022 22:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653285457; cv=none; d=google.com; s=arc-20160816; b=CXkA6vRpGH7FecwaO3ROFdsLMlrkY1+BLbK3WxYn+8Aa2V3iPylAeM/j/j4d+k0GAY ojiAb0MYtcGUB25wMJWrgfDcKkz6scaTXqGByXNW1JFgwPNp9hofKn/HcRlpIEgi3ClK 54Gh/ovBdof8qr20Oj7BHr8PIclwZWZJPVgu4gb5jSSEpB7OL3ngdOvPSGIOyDnVEY35 zaoAxiQg1WPSMXjdzFS2K7P0ZxE0W0ctE31cM/ziHxsuaO15zuMx3R7D3xIfs3AFKQxS rU0onzaE+F8gbBMbN52gqcFaT02eHJuAwpA9OJEjeSG9IK/jMz41+7RBPsY/qZFeFCjl CGjg== 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=7aeS6HculHl4qI03qom5YEEIPBsq+Mk/Q08ZjEhkH2E=; b=IiZUW1o4tEQmOUqIwIgkiubBveHSVCgsmpCG0Tqeqrahwhtz0KdpqbceixhK0g4ruQ QUujUZ4kVaU2cIDgOoJ/EuFc6R/o9CkONYoP7Th3iwDEU0WSPQv1VwrvamKDMQQfxsLk e9WTlWmw7dSFLKtd74mDP1Kl5/+OzGynS0dOCdcU/BNmjtkl3BQnw+iQRWUqDPyjtEpk FhCsyiu3693sWO81UZiioAca/aI396uPqbhwV02Twi3tJBOGX+bAveiWl5cAZE1mHTpY 4qtVP67P+Gg29tOk/oDt1BGUexiGk1jdoqff2hzKlnNj4UaxKX+/yaRuEQT/UkFjgdbX kL1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h185-20020a6383c2000000b003fa3f7ea593si4173011pge.800.2022.05.22.22.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 May 2022 22:57:37 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 66D832C667; Sun, 22 May 2022 22:53:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345415AbiEUDrw (ORCPT + 99 others); Fri, 20 May 2022 23:47:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229773AbiEUDrt (ORCPT ); Fri, 20 May 2022 23:47:49 -0400 Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D3D8187DB4; Fri, 20 May 2022 20:47:48 -0700 (PDT) Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id D4DAD1A0740; Sat, 21 May 2022 05:47:46 +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 9F16F1A02E1; Sat, 21 May 2022 05:47:46 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 7CD7D180031E; Sat, 21 May 2022 11:47:45 +0800 (+08) From: Shengjiu Wang To: bjorn.andersson@linaro.org, mathieu.poirier@linaro.org, arnaud.pouliquen@foss.st.com Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, shengjiu.wang@gmail.com Subject: [RESEND PATCH] rpmsg: char: Add mutex protection for rpmsg_eptdev_open() Date: Sat, 21 May 2022 11:35:05 +0800 Message-Id: <1653104105-16779-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=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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,the return state may be success or EBUGY. Fixes: 964e8bedd5a1 ("rpmsg: char: Return an error if device already open") Signed-off-by: Shengjiu Wang --- changes in resend: - add fixes tag 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