Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2645187pxb; Tue, 21 Sep 2021 04:43:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjP4kZWHExPYKu8eybJsch3s5sF89ddupsL3Cqzy6ZsmWmKCub6AcH73/99pxBOw1tPjCI X-Received: by 2002:a5d:9047:: with SMTP id v7mr19601676ioq.214.1632224604568; Tue, 21 Sep 2021 04:43:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632224604; cv=none; d=google.com; s=arc-20160816; b=eGUrmIjwXk/OFnpDlvzmDJ0Up6xPqgl4ZeL6kVemU77ipCZu2g9A3bECWs313mZcUP IFWceQdjx8DXyCNxT10u8Uvyu0oweDAF4q5RA3jHTltiVYmXJfmmJjqtVZWWSGfIgfyH fASWnKLl/34s4h6H4nYjiNJn0h29iDWfpIrdkwFVoJYEHk3mnd923h9o63pt3rrwu9jJ IZlljPjYuIZYZlBV2uPY3YSlgZcLKTf1VxwkP8v2hVh6uobU+cI5JCALL8LXr+KrAQB5 VDBCAtVlAiUa9fDjh2m4QA7uGhXYm0wYKXtw2D5BzaMisaD3dxpiMeuumbHPTYo7SjP/ Ztmg== 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=mUGTfxalNUjjWIXL6NGEMIk7NZxTN5evAWQSKm2dfB0=; b=qahXlmVdM6pS1HRgOfG+h9JfT93WJw8Ax0/rfSzBuVXYdtyz22p7nhtd2Mdu1B9nwK xi5nx76HY/r5Q+N2FuOoGeTbaSQjDPEY2f68DT3EneRHVYfR1MSs6HjBareOKbiTHCZ6 b+u43OgmhxHDAymDQrEw/e3ipXkYG/etJkehycwNsT3ESMjIE6AtVKuO7lWGAOZ79fQP 4XIjr04IWNE82ls5xVIuo7GuetFHyElgUaOTg3d2fP9aVjdmiBv4W4g0549UnpPhQc6D qjkwxoHJu1ASUZ3EEEj2oA5fHQpxQJuovM+FiweW4PJ50IDcSE2PTkQ6Vc4K6QFwLSpO 4EEw== 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 n12si1227638iob.114.2021.09.21.04.43.10; Tue, 21 Sep 2021 04:43:24 -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 S232511AbhIULnj (ORCPT + 99 others); Tue, 21 Sep 2021 07:43:39 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:45658 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232439AbhIULnj (ORCPT ); Tue, 21 Sep 2021 07:43:39 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 5D9E91F41E17 Subject: Re: [PATCH] platform/chrome: cros_ec_proto: Fix check_features ret val To: Prashant Malani , linux-kernel@vger.kernel.org Cc: Benson Leung , Guenter Roeck , "Gustavo A. R. Silva" References: <20210916014632.2662612-1-pmalani@chromium.org> From: Enric Balletbo i Serra Message-ID: Date: Tue, 21 Sep 2021 13:42:04 +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: <20210916014632.2662612-1-pmalani@chromium.org> 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, 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. Other than that the patch looks good to me. Thanks, Enric > + return false; > + } > > msg->command = EC_CMD_GET_FEATURES + ec->cmd_offset; > msg->insize = sizeof(ec->features); > @@ -839,7 +841,7 @@ int cros_ec_check_features(struct cros_ec_dev *ec, int feature) > kfree(msg); > } > > - return ec->features[feature / 32] & EC_FEATURE_MASK_0(feature); > + return !!(ec->features[feature / 32] & EC_FEATURE_MASK_0(feature)); > } > EXPORT_SYMBOL_GPL(cros_ec_check_features); > > diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h > index 02599687770c..55844ece0b32 100644 > --- a/include/linux/platform_data/cros_ec_proto.h > +++ b/include/linux/platform_data/cros_ec_proto.h > @@ -227,7 +227,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, > > u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); > > -int cros_ec_check_features(struct cros_ec_dev *ec, int feature); > +bool cros_ec_check_features(struct cros_ec_dev *ec, int feature); > > int cros_ec_get_sensor_count(struct cros_ec_dev *ec); > >