Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3233023ybf; Tue, 3 Mar 2020 02:05:00 -0800 (PST) X-Google-Smtp-Source: ADFU+vuLGR4kS5P0ATcL3/QfLHM9s0DqSIfwyZt090Zmde9t+f1k9li6j/Iht1gJcFmNOQ/vkv6k X-Received: by 2002:aca:504e:: with SMTP id e75mr1855559oib.143.1583229899900; Tue, 03 Mar 2020 02:04:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583229899; cv=none; d=google.com; s=arc-20160816; b=y6X+Mfo0i4ue6x6r0eKoNqJz922bXLCvuo1EmwNQnZc0cx3/wN5om1OUpVGZnQ/BPn mMtfi4Q3XD+4Elv1RcnljU98uU1ewfzCGdw475y7upFNX6LDeZUnPjtpc1j9yeYng1U3 FpRIuz1NBWS+t/WtWz3jkIQ2nnWt0CgT2k6EkqMmkeC4V2JP/L9UVNcNfnWgsQ5VjBXS 9fG2b/y2WjcsCtQnHgJJl6H9Hn47iUD/zkRsTZhF2JCQ8RXoADIUysdXzo2oHQU8WLmq kHRpQD+QswjPtDWPxf0F3pnYuFnarBCO02yyhlx7PdNh2xcpGkgrq0cbEfxTVw6V5eyF wTng== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=EdoK2QGQXrG2rs1QBp+0Ido/AghR/c4QpIV+nkBTbIY=; b=LmKUfwdlWiqf8TpvSQJvHTgoPk3WZyuaAcVkfyPosEjbTOLw2b4UVynfCnj9wL/wKq XYp8UeZQYBzS5m9iM/mSz5k45WGgvszY9sjbX6Gk6YodwU0znj0oTiFSsqIk9o0RPbiW 2DiwI5Q8KWQut5HPi8eCuj5MAmb7zzgxc6Njc4RBpwrFuOA6psnZg3BcDe/Pshef8C09 +3PBEgNRWGsXiH/4VzFxEbw7PmOhAM9OW5zvMkTowiDjF+ri4lMnfcSYOI26l415qNbe au3Plq969bziiPM06rroPLb8CuDBQjFtc3UlmxyJkXM5pthRCMkbThKAHaE5mcoMKKMC 0w6w== ARC-Authentication-Results: i=1; mx.google.com; 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=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e8si3935657otj.25.2020.03.03.02.04.46; Tue, 03 Mar 2020 02:04:59 -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; 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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728005AbgCCKDZ (ORCPT + 99 others); Tue, 3 Mar 2020 05:03:25 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:54898 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727798AbgCCKDZ (ORCPT ); Tue, 3 Mar 2020 05:03:25 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 216422955E8 Subject: Re: [PATCH] platform/chrome: cros_ec_rpmsg: Fix race with host event. To: Pi-Hsun Shih Cc: Benson Leung , Guenter Roeck , open list References: <20200214082638.92070-1-pihsun@chromium.org> From: Enric Balletbo i Serra Message-ID: Date: Tue, 3 Mar 2020 11:03:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200214082638.92070-1-pihsun@chromium.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Pi-Hsun, On 14/2/20 9:26, Pi-Hsun Shih wrote: > 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 > --- Applied for 5.7 > 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 >