From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C2EBC54FCB for ; Mon, 20 Apr 2020 12:54:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1E4D206D5 for ; Mon, 20 Apr 2020 12:54:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587387294; bh=oHFlV+IW5EELeqfubWhSlP5v37UyQIB/GC3bKne0vCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=qNVmwjH0vc+yLnNwGooC1PnnXV36aKOOxvJy8nswn4d+82t2h0J/pAJKm4zUDqPiy gPoV5atvYXNdddHhoGcqK1l1zAaivNlphDNBgnLx1sa6J5pW+FJQc3UzlCc3G4phM6 s0srP4iUhK6pda3Uojz08s2JDliJDJxS0A8/hR3M= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728900AbgDTMqT (ORCPT ); Mon, 20 Apr 2020 08:46:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:41528 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728888AbgDTMqS (ORCPT ); Mon, 20 Apr 2020 08:46:18 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CD7992078E; Mon, 20 Apr 2020 12:46:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587386775; bh=oHFlV+IW5EELeqfubWhSlP5v37UyQIB/GC3bKne0vCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sNp3rK6ziQU3ihjDk/6lTKmqY8XwVwRIWAbq12NbJeKelmM1HZmpLS2aeGEKnqjX7 Vy+LgIjLygOcT24MvLw5m3uwQ25lYL0Vga7SKmAHpi7UpNqQW+/lMW55/7R0Tn0LuH 3p6Z0mdKCTmxoP34aePQFxSclSQEF238VBc8qkb8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pi-Hsun Shih , Enric Balletbo i Serra Subject: [PATCH 5.4 21/60] platform/chrome: cros_ec_rpmsg: Fix race with host event Date: Mon, 20 Apr 2020 14:38:59 +0200 Message-Id: <20200420121507.879999606@linuxfoundation.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200420121500.490651540@linuxfoundation.org> References: <20200420121500.490651540@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Pi-Hsun Shih commit f775ac78fcfc6bdc96bdda07029d11f2a5e84869 upstream. 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 Signed-off-by: Enric Balletbo i Serra Signed-off-by: Greg Kroah-Hartman --- drivers/platform/chrome/cros_ec_rpmsg.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) --- a/drivers/platform/chrome/cros_ec_rpmsg.c +++ b/drivers/platform/chrome/cros_ec_rpmsg.c @@ -42,6 +42,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; }; /** @@ -186,7 +188,14 @@ static int cros_ec_rpmsg_callback(struct 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); @@ -249,6 +258,11 @@ static int cros_ec_rpmsg_probe(struct rp return ret; } + ec_rpmsg->probe_done = true; + + if (ec_rpmsg->has_pending_host_event) + schedule_work(&ec_rpmsg->host_event_work); + return 0; }