Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp143146ybh; Tue, 21 Jul 2020 18:58:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPmgIRymkDSJGeyIflMynj/zFQ8cgZEPEBxG48tZ/i8tUsC0OjxrF92VuE+0HVzOhIeHCD X-Received: by 2002:a17:906:2641:: with SMTP id i1mr29312833ejc.380.1595383111010; Tue, 21 Jul 2020 18:58:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595383111; cv=none; d=google.com; s=arc-20160816; b=IUHJhiDKGq1UjZvQho8ZdgyjHoBWqVLlocqbuFjIVTWgMeSeznk6R7B3h3AIoopVFp F+PzW4wtgxLz4TnakaHlviQhOOx/UFPuUAijo01WMM4hJ1xf5Itfx3mhClqNoH0Ih4CB HnsUtyLOzjpwSnpm26gaaMjSLWYBUSWdVbLGUEFq3GVp2MWtrT2UrEaMGgDzLLpo1sIq 0S98uGerqPvAnS1/HvqnTilkSfbI5ELoHvwIXKK7BXuKg3N+EDzZ64W6Bvc1t3OzbySI djuA7EGRJpSjxDOQZ9uc9tPRHL8LY0jBoLcVS6TLexND9UfuxWc4BI7GH7X7YqJ5DWUC Iu4Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=su1XkeyRnzMEHK9Yn/D1y3WRDB7LvpOU7Y4o6l5KStw=; b=LmHEx399hJ0hLfrtPbyOB/3C2BHpab8TJBBASIwCE1TPnv7eyKIaGnKHAuBveJCfw2 r/OQhE7QV9qjKwJyFV3chhcbZ3SanirMwJufb/st31S/2bgybZu4G31yR0w3O/doW2JY LPCRl53VYoYSNX0K8thEL+QsSRWnPwI8pgtQaaeZVvrkpycnhKkvs5bTi62xx5ioPMje yNmq/cH/Utoe14t3z4bXh0Oi1TkfUG2rp9IjsNwQVP6yJhsWGbih+46x6BeKql9hUTgs QRWfgMoUgYYbqvA9FnNXc3sUIZSxiyIV6JVQy4xxOLtrsSXYUxGF36dBDv2yINtdunEH LtEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MmepaoUC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bo4si12521833ejb.279.2020.07.21.18.58.07; Tue, 21 Jul 2020 18:58:30 -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=@chromium.org header.s=google header.b=MmepaoUC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731727AbgGVB5v (ORCPT + 99 others); Tue, 21 Jul 2020 21:57:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731614AbgGVB5v (ORCPT ); Tue, 21 Jul 2020 21:57:51 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF781C061794 for ; Tue, 21 Jul 2020 18:57:50 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id a24so351627pfc.10 for ; Tue, 21 Jul 2020 18:57:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=su1XkeyRnzMEHK9Yn/D1y3WRDB7LvpOU7Y4o6l5KStw=; b=MmepaoUCiDHsOdlsts0QjlFqbQdU0BbhFm4FK/Ima/IkA6DkQ+yY7kShOxmA9KZPU0 ldiyGqYLLufEvYLkiIRRxf52AOdEKR7+NMrGsZ1tXJooC+xPibcSJw8tDxkPskwS2daH 3/3azAb+DnRLnP08f/yMsxrXGiic/sdMkXV84= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=su1XkeyRnzMEHK9Yn/D1y3WRDB7LvpOU7Y4o6l5KStw=; b=GN3ysoYI1BGJb1EmpHb6Gw6T+Wus1b81C3LnPWtcNfUMUw6u6Vhy2BHX+8VImMWZlD Qnm2+nYr8DyeJheYJE2M8KWkf58SnqovHLDiJ1tkoeyK8zAVFgfvFz9k6/UX2nHSUEyz h5vXibIvQCNHEmgFnidGBDAsmBa5bfxvonBYQIfFrEbpZm/tN7zSlS5Xw94OsVQoyWd2 wjEbfSrY8ojycCyEq4vsjA0RJYzjNGAjP/ir2kQ0mfMwwYTP09SEH29MFeQHWeueVynh 8GPfI5v7LOa2lP8Vuz5eE43qi5bVYhRPzZnAwpUqF1OZ/XrZgvhu+j+cfdGfpXMOwf+O KVDg== X-Gm-Message-State: AOAM53333VTwoOcD893rp7OcQRTDw78yKEatiNJOnZ7Q+E6WJprZHjQl 9sGDRE/I468oLTcUH+ic8FSnVJZKHoU= X-Received: by 2002:a65:6799:: with SMTP id e25mr26124415pgr.364.1595383070340; Tue, 21 Jul 2020 18:57:50 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:8edc:d4ff:fe53:350d]) by smtp.gmail.com with ESMTPSA id c1sm19408729pgi.52.2020.07.21.18.57.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 18:57:49 -0700 (PDT) From: Brian Norris To: Benson Leung , Enric Balletbo i Serra , Guenter Roeck Cc: , Brian Norris Subject: [PATCH 2/2] platform/chrome: cros_ec_proto: check for missing EC_CMD_HOST_EVENT_GET_WAKE_MASK Date: Tue, 21 Jul 2020 18:57:32 -0700 Message-Id: <20200722015732.1720840-2-briannorris@chromium.org> X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog In-Reply-To: <20200722015732.1720840-1-briannorris@chromium.org> References: <20200722015732.1720840-1-briannorris@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.28.0.rc0.105.gf9edc3c819-goog