Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5072569pxv; Tue, 20 Jul 2021 18:46:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4VWn1enO8ca83r8/sUNaAV5viI6o2n2KJ2jKVdvVCrvFLOHq/6miaVLxAmJx3QkTDfQ3B X-Received: by 2002:a02:380c:: with SMTP id b12mr28767244jaa.68.1626831969847; Tue, 20 Jul 2021 18:46:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626831969; cv=none; d=google.com; s=arc-20160816; b=fPwzE78l1DH0toDLcBrhjvqAmi7i08gE0+EugyQpOe7kaVY9VyyAWP9j/Es/sFWtB7 0ok1qAa4XKKAPyxi+4XyndU2R4fWxRRC8TJANYwtxpVJR4LJrRtPVdXKNSUH3LIoVoV2 JRXOb7Ih5OMtviESCoz2wtg1k8nYeAdndd/MROFQz44W+inoX+a/SHIoEnLguS2GRyaq 0ydXh/rpqJBrN7DvL/vstnz4ib9C3uBPetg/0AGOgphTStmmVVHFASk6nO2uWOIXt6vw mKX6myZOq34YI5tAHtKTiqkoT6aVAa9lBBYP8UesCrT6+o5cAYJwwfrxFUlxMbHtBjtG W4Ww== 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:dmarc-filter :sender:dkim-signature; bh=mtzWCbrz+cE9oYupzBvuDqsFyd7ZcoJ86HtTVGOmLiE=; b=PzxOjSMDXWRQwmNh5kDiaaI3I5IFcxZ0RCWxbt5/1LzC0TsAz3rkqWDBGIA8to723F GZMqfR87w0hBqZzmvglhCD5kftb3S6+JS0+97MOd51m23yXaXJb7UO/cNhZi3KSXxRk3 VrnrK2PytaDpC9fBUD3cOX9O6RxfUPdCj3WpEDZj3VgIlFoaWHDCFJN4sr7jLa4G0njT GNKIpgl+CqK2rpNC2Nnm5g5TLxTbjFh9BQ1ehjh9u/zsUA5vcN3xWhaJ6KjjFGDsgmOO EwvxxRpxrxjGJTI2YBHWSKUrcYIMTZQK3zmr2tOFEH+olS6wsZLRifPCb+ncLprthcLo Yiqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=NwBcS0yd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v8si15481198jas.68.2021.07.20.18.45.58; Tue, 20 Jul 2021 18:46:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=NwBcS0yd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231196AbhGUBC7 (ORCPT + 99 others); Tue, 20 Jul 2021 21:02:59 -0400 Received: from so254-9.mailgun.net ([198.61.254.9]:10852 "EHLO so254-9.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230465AbhGUBCc (ORCPT ); Tue, 20 Jul 2021 21:02:32 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1626831787; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=mtzWCbrz+cE9oYupzBvuDqsFyd7ZcoJ86HtTVGOmLiE=; b=NwBcS0ydd9ApUPSgBeUru+aMnzq99wBSLtQf9bG+8XUhaP5xsSm2orChGjJbHQ48MQY4jJrd MkRxNBWFqc7N8256dWs6dSytCSKpC+IaP8IWrJNyLtXwtuKQMtn2TWmv9FV3RKerMNuhnv4u dufVVtfbA64rvFvo0Nz0riC3n98= X-Mailgun-Sending-Ip: 198.61.254.9 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n02.prod.us-west-2.postgun.com with SMTP id 60f77baae31d882d189c2842 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 21 Jul 2021 01:43:06 GMT Sender: bbhatt=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 3F483C4338A; Wed, 21 Jul 2021 01:43:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00,SPF_FAIL autolearn=no autolearn_force=no version=3.4.0 Received: from malabar-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: bbhatt) by smtp.codeaurora.org (Postfix) with ESMTPSA id 46699C433D3; Wed, 21 Jul 2021 01:43:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 46699C433D3 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=bbhatt@codeaurora.org From: Bhaumik Bhatt To: manivannan.sadhasivam@linaro.org Cc: bqiang@codeaurora.org, linux-arm-msm@vger.kernel.org, hemantk@codeaurora.org, clew@codeaurora.org, linux-kernel@vger.kernel.org, Bhaumik Bhatt Subject: [PATCH] net: qrtr: mhi: synchronize qrtr and mhi preparation Date: Tue, 20 Jul 2021 18:42:58 -0700 Message-Id: <1626831778-31796-1-git-send-email-bbhatt@codeaurora.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A dl callback can be received anytime after mhi_prepare_for_transfer has been called. There is a window where the callback may happen before the probe initializes the qrtr_mhi_dev state. Move the mhi_prepare_for_transfer call after the registering the endpoint. Once moved, the reverse can happen where qrtr will try to send a packet before the channels are prepared. Add a wait in the sending path to ensure the channels are prepared before trying to do a ul transfer. Fixes: a2e2cc0dbb11 ("net: qrtr: Start MHI channels during init") Signed-off-by: Bhaumik Bhatt --- net/qrtr/mhi.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c index 29b4fa3..22b0395 100644 --- a/net/qrtr/mhi.c +++ b/net/qrtr/mhi.c @@ -15,6 +15,7 @@ struct qrtr_mhi_dev { struct qrtr_endpoint ep; struct mhi_device *mhi_dev; struct device *dev; + struct completion ready; }; /* From MHI to QRTR */ @@ -50,6 +51,10 @@ static int qcom_mhi_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb) struct qrtr_mhi_dev *qdev = container_of(ep, struct qrtr_mhi_dev, ep); int rc; + rc = wait_for_completion_interruptible(&qdev->ready); + if (rc) + goto free_skb; + if (skb->sk) sock_hold(skb->sk); @@ -78,11 +83,6 @@ static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev, struct qrtr_mhi_dev *qdev; int rc; - /* start channels */ - rc = mhi_prepare_for_transfer(mhi_dev, MHI_CH_INBOUND_ALLOC_BUFS); - if (rc) - return rc; - qdev = devm_kzalloc(&mhi_dev->dev, sizeof(*qdev), GFP_KERNEL); if (!qdev) return -ENOMEM; @@ -90,12 +90,22 @@ static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev, qdev->mhi_dev = mhi_dev; qdev->dev = &mhi_dev->dev; qdev->ep.xmit = qcom_mhi_qrtr_send; + init_completion(&qdev->ready); dev_set_drvdata(&mhi_dev->dev, qdev); rc = qrtr_endpoint_register(&qdev->ep, QRTR_EP_NID_AUTO); if (rc) return rc; + /* start channels */ + rc = mhi_prepare_for_transfer(mhi_dev, MHI_CH_INBOUND_ALLOC_BUFS); + if (rc) { + qrtr_endpoint_unregister(&qdev->ep); + dev_set_drvdata(&mhi_dev->dev, NULL); + return rc; + } + + complete_all(&qdev->ready); dev_dbg(qdev->dev, "Qualcomm MHI QRTR driver probed\n"); return 0; -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project