Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1488435ybv; Fri, 14 Feb 2020 00:27:25 -0800 (PST) X-Google-Smtp-Source: APXvYqxTmmM/CTne5B1EQo4cZDZIFD6pLsPncBTYd1WbM8r/jkChOYgvW0uuge53zSOTzp0LK9lp X-Received: by 2002:aca:c256:: with SMTP id s83mr1118366oif.57.1581668845815; Fri, 14 Feb 2020 00:27:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581668845; cv=none; d=google.com; s=arc-20160816; b=zDUBEl0T0KQfRU+KJYIlKDff9w7CEoOpyZ1l/3mEaL6yskfBrY98aDPSoX+7zzmGYd skp20obsfgl74csakbD0CbWen0A4kKNX+0zONart9tdUVnHz/gI4a49PDWWicVb97wzb PpKB9f6R4D90nVEr9Xn11ZTjrf4gGoKbOJK5CNnOjrbrajwXf3PMGc/u00vMP7CiNAJ/ J5WlWep8KaTXJcaCotZ0k1hc3Zpw64K2yIY5h5ZFwf615/LwzPvwD//3pd6qaQs4ajPR uwskxm37OmOkaK4qOzp4eYX6OU+onDSZoTccK38T1p33mpUpvNP2UJOJdpSdkJmpm3fO r84g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=G3bmgmETZeBo0EFsBeEB+TZ0Z824p4H/W8k7nEd9ZXs=; b=mvmf9TLImDiqYsZ+roo1fvtqhRyzAU5WNqcxe4AnVuJGIIehjj6LEwqysK+p7IYdf5 8hYIxT7Wo7l1AZw4Gsx6lWHjdJVDym+gkMCqI+XgsLRsLFEZSb+1BsOokcdxBfOKhfhx tGFrqW5USTaC/iBfAbCd+TWbomCpp8yqYd/G88/sYr7rNZ4ugTw5buEotiVR4MIiC7Ii hM0hY369rqll5X5l9pLTbHlkudY46QoLA0CD6meCDSpXE53Oh9iEwpemIk9WWfLW3Zdj lrr4o4aMsjhU5Lh/9blqjh6P5lwSG2ys9Nxox0o9SYnQ9VevDCw14BXdkhIDLMmT92V3 WfPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=T435wpmq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10si2443563oti.226.2020.02.14.00.27.13; Fri, 14 Feb 2020 00:27:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=T435wpmq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728740AbgBNI06 (ORCPT + 99 others); Fri, 14 Feb 2020 03:26:58 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:36209 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726004AbgBNI06 (ORCPT ); Fri, 14 Feb 2020 03:26:58 -0500 Received: by mail-pl1-f193.google.com with SMTP id a6so3467042plm.3 for ; Fri, 14 Feb 2020 00:26:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=G3bmgmETZeBo0EFsBeEB+TZ0Z824p4H/W8k7nEd9ZXs=; b=T435wpmqpKgEEgCx+n7GAU+TvalD+G4SMWspDq7b/zaFvbaJ4EEEf84Gy8W7tlU6dl P+vN2AJGX+WeV9DaXg7M7z5nMOjCN1qGwQA4AWd/ymOT++fwNS73IDXyMBSqvHeG0ci/ CKZDxPT+pRzVeFR5Ffx/WTVORhvpOKPnzYAB8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=G3bmgmETZeBo0EFsBeEB+TZ0Z824p4H/W8k7nEd9ZXs=; b=Rbj70fd8GV6mx52JeIA0dF55oCuuETPQIJltCq9GyYG4O8EoqDEto5bNxgFtOD8eny IwhUkKttfbX4h+Es0zLXERM1PJrRXznuFdjtJ5BCnSeL7mFUOEjD3LINgM/ajh34CxPl cVZTQB9Arg5fi9doHwT87yMsSfzslbeTeUj7EVMgxfLhdeMJ5gskPi8DYe1VeBUVQU/j fm5aa3Yze28sZeWEEcWRDg1IxQpVUR8btJnFprE0FqH1PgftaCY/AWuo4IMuslw2IkF5 pJTzPJIPp+Klbe3NHo3w6PV5JKp3kJzMmwX+FPk5n0ERZ99+GUggmyC0vF4WzyLGfUNc t61A== X-Gm-Message-State: APjAAAUow+RAV9mMR4P/Pfmw/fXcA/qhakxRBv6fu/M6LZ7Iki79XR5R iUQw66lZ682i96RnzSGrpbH+KQ== X-Received: by 2002:a17:90a:5801:: with SMTP id h1mr2164293pji.121.1581668817956; Fri, 14 Feb 2020 00:26:57 -0800 (PST) Received: from pihsun-z840.tpe.corp.google.com ([2401:fa00:1:10:7889:7a43:f899:134c]) by smtp.googlemail.com with ESMTPSA id m12sm5125622pjf.25.2020.02.14.00.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 00:26:57 -0800 (PST) From: Pi-Hsun Shih Cc: Pi-Hsun Shih , Benson Leung , Enric Balletbo i Serra , Guenter Roeck , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] platform/chrome: cros_ec_rpmsg: Fix race with host event. Date: Fri, 14 Feb 2020 16:26:38 +0800 Message-Id: <20200214082638.92070-1-pihsun@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Host event can be sent by remoteproc by any time, and cros_ec_rpmsg_callback would be called after cros_ec_rpmsg_create_ept. But the cros_ec_device is initialized after that, which cause host event handler to use cros_ec_device that are not initialized properly yet. Fix this by don't schedule host event handler before cros_ec_register returns. Instead, remember that we have a pending host event, and schedule host event handler after cros_ec_register. Fixes: 71cddb7097e2 ("platform/chrome: cros_ec_rpmsg: Fix race with host command when probe failed.") Signed-off-by: Pi-Hsun Shih --- drivers/platform/chrome/cros_ec_rpmsg.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_ec_rpmsg.c b/drivers/platform/chrome/cros_ec_rpmsg.c index dbc3f5523b83..7e8629e3db74 100644 --- a/drivers/platform/chrome/cros_ec_rpmsg.c +++ b/drivers/platform/chrome/cros_ec_rpmsg.c @@ -44,6 +44,8 @@ struct cros_ec_rpmsg { struct completion xfer_ack; struct work_struct host_event_work; struct rpmsg_endpoint *ept; + bool has_pending_host_event; + bool probe_done; }; /** @@ -177,7 +179,14 @@ static int cros_ec_rpmsg_callback(struct rpmsg_device *rpdev, void *data, memcpy(ec_dev->din, resp->data, len); complete(&ec_rpmsg->xfer_ack); } else if (resp->type == HOST_EVENT_MARK) { - schedule_work(&ec_rpmsg->host_event_work); + /* + * If the host event is sent before cros_ec_register is + * finished, queue the host event. + */ + if (ec_rpmsg->probe_done) + schedule_work(&ec_rpmsg->host_event_work); + else + ec_rpmsg->has_pending_host_event = true; } else { dev_warn(ec_dev->dev, "rpmsg received invalid type = %d", resp->type); @@ -240,6 +249,11 @@ static int cros_ec_rpmsg_probe(struct rpmsg_device *rpdev) return ret; } + ec_rpmsg->probe_done = true; + + if (ec_rpmsg->has_pending_host_event) + schedule_work(&ec_rpmsg->host_event_work); + return 0; } base-commit: b19e8c68470385dd2c5440876591fddb02c8c402 -- 2.25.0.265.gbab2e86ba0-goog