Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp393700ybt; Mon, 6 Jul 2020 11:55:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiuoFVGXq4uj9ebx2tCVpwPKxVkC6+tbb+tYxoyMg03WtxdINm9+JiP81ifWtE8Lnmh/gy X-Received: by 2002:a17:906:c056:: with SMTP id bm22mr35879014ejb.444.1594061755917; Mon, 06 Jul 2020 11:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594061755; cv=none; d=google.com; s=arc-20160816; b=FayWVDvAIsH9UtvG0DwozMopgT5laYNLdOeJBH9RvQuUu8sULjwywU0N8dVy53ygrK +N9zVgbjbwuyrqN4v2S/iySV8BhiOn8tzBvB970qRGn+3oekZvueOVn/72NOZ9LYKPLF OZ7Ohyab0vtI1vtt1nNtvJY8K0CDzyJAgH7tF5phEhBSsaO1z/VIhwQbGHx5yCBQO/hl 5y/uC0Jitbi6PuPVb5aBm9wmsItLB6OfTDurZiSo27ZnATVf3Zb1+ZlATNeOBJL5SRJQ GqFYBjBe8RnnpiayF2cTKuksgMhz8EbBmpYfezzsTZ/NxL2yrOf8kqzGNq/HN7UvKRdW U5lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=LQf9W6lyj1BEyVBQY9ZVbVP6ArVDZ+iAsAbrwyXvk+A=; b=lU8OYgHJlLhp0DNNQQ17Gc7DutGYczg/qzhCsjPt9VGUAL1xiYim+ZSC0jURsEhgYG E4ZAYWQmH6vW2PugF+tGmLQ8sGHtOisOIYVUif2LTz4H9/t+XthEsps9x+mSPea35OTX HP6ZNExLxeb3rgbpRDZ9BN5xiLThVcNrfAh3btPb89HvXiYeZGQY/MrNyAKU6TaIeS5Y 8jq0aSFR08L0L1HROHxUEcyBu86bMcqHSFvv4czoyI2Odo8rtb+v9NOCrw0XFQpgkWFw k2aIZs6GVpLwPCuR30L3cT/ANzjQvyxVAtkkNEJXEPjQyQOLsS4GtcFoJPjxy0eGuMDq KqYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fxaIpwip; 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 w20si13498245eds.305.2020.07.06.11.55.32; Mon, 06 Jul 2020 11:55:55 -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=fxaIpwip; 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 S1729800AbgGFSwd (ORCPT + 99 others); Mon, 6 Jul 2020 14:52:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729733AbgGFSwc (ORCPT ); Mon, 6 Jul 2020 14:52:32 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4093AC061755 for ; Mon, 6 Jul 2020 11:52:32 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id l6so14089498pjq.1 for ; Mon, 06 Jul 2020 11:52:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=LQf9W6lyj1BEyVBQY9ZVbVP6ArVDZ+iAsAbrwyXvk+A=; b=fxaIpwipZBmv6PkXDTJzLIHBSZELnRDWZVgzap0uWPXyvFG0nBSJxgTyLscWL7abpP O1ahM5LtzK3rP02DIwF1bQ5va3MHEbUuRIW/cIUdp4ORDpANzDwnS0eVo75rNPX9aS+b 0Zbfl9Wlp2oaiE5bMKg1CpQJkuSqNKhYh3exY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=LQf9W6lyj1BEyVBQY9ZVbVP6ArVDZ+iAsAbrwyXvk+A=; b=LF3UXPd7ZG6jF6gyXnl7zSo7cVFGlWB2yugG7YRU7sDuMqnlHPArcZWvZVcEVWLU6M PCOiLYo6vowsc0eJ6Ipp90lX9WvwXv4KDJisL3hclZSxvhjX/zIAZZ6pVZR1JFEnCH5W C9OlUOQlJWV2N1uWBExEVdp9L8YRuNwm7bbTEFsF4J0XBhtPqt/F1M0FA98tzl2ZEibr 9/1g57A/WduSHVoCHX3iMpj2onaEeLsK4K0GIyNY8XO6NHkd34YE6t5zedoIDJrzeJ3R 9OxTBu9/tK+62xUhyI6LXuVfvQRIk4+UdISBP9/LES1AJCN8PGmMfmw57nFnzZ08WInO NuNQ== X-Gm-Message-State: AOAM53344rv4uiVgDdn7dOg0QqrQmMLQs62WKjsR/p2YiZBNnAmiiD/2 KhCtEh5A4Ve342kc+2JW6o/17UqWGeA= X-Received: by 2002:a17:90a:cf01:: with SMTP id h1mr571326pju.234.1594061551462; Mon, 06 Jul 2020 11:52:31 -0700 (PDT) Received: from google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id h23sm5270455pfo.166.2020.07.06.11.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2020 11:52:31 -0700 (PDT) Date: Mon, 6 Jul 2020 11:52:30 -0700 From: Prashant Malani To: Guenter Roeck Cc: Enric Balletbo i Serra , Benson Leung , linux-kernel@vger.kernel.org, Yu-Hsuan Hsu Subject: Re: [PATCH] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Message-ID: <20200706185230.GA792857@google.com> References: <20200704142607.171400-1-linux@roeck-us.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200704142607.171400-1-linux@roeck-us.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Guenter, On Sat, Jul 04, 2020 at 07:26:07AM -0700, Guenter Roeck wrote: > The EC reports a variety of error codes. Most of those, with the exception > of EC_RES_INVALID_VERSION, are converted to -EPROTO. As result, the actual > error code gets lost. Convert all EC errors to Linux error codes to report > a more meaningful error to the caller to aid debugging. > > Cc: Yu-Hsuan Hsu > Cc: Prashant Malani > Signed-off-by: Guenter Roeck > --- > drivers/platform/chrome/cros_ec_proto.c | 37 +++++++++++++++++++------ > 1 file changed, 29 insertions(+), 8 deletions(-) > > diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c > index 3e745e0fe092..10aa9e483d35 100644 > --- a/drivers/platform/chrome/cros_ec_proto.c > +++ b/drivers/platform/chrome/cros_ec_proto.c > @@ -543,6 +543,29 @@ int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev, > } > EXPORT_SYMBOL(cros_ec_cmd_xfer); > > +static const int cros_ec_error_map[] = { > + [EC_RES_INVALID_COMMAND] = -EOPNOTSUPP, > + [EC_RES_ERROR] = -EIO, > + [EC_RES_INVALID_PARAM] = -EINVAL, > + [EC_RES_ACCESS_DENIED] = -EACCES, > + [EC_RES_INVALID_RESPONSE] = -EPROTO, > + [EC_RES_INVALID_VERSION] = -ENOTSUPP, > + [EC_RES_INVALID_CHECKSUM] = -EBADMSG, > + [EC_RES_IN_PROGRESS] = -EINPROGRESS, > + [EC_RES_UNAVAILABLE] = -ENODATA, > + [EC_RES_TIMEOUT] = -ETIMEDOUT, > + [EC_RES_OVERFLOW] = -EOVERFLOW, > + [EC_RES_INVALID_HEADER] = -EBADR, > + [EC_RES_REQUEST_TRUNCATED] = -EBADR, > + [EC_RES_RESPONSE_TOO_BIG] = -EFBIG, > + [EC_RES_BUS_ERROR] = -EFAULT, > + [EC_RES_BUSY] = -EBUSY, > + [EC_RES_INVALID_HEADER_VERSION] = -EBADMSG, > + [EC_RES_INVALID_HEADER_CRC] = -EBADMSG, > + [EC_RES_INVALID_DATA_CRC] = -EBADMSG, > + [EC_RES_DUP_UNAVAILABLE] = -ENODATA, > +}; > + > /** > * cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC. > * @ec_dev: EC device. > @@ -555,8 +578,7 @@ EXPORT_SYMBOL(cros_ec_cmd_xfer); > * > * Return: > * >=0 - The number of bytes transferred > - * -ENOTSUPP - Operation not supported > - * -EPROTO - Protocol error > + * <0 - Linux error code > */ > int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev, > struct cros_ec_command *msg) > @@ -566,13 +588,12 @@ int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev, > ret = cros_ec_cmd_xfer(ec_dev, msg); > if (ret < 0) { > dev_err(ec_dev->dev, "Command xfer error (err:%d)\n", ret); > - } else if (msg->result == EC_RES_INVALID_VERSION) { > - dev_dbg(ec_dev->dev, "Command invalid version (err:%d)\n", > - msg->result); > - return -ENOTSUPP; > } else if (msg->result != EC_RES_SUCCESS) { > - dev_dbg(ec_dev->dev, "Command result (err: %d)\n", msg->result); > - return -EPROTO; > + if (msg->result < ARRAY_SIZE(cros_ec_error_map) && cros_ec_error_map[msg->result]) Do we expect a case where cros_ec_error_map[msg->result] == 0? > + ret = cros_ec_error_map[msg->result]; > + else > + ret = -EPROTO; > + dev_dbg(ec_dev->dev, "Command result (err: %d [%d])\n", msg->result, ret); > } > > return ret; > -- > 2.17.1 >