Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp492689ybt; Mon, 6 Jul 2020 14:39:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8dilSPadQPZSA98FycqOjP7esz/nsZW8RWqDMgwsa6MXAnnCpFb4E+Udv3FMgUQgpDtro X-Received: by 2002:a17:906:5243:: with SMTP id y3mr47547412ejm.193.1594071595242; Mon, 06 Jul 2020 14:39:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594071595; cv=none; d=google.com; s=arc-20160816; b=ifdzclUlPiUEgwl3CmiaAI4pYbYaNf99TvSc1oQ9msJ9k8Yi2Y5rBaSIBxRN27/1qr s+GbRQKfj72sonJZY03YscEZdiRvcHmW8C0HcP1w6HuohbbnpsV1ln65Xx5BdoY6bU2Q 3ngPQP07RgxxWKz8gRAgukNTYJAaq95z+Cd5HfPYp3op0jlsRBxBQO9/rV6VMqUklisK crAMNQ7OfvcvuO79e00omT9g/DfDanEmG1r9N+DxroGxqJwiyvnEKQy13vNU0UnOPLVO l36ejExU36tyGgaFoQhEZQgnOEOmqLtefMeVpMd1ZL1TPDJd44RV+iaqF2ZguEeMJ7j2 i5LA== 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:autocrypt:from:references:cc:to:subject:dkim-signature; bh=UCl4wVbcsht/zku6xJc527nvr4RdOXbi85FVXi9skdc=; b=wKKJUtGJmicxK8SaQwY6NsxeQ9UrA//PHqpyiTTLG/vOXN6T/QVEX7S4k67I1OtH37 3LV4DsqSwUmP3jz89ltWBXn+Yk+WlblqX+5uj4qDDiTBXimVPT0aw158/5jAFQf+SvLY 41R9fNBpNU/jhxHuLx/dJ7ra8R69a9mTCAwq94qYpdzB8hq1CzfqhqT6ilygtJVbjerO cgLrpwz2SQgx3Hfz6nam99AhLYGrev7uoS/sldH1ri9n4MO7DV1kvwMfR/mx/cxZqExN Qo0eDhvwKYyqHwDqGDxA9BKFPVaspZ0JJcUKaGT6WdNUIXaoZ2oFcKIyQyH6xhbHJGBR Jl+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=fH9wxfTI; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qx22si13186857ejb.148.2020.07.06.14.39.32; Mon, 06 Jul 2020 14:39: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=fail header.i=@gmail.com header.s=20161025 header.b=fH9wxfTI; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726936AbgGFViC (ORCPT + 99 others); Mon, 6 Jul 2020 17:38:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbgGFViC (ORCPT ); Mon, 6 Jul 2020 17:38:02 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43AA5C061755 for ; Mon, 6 Jul 2020 14:38:02 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id w17so1390039ply.11 for ; Mon, 06 Jul 2020 14:38:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=UCl4wVbcsht/zku6xJc527nvr4RdOXbi85FVXi9skdc=; b=fH9wxfTIjzfHa7HWFeWHMQu1lzSnZYl8rShWBP2JKkn6nkvQHjOzXWweDiPnxNMhIE /xYJas5omYRe8ca5w5EYN/S1XFDkHBEJItsxGmOfeq3DpHGItXYjBenscHl7YyViDuhN dt0eNrwOR3Zu1UKABYQg+bacEU5JpuvHwrPRZHOMF603I5CMrd946SEMWSQRxTRXZKQ9 FSRSr8TsNz02XrHV9i+qYGvN5T0HrXA6MTh/OjutBYEnnvW3GYMzz9DmslA177sYAIeP pdvh6j3bmbf5OX+NyzBjk7LMkEz0pZq6Htvtnh+FlXjkUjTc3j9iORixGwpdr70nYtGH VIMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=UCl4wVbcsht/zku6xJc527nvr4RdOXbi85FVXi9skdc=; b=b8psHFf4asWd6AYD92vht0jt4Nw8BB8sEiYuR3v/g5JZHJVsM6OYNx3vG6LoeE5ESq qUYZwcj3PaLeZNFxrxFhQvfgmLWTzTnk4GoOb8agoNw41EnMl55no2lqvF2mNjrC14Ms wtjPQX4mPNvjW6fU/VAQ+Tj6s+nJVFqLLkct2+n//YtKnCqBIfQLQ/WM3Okvgs+7RwbD Gn3bKezeitfe/Y79u2wbMFi6oi6BBHIdm7gYB+OoA8voxSBoj0l3EHCb72QcuwCiSG9x Hv90I5yQ5Duod/Di1blgwiItsjIly/pL3WFtz00WhcUF+t9u7eZUFyt6KcI4HSN2C7lv Nxxw== X-Gm-Message-State: AOAM531N2OT/h9aEcjFduL1g+pIlWnjonxvEA+AC+nHEhp1v/yLbzZeg GmdJF52sXAr8vNqt3//s73c2vn3+0WE= X-Received: by 2002:a17:902:c404:: with SMTP id k4mr39348377plk.99.1594071481735; Mon, 06 Jul 2020 14:38:01 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id g26sm17711776pfq.205.2020.07.06.14.38.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Jul 2020 14:38:01 -0700 (PDT) Subject: Re: [PATCH] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes To: Prashant Malani Cc: Enric Balletbo i Serra , Benson Leung , Linux Kernel Mailing List , Yu-Hsuan Hsu References: <20200704142607.171400-1-linux@roeck-us.net> <20200706185230.GA792857@google.com> <20200706194120.GB180826@roeck-us.net> From: Guenter Roeck Autocrypt: addr=linux@roeck-us.net; keydata= xsFNBE6H1WcBEACu6jIcw5kZ5dGeJ7E7B2uweQR/4FGxH10/H1O1+ApmcQ9i87XdZQiB9cpN RYHA7RCEK2dh6dDccykQk3bC90xXMPg+O3R+C/SkwcnUak1UZaeK/SwQbq/t0tkMzYDRxfJ7 nyFiKxUehbNF3r9qlJgPqONwX5vJy4/GvDHdddSCxV41P/ejsZ8PykxyJs98UWhF54tGRWFl 7i1xvaDB9lN5WTLRKSO7wICuLiSz5WZHXMkyF4d+/O5ll7yz/o/JxK5vO/sduYDIlFTvBZDh gzaEtNf5tQjsjG4io8E0Yq0ViobLkS2RTNZT8ICq/Jmvl0SpbHRvYwa2DhNsK0YjHFQBB0FX IdhdUEzNefcNcYvqigJpdICoP2e4yJSyflHFO4dr0OrdnGLe1Zi/8Xo/2+M1dSSEt196rXaC kwu2KgIgmkRBb3cp2vIBBIIowU8W3qC1+w+RdMUrZxKGWJ3juwcgveJlzMpMZNyM1jobSXZ0 VHGMNJ3MwXlrEFPXaYJgibcg6brM6wGfX/LBvc/haWw4yO24lT5eitm4UBdIy9pKkKmHHh7s jfZJkB5fWKVdoCv/omy6UyH6ykLOPFugl+hVL2Prf8xrXuZe1CMS7ID9Lc8FaL1ROIN/W8Vk BIsJMaWOhks//7d92Uf3EArDlDShwR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SuCn7UG+qVWZeKEsFKFOkynOs3pVbcbq1pxbhk3TRWCGRU5JolI4ohy/7JV1TVbjiDI HP/aVnm6NC8of26P40Pg8EdAhajZnHHjA7FrJXsy3cyIGqvg9os4rNkUWmrCfLLsZDHD8FnU mDW4+i+XlNFUPUYMrIKi9joBhu18ssf5i5Q= Message-ID: Date: Mon, 6 Jul 2020 14:37:59 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/6/20 1:07 PM, Prashant Malani wrote: > On Mon, Jul 6, 2020 at 12:41 PM Guenter Roeck wrote: >> >> On Mon, Jul 06, 2020 at 11:52:30AM -0700, Prashant Malani wrote: >>> 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? >>> >> >> It seemed to be prudent to assume that this code is not going to be >> updated whenever a new EC error code is added. Doing nothing would >> risk returning 0, and addding WARN_ON or dev_warn seemed excessive. >> Having said that, I don't really have a strong opinion one way >> or another, and I'll be happy to change the code to whatever people >> think is appropriate. > > Thanks for providing the rationale. I think if a new EC error code is > added (and this array isn't updated), > msg->result < ARRAY_SIZE(cros_ec_error_map) would return false, and > the code block would return -EPROTO. > Some scenarios: Developer 1 adds EC_RES_SOME_ERROR, and does not update the array. Developer 2 adds EC_RES_SOME_OTHER_ERROR and updates the array, but does not realize that EC_RES_SOME_ERROR is missing as well, and does not add it. Developer 3 adds two (or more) error codes, and does not update the array. Someone else later finds a -EPROTO return code and adds the necessary translation to the array. That translation happens to be for the last error code. The developer doing that does not realize that other error codes are missing as well, or does not realize the impact, and does not add translations for the other missing error codes. Overall there are too many situations where this can go wrong for me to trust that it never will. > I'll defer to the maintainer's opinion(s), but I think we can remove > the condition after '&&'. > I thought about it, but I find that I don't feel comfortable with doing that. If that is what is asked for, would you mind providing a separate patch which doesn't have my name on it ? Thanks, Guenter