Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp390288ybh; Wed, 22 Jul 2020 03:20:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxN6gK5iJfAD+kpv9+1qjRSrrIpOuPu3ZiozNeD2TVbUF4S3XPQnWv+3mJb6vecpQOJyzqf X-Received: by 2002:aa7:c50e:: with SMTP id o14mr30496812edq.168.1595413222173; Wed, 22 Jul 2020 03:20:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595413222; cv=none; d=google.com; s=arc-20160816; b=g9pNG8w0KzBNIMyz0GG6uCSmjYWZUHke7Q+H+nmQgIiwJivYU4I55PS78rguQMTB+g ARHxe8ivuiwrTOOYHSv9LJcBQhIk5nATdbVj88IFWqeo7tp3XiLsS+Ygeo2TXXRejqEc YJC4PkMcAlwHSgxLuExjhbBIhwpndl25APYV1GA4fT1bovx5vZF3VC13bZH+eDfqMJrZ Ok2oyFsozELRVxwuMmoTMOPF3dknErps1l4jlEZG5gadLtVHXhCL+yIc42Z5iEdWsVI3 UA7YFh5ZtwWTZ1VrLG3ml0VOoyqAn+4t+QzUKcMIq27Dz0IEufmt0gDyhqoJIBRaAiAm DTUQ== 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=wfe3JbhlCtNe88S7tftL5wKABxT458Cu7HPXwmdxUSA=; b=WRArHhlfDptzlSALwMYc1gGvKHkxOEq3r+FphTVm+LzewChQRljsXuVczDszuwjG8+ /QXJE76oEZ+F+Q8+edLvIGjElHSaJNguvkq7NPiPvamAbwT7Wk/mC7eqsAr+sSSXZoWq kUO+AE0qewFbFydesu8sbfB+PZBXCUSTZQVI1la6cNgqQ4sd/g0O2WOzrym6L1aCM0/Y 2HxyjbpUFlkXu8t1L4JM4u0RxIBh2RfthRQWahwu9xMvBrx2VXUQrFSBrWNlXRXjae6A GU0dzwL+x43uZgsPNTBw1X+8v94rv/IxH0aQ0psSnZq1VejfMwMhtchbhoc7a+NCGSui rCsA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h18si11301637ejd.91.2020.07.22.03.19.58; Wed, 22 Jul 2020 03:20:22 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730142AbgGVKTp (ORCPT + 99 others); Wed, 22 Jul 2020 06:19:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727034AbgGVKTp (ORCPT ); Wed, 22 Jul 2020 06:19:45 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33B76C0619DC for ; Wed, 22 Jul 2020 03:19:45 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 06C3C260FCD Subject: Re: [PATCH 2/2] platform/chrome: cros_ec_proto: check for missing EC_CMD_HOST_EVENT_GET_WAKE_MASK To: Brian Norris , Benson Leung , Guenter Roeck Cc: linux-kernel@vger.kernel.org References: <20200722015732.1720840-1-briannorris@chromium.org> <20200722015732.1720840-2-briannorris@chromium.org> From: Enric Balletbo i Serra Message-ID: <5ebf1534-8045-9894-9c1c-b92b9c6d8479@collabora.com> Date: Wed, 22 Jul 2020 12:19:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200722015732.1720840-2-briannorris@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 Brian, Thank you for your patch, I'll take a look soon but I'd like to ask if you can join the discussion with this patchset [1], specially this one [2]. We're trying to match EC errors with standard linux kernel errors because we think can be helpful. [1] https://lore.kernel.org/patchwork/cover/1276734/ [2] https://lore.kernel.org/patchwork/patch/1276738/ Thanks, Enric On 22/7/20 3:57, Brian Norris wrote: > As with cros_ec_cmd_xfer_status(), etc., it's not enough to simply check > for the return status of send_command() -- that only covers transport or > other similarly-fatal errors. One must also check the ->result field, to > see whether the command really succeeded. If not, we can't use the data > it returns. > > The caller of cros_ec_get_host_event_wake_mask() ignores this, and so > for example, on EC's where the command is not implemented, we're using > junk (or in practice, all zeros) for our wake-mask. We should be using a > non-zero default (currently, it's supposed to be all-1's). > > Fix this by checking the ->result field and returning -EPROTO for > errors. > > I might label this as fixing commit 29d99b966d60 ("cros_ec: Don't signal > wake event for non-wake host events"), except that this fix alone > actually may make things worse, as it now allows for a lot more spurious > wakeups. The patch "platform/chrome: cros_ec_proto: ignore battery/AC > wakeups on old ECs" helps to mitigate this. > > Signed-off-by: Brian Norris > --- > drivers/platform/chrome/cros_ec_proto.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c > index e93024b55ce8..01a74abe4191 100644 > --- a/drivers/platform/chrome/cros_ec_proto.c > +++ b/drivers/platform/chrome/cros_ec_proto.c > @@ -208,6 +208,12 @@ static int cros_ec_get_host_event_wake_mask(struct cros_ec_device *ec_dev, > msg->insize = sizeof(*r); > > ret = send_command(ec_dev, msg); > + if (ret >= 0) { > + if (msg->result == EC_RES_INVALID_COMMAND) > + return -ENOTSUPP; > + if (msg->result != EC_RES_SUCCESS) > + return -EPROTO; > + } > if (ret > 0) { > r = (struct ec_response_host_event_mask *)msg->data; > *mask = r->mask; > @@ -488,6 +494,13 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev) > BIT(EC_HOST_EVENT_BATTERY_CRITICAL) | > BIT(EC_HOST_EVENT_PD_MCU) | > BIT(EC_HOST_EVENT_BATTERY_STATUS)); > + /* > + * Old ECs may not support this command. Complain about all > + * other errors. > + */ > + if (ret != -ENOTSUPP) > + dev_err(ec_dev->dev, > + "failed to retrieve wake mask: %d\n", ret); > } > > ret = 0; >