Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp291664pxb; Wed, 22 Sep 2021 02:14:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGBup0oNcrKdUtstPfTX4kAaymaGDLPO6KlvvICsprkGEYGiQFMihupRq/2kdDjhxUWVzu X-Received: by 2002:a92:440c:: with SMTP id r12mr24403043ila.174.1632302056777; Wed, 22 Sep 2021 02:14:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632302056; cv=none; d=google.com; s=arc-20160816; b=ja7NRGJsJP6TbLsweqxUHv+JZCQ/2RMNvYwhiRv2fx6AjIh8UlRgHsEmaTd1CT/vYp KF4ILqlWBxuEUHygbOnhNBApWmYtV2drA5HQ1r4xnnBd/C8t7FKXwhr0j3HQYtXhAvFF ZKI1+OjmEh9v/rAnAtQoFt0Mg+Y/DajM4jyfo91qyZtmwkKAh9z9curo+RvPLkgD3+ZL g+I0ljOncGGByXgGZollyBDA2chAaNu9dTQ4s0s56JH5k0z2HyvqbHaS7pn/wTnKIMP9 ZGl/6hJR1EqIo99d/iNFELsuU+j0z4KetpTgDmV3+SjPSX1DEgPjZGrrnEvCtEpt5/7R OG+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=LL8s9n2uPHlrxFIoBg+8K1IkvPi8HW6m5pzVXV0lBsw=; b=DhRbeLEHHvqOsOxKtRYNzQEZWNlisKQ1vQdIQzMCsGSZla1fvd8JeZ1TqjoMUgM/dO 4Xpp4NoG86yeJuhA7N1ecLDyt7N6dUW5iNlJueBIM59BYdJAC21A1cPdM0fCqzn7k9bE YFa+zJkslMb1c8+ERFjryNG+53BPGaKYYqK3sUZcdg/s7HR1tHxlFwIdBspU0T43gaoo 0398tDISzR55wHcaO7pmGryu0Wn+ZRGT0u9b/3SkCZc2O6yiuDqcZJw43DYFhFI3VtKc aAYda85TjjfbVKn7cbt+W86lxwUki1TjgAykOtKTIv6m8PIbxMaZbPvOX4r6h49gwZhc IrXg== 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 x5si1663664ilp.149.2021.09.22.02.14.04; Wed, 22 Sep 2021 02:14:16 -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 S234367AbhIVJN6 (ORCPT + 99 others); Wed, 22 Sep 2021 05:13:58 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:56672 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234183AbhIVJN5 (ORCPT ); Wed, 22 Sep 2021 05:13:57 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 2D9E31F42CDF Subject: Re: [PATCH] platform/chrome: cros_ec_proto: Fix check_features ret val To: Prashant Malani Cc: linux-kernel@vger.kernel.org, Benson Leung , Guenter Roeck , "Gustavo A. R. Silva" References: <20210916014632.2662612-1-pmalani@chromium.org> From: Enric Balletbo i Serra Message-ID: Date: Wed, 22 Sep 2021 11:12:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Prashant, On 21/9/21 19:29, Prashant Malani wrote: > Hi Enric, > > Thanks for reviewing the patch. > > On Tue, Sep 21, 2021 at 01:42:04PM +0200, Enric Balletbo i Serra wrote: >> Hi Prashant, >> >> Thank you for the patch. Just one comment below ... >> >> On 16/9/21 3:46, Prashant Malani wrote: >>> The kerneldoc for cros_ec_check_features() states that it returns 1 or 0 >>> depedending on whether a feature is supported or not, but it instead >>> returns a negative error number in one case, and a non-1 bitmask in >>> other cases. >>> >>> Since all call-sites only check for a 1 or 0 return value, update >>> the function to return boolean values. >>> >>> Signed-off-by: Prashant Malani >>> --- >>> drivers/platform/chrome/cros_ec_proto.c | 12 +++++++----- >>> include/linux/platform_data/cros_ec_proto.h | 2 +- >>> 2 files changed, 8 insertions(+), 6 deletions(-) >>> >>> diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c >>> index a7404d69b2d3..a34cf58c5ef7 100644 >>> --- a/drivers/platform/chrome/cros_ec_proto.c >>> +++ b/drivers/platform/chrome/cros_ec_proto.c >>> @@ -808,9 +808,9 @@ EXPORT_SYMBOL(cros_ec_get_host_event); >>> * >>> * Call this function to test whether the ChromeOS EC supports a feature. >>> * >>> - * Return: 1 if supported, 0 if not >>> + * Return: true if supported, false if not (or if an error was encountered). >>> */ >>> -int cros_ec_check_features(struct cros_ec_dev *ec, int feature) >>> +bool cros_ec_check_features(struct cros_ec_dev *ec, int feature) >>> { >>> struct cros_ec_command *msg; >>> int ret; >>> @@ -818,8 +818,10 @@ int cros_ec_check_features(struct cros_ec_dev *ec, int feature) >>> if (ec->features[0] == -1U && ec->features[1] == -1U) { >>> /* features bitmap not read yet */ >>> msg = kzalloc(sizeof(*msg) + sizeof(ec->features), GFP_KERNEL); >>> - if (!msg) >>> - return -ENOMEM; >>> + if (!msg) { >>> + dev_err(ec->dev, "failed to allocate memory to get EC features\n"); >> >> In case of failure you will be noticed by the allocator, prints after >> [k|v][m|z|c]alloc() functions are not needed, so I think you can just return >> false here. >>> > > Makes sense; I can make the change, but I had one question: > > If we solely return false, how will we tell from the logs that the > allocation error message was associated with this driver? Only returning > false means the driver probe (e.g cros-ec-typec) will continue (just assuming a certain feature > is not present). Wouldn't having this error message make this clear? > So I tried to find some doc about this without luck. But I think it has been an unwritten rule that GFP_KERNEL allocations for small allocations will never fail. If you system fails to allocate that small amount of memory you probably have bigger problems to solve and the above message is not really useful, even confusing, as the focus, likely, shouldn't be in this driver to solve the problem. Thinking a bit more about this change, and after your question, I don't really like functions not returning an error in the unlikely case that fails. On the other hand, I like this function return a bool as is a bit more clear IMO, so I'm wondering if wouldn't be better don't use dynamic memory here (I know that this is not really related to your patch) And another thing that I detected, now that you're returning a bool is that in drivers/platform/chrome/cros_ec_typec.c there is: typec->typec_cmd_supported = !!cros_ec_check_features(ec_dev, typec->needs_mux_ack = !!cros_ec_check_features(ec_dev, I think that you can remove the !! now. That could be in another patch. Thanks, Enric > Best regards, > > -Prashant >