Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4451001imu; Mon, 14 Jan 2019 23:39:12 -0800 (PST) X-Google-Smtp-Source: ALg8bN4cy0B0aCWCiDkVFg8uHcDj0bxORQbD+wZE1w41E9b/5HgnkLQmfSQbQ8yuKe9rKBNncw1W X-Received: by 2002:a63:ef04:: with SMTP id u4mr2592218pgh.197.1547537952145; Mon, 14 Jan 2019 23:39:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547537952; cv=none; d=google.com; s=arc-20160816; b=jxied+HcRVeCg9ZFLU59VyM7D9borFbanAiUjbGXnqqB++RaCWAKV/TmuIQH0RpvzB EY5cn3ug7QYllQiIn0u3TAG0rwjo54gBqJtAHktGKOJGK8Iz2h9Gi4TexCLpBS4lOZOo RY1rxPMwzb+YTXdWAqIZpXwMzEYGnmGvOxI/4gwozpKkaG7nfAlCNwDhuLaE5VKzkS7n 5No1fDWWpYK07cwd07lsf3C8djZQPklxLUFUvaMKyGljsV1nsnGDrghLa0kBBz536fGk AG0a0NMUtlPVJ9UBGdI1yujJLSVDNz0iKqUmlYe8qNs7hzy1Q2rJ3ywk5vHBzRnEgzXe Fg8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=PXDiDbCWSojGdBQHy8QvvSwkVb8vcMJGGTZ3hLVJa2A=; b=RtCQqfcTI2QZDAkQHPVRtB3JlZs4yO2sjMdvR8M2qbveMecOsf//xBof/aMMZqezGE +3jBIm/KQcQ9mbe+8AbW4O5n5VhwjEG9yrSGpDreJOiD1r/A/izUg1QLzm3w7fxUgmV4 mX8YgOPKjVRq84DtgtKfumO+RsHGoQZKki4Z6SRoCOn/5Ud2DM0jYULPZgATOu4XSRNh QM4xauZKYE6yHLd8U/92hyI3vH+Cospc9RA80JEI0kAUDgI1iDby9LwBICOa0Q6/tYYJ k32Az8JScJM24brvDKfxHH15B6qHeDJ2hNSJA60o9zisCXibIu/54YFJw5LOJilOhtVj cHRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JUd0nvd3; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v141si2927057pfc.260.2019.01.14.23.38.56; Mon, 14 Jan 2019 23:39:12 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=JUd0nvd3; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728179AbfAOFmp (ORCPT + 99 others); Tue, 15 Jan 2019 00:42:45 -0500 Received: from mail-yb1-f195.google.com ([209.85.219.195]:44035 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727211AbfAOFmp (ORCPT ); Tue, 15 Jan 2019 00:42:45 -0500 Received: by mail-yb1-f195.google.com with SMTP id e1so590493ybn.11 for ; Mon, 14 Jan 2019 21:42:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PXDiDbCWSojGdBQHy8QvvSwkVb8vcMJGGTZ3hLVJa2A=; b=JUd0nvd3wkt/6LG6T/IJx11IwhmrWtm5Y7xgOXGJmAUHHGKQpKlufxx371cdTMgZf/ ZXqhP/BV2TKqFC4jAD2MEZJfQAJrOQ+Avj2D3n4c7Gbw5qdAZnQfBAV1W+9Stxr7wJp6 sEUDzBNErQeMh0UmAh9Q0SnpdWeGMpEWIgyEDsoEazidy0JZU3FhK2oczf5MQn5UoSaB jI4gO4DVSneg+glXU6+bcCYsFNBetY0mljwlFWE5Ct7tjLqemB4S7i8kzFAciAok2cwO mfhMX0ekAzFut31VZawG+UIj7GwwVu4Uyue6LQacW3FfdzXPqArdL4ilZClmF09E3//V UBiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PXDiDbCWSojGdBQHy8QvvSwkVb8vcMJGGTZ3hLVJa2A=; b=WzkHrJHWkaxQB4TehB9AOUAOPDOZNMsbKOnw427uZBtrWp9Cgp5WEHUFXloCO78Cx6 M9InFBByBg5KER7KOfMvgmJ1R5q7D9rRINXmbE42/VRZjSR+xQOSVl741EdYe8g50gmP xRHtJ4sEzt9rj7B4VzPtVYmob0wFTvbUoJhsKazkYS0/Q7yODLKbMYpQZDoazsehRUXS wy0326LS4KSx5XVje9yDi+xCGW/60DhvGFJh1YUWPJbZU01lzO2pMl9NcP6ACYAZpXTT KUuwSyxfWnPtknX5V1Bb81KTYXARoIyCwkD6GczyUFtxoj/gdMXQBGW3Kw1Ht9YwJbsC JGsQ== X-Gm-Message-State: AJcUukdYl6Yu5W+HciId4IDd7aw6dVnw66/zR9BVHvIoIl76RZRduPOd NPptSolJJQawWXKFYez1z0fOX4cw5oOZZgdCfVM+sg== X-Received: by 2002:a25:c184:: with SMTP id r126mr1485509ybf.441.1547530963538; Mon, 14 Jan 2019 21:42:43 -0800 (PST) MIME-Version: 1.0 References: <20181129195548.204153-1-egranata@chromium.org> <20181207222223.GA240898@google.com> In-Reply-To: From: Gwendal Grignou Date: Mon, 14 Jan 2019 21:42:30 -0800 Message-ID: Subject: Re: [PATCH] mfd: cros_ec: Add support for MKBP more event flags To: Brian Norris Cc: Enrico Granata , Lee Jones , Benson Leung , Olof Johansson , Linux Kernel , Enrico Granata Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 14, 2019 at 6:04 PM Brian Norris wrote: > > Hi Gwendal, > > On Mon, Jan 14, 2019 at 3:50 PM Gwendal Grignou wrote: > > On Fri, Dec 7, 2018 at 2:22 PM Brian Norris wrote: > > > On Thu, Nov 29, 2018 at 11:55:48AM -0800, egranata@google.com wrote: > > > > --- a/drivers/platform/chrome/cros_ec_proto.c > > > > +++ b/drivers/platform/chrome/cros_ec_proto.c > > > > @@ -420,10 +420,14 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev) > > > > ret = cros_ec_get_host_command_version_mask(ec_dev, > > > > EC_CMD_GET_NEXT_EVENT, > > > > &ver_mask); > > > > > > It's not exactly new here (although you're using 'ver_mask' in new > > > ways), but cros_ec_get_host_command_version_mask() doesn't look 100% > > > right. It doesn't look at msg->result, and instead just assumes that if > > > we got some data back (send_command() > 0), then it must have been a > > > success. I don't think that's really guaranteed in general, although it > > > might be for the specific case of EC_CMD_GET_CMD_VERSIONS. > > > It is guaranteed: if msg->result is not EC_RES_SUCCESS, then ret can > > not be greater than 0. At best it will be 0, or a negative number if > > we can already qualify the error in the errno space (see > > T() for instance). > > Sorry, where do you guarantee that? The only enforcements I see in > those xfer implementation are: > (1) if result == EC_RES_IN_PROGRESS, we convert that to an errno > (2) if the expected length or checksum are bad, we turn that to an errno > > So technically, the EC *could* be sending a valid, checksummed > response of the expected length, while still setting the ->result > field to something besides EC_RES_SUCCESS or EC_RES_IN_PROGRESS. And > we would treat that as a valid 'ver_mask'. You're right, I misread cros_ec_pkt_xfer_i2c(). > Albeit, that seems unlikely, given understanding of how the EC is > supposed to behave, but our code is not properly defensive AIUI. This > is basically why cros_ec_cmd_xfer_status() exists -- so that > sub-drivers don't get lazy and use cros_ec_cmd_xfer() without handling > the ->result field properly. send_command is called for a very small subset of command where the ec_dev mutex is already held. We indeed need to be careful when calling it directly. Gwendal. > > Brian