Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3597948ybz; Mon, 20 Apr 2020 06:03:52 -0700 (PDT) X-Google-Smtp-Source: APiQypIrSa8Y/BQ9817j7bpKDr3Kcitk4HxEhAfpiRJIYWNAGaTa3kjyKk0LknanHXH7jmyLZoEo X-Received: by 2002:a50:c30f:: with SMTP id a15mr13912390edb.35.1587387831671; Mon, 20 Apr 2020 06:03:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587387831; cv=none; d=google.com; s=arc-20160816; b=EPaAcd/Pp3o0JBOqQ9pRDgYUElzP/50HOjx9+RAfqfDkUOBxTjyNCk1LCedL1MSe+6 TUrAh8vOq7gCEi2D7mtvL6OePC8Rd0PGQUQuRmhIUg35uPUckjD2rU2h+b6sc46rmZTq wY0anMzp1TuirlH8HoTTZk38Jh63D7nj6em2Am5tmx4qLCX5/C5DJh2IGFRMH9/g8eZm G3fRCIEo3i+y02lm/hE1KGEAFndThQNCZnPDUnwuo5r+JUeYcgQff4USIdrS9ixCoRnO mckI88AJ7RPkwSw/TMdKfgwCLzDQzeUk5X2PkUTcqGKNxvJ81PZeEREAPQRU0qV80xQG WwaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GgiVKl4bAF8D84acyQWqiNvQDRxR8EBtu6vebG8NQdo=; b=LabC2AlNx5yvKaaK7NPROLtc5rpGEBgxSCRvCqLv7bgjloCVEmGTYxMGw1scfwpFsY D+drJCugOPjT1VAunbziZGb3e8cHowmCVAlztTChDW4KxgD04SSdVZMKrPp/kuCxLqZO XfecWQUoHqSz5Jjer84AgwH9yp47a5s6BsQpNZVXbsdATLFLxI/BNDQMLlUsXILoRGLH EQyZl0e6fY0qPtkRqe83vFg0HKb7y0u9W7jA8ZDsPigG+Pg2yAkSTGLJko7VdqhtX7Pg bs+gpO9ILf/kaCj0+Aa0oAD4pCb69LeD/f0Thq/sJJ32yY6WQxmThFTPWTcPTbN6kfkk YZZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y+h4168b; 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 l9si456218edf.315.2020.04.20.06.03.28; Mon, 20 Apr 2020 06:03:51 -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=@kernel.org header.s=default header.b=Y+h4168b; 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 S1728073AbgDTNAL (ORCPT + 99 others); Mon, 20 Apr 2020 09:00:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:33010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727812AbgDTMkk (ORCPT ); Mon, 20 Apr 2020 08:40:40 -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 4B5792070B; Mon, 20 Apr 2020 12:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587386439; bh=etT5MZ8mwbz2xuKce0zzrF5OeDSGl/wFU/I+fVDBueM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y+h4168bVJDCsoTQ/kr1qHxmB3pCJHLQl0lb47sJXVD1xEZMmtMQfO/8YonNgSX6r tsmDsQgR4pmdP8cvYOzazjfqxAeFaQp7bhEJ3wuBihVZB09RxA1AhwcHcLxtWpM3B6 63XZh4XLUJBe696LhRbv1VUPWIzwIc9bi/p/FIHc= 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.5 23/65] platform/chrome: cros_ec_rpmsg: Fix race with host event Date: Mon, 20 Apr 2020 14:38:27 +0200 Message-Id: <20200420121511.525317370@linuxfoundation.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200420121505.909671922@linuxfoundation.org> References: <20200420121505.909671922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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; }; /** @@ -175,7 +177,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); @@ -238,6 +247,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; }