Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp365208lqs; Thu, 13 Jun 2024 12:15:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUHNsvN4Xm4WR4BqAe9Yo7StGN60DLDZ7Qg6xCEukVOWNH6oWZ1w1O/r+PfL9VlCjjaAyWGj9u6IqnT8h/SxhXJlctgR20i5uLOvZSTYQ== X-Google-Smtp-Source: AGHT+IFN54QXUOGREUd4g9E829eeM5SYCluB7678FykzTowWXIzwHkrlZQscy21x0tnSzBvN7Qe3 X-Received: by 2002:a17:902:d4c5:b0:1f8:3b20:3813 with SMTP id d9443c01a7336-1f8625c1762mr6017325ad.12.1718306101422; Thu, 13 Jun 2024 12:15:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718306101; cv=pass; d=google.com; s=arc-20160816; b=0x/iQgTAnlEZrRVaof3Orqc8rn/6Eex5qA/kZo+BKA3VQFqOv1IN2QoSk+YyMV43Ht 7XhLrdvS7Z+8dId/oqy5VsYySoNWI7/po6/F7Qcbub8EhS2ZtRvLIgV8DtFyW2mjp3OG op908Y76CogxJ2sMfZRhhz81A1rRFV+V9pCA5CWpwHaccaCp4Me6M0VpZW4qqLBpR0gH a3oomT6L3V1tj6rbEEna3LbuLEuc3ieJ+bl8xXCOqtzVDomOu5wrkcmyy+HiaQnSqUdd 72tIV33Dx93vh5dqh2+8DjqgAU4vRflFVnPr8e1hW6B9UVapTghAUxFXl/1PgelCIBsP mG0g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=1Y2fqfo34jYOSwwgMfXN35xvUGJse2iPb8SuE0d9SRI=; fh=OgM3vTl7V9SvGkq2cAR5xgIvu8TGa/FjVHD3x6LG5IM=; b=nnOwNagNepI5SQjcRocMFtapjC6Gf8iq41ph+CS3yHSLSXIHyZwpA6Zdeh8pQcG2E6 hq0PrJ1yGucUrUm2P/a7xNX9zsi9qWKyig5NAG0j6BWjxFZyOltoXU5R2dWznn+76TU5 55Mvv2QFxgi1d6EUjsNUMms/GN36jm+kUXOo+Ay6ewE069O/9B6EM6rhvh/AG/qcTT3G 9aYRREccky3MgDaaxiUU/iukFHKlu6nMvAHNHwJqOCoAEX8yyG9WpGQtfQWrpsDht8zF OhgAEq8/sqp8IxMqyC3Y3ekxSvRSsIkAnoNblLZMZNOd1inXuE+/HRMdIACqEgRlX8SU ftfw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@jubnut.com header.s=MBO0001 header.b=L4RxlyWP; arc=pass (i=1 spf=pass spfdomain=jubnut.com dkim=pass dkdomain=jubnut.com dmarc=pass fromdomain=jubnut.com); spf=pass (google.com: domain of linux-kernel+bounces-213890-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213890-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=jubnut.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f855ee1921si10365835ad.345.2024.06.13.12.15.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 12:15:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213890-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@jubnut.com header.s=MBO0001 header.b=L4RxlyWP; arc=pass (i=1 spf=pass spfdomain=jubnut.com dkim=pass dkdomain=jubnut.com dmarc=pass fromdomain=jubnut.com); spf=pass (google.com: domain of linux-kernel+bounces-213890-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213890-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=jubnut.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2712F285CB0 for ; Thu, 13 Jun 2024 19:14:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 671F314C583; Thu, 13 Jun 2024 19:14:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=jubnut.com header.i=@jubnut.com header.b="L4RxlyWP" Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4DF1149E1A; Thu, 13 Jun 2024 19:14:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.161 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718306069; cv=none; b=GqCZgXHjcNehXRKLyL90cfpFY2dXui0pe9woeLOa7cGasi6cvb8rANnXB1X5PYZe0TKqOB9pEigySmOvnJutUKEMdC66iLPwQOvU05D+wt5zs1h/vPAF1nupaP7XV0thd1E8robgjdIjmbLudguJYfvDRnn605DogAZJjlZgRGQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718306069; c=relaxed/simple; bh=SInef4o5M1AK1ysJCyquEWbuWWbqBrt9x4MkjqwsuwI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=AXGEc5a5QEqpYGcAZ1DtXDW2jsqWamHiZzZUyHNykw+mycbFEmSz8ASBq/mXaw3rkJoKeTTPqZqOe/Z3RmVl95lqL2azrkKqaSrwWv5b07szaiPZaxgpzMn+ws4qqCWqqJgSAO9t6YJJz2z6DUW2xniZe0VaXWQspPEpFdTPe6E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=jubnut.com; spf=pass smtp.mailfrom=jubnut.com; dkim=pass (2048-bit key) header.d=jubnut.com header.i=@jubnut.com header.b=L4RxlyWP; arc=none smtp.client-ip=80.241.56.161 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=jubnut.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jubnut.com Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4W0XCF1gwBz9sxf; Thu, 13 Jun 2024 21:14:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jubnut.com; s=MBO0001; t=1718306057; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1Y2fqfo34jYOSwwgMfXN35xvUGJse2iPb8SuE0d9SRI=; b=L4RxlyWPdRZoDVbvUgoWt2/kWCnKJ7oAPnbO+v1RwHWV3LF2hCxNYY9N8vjMGTXuouXGBK iphm4wecR/ExSX/HS+R1hFOudMbV8ifHxVucEX5U5phwek+q6L4NNKO0Cjk2P6dY54Mv0S 8exe4k+Waxw2CB0qK5agl+NEZG/pxZJSGRDjpw5lhIZSFSvRthHjbKnDhqjN8kJML2r9jT ws2jnB4NgmRYtSCK1gONy5RMpoIEHKYvQU4j60oGZa9wXaUZ9hkdJAzJiwOd5c9ekE64Gr ayP9w+14JxfuicqdivAQiuPAAHOrxbULdqg4p/bM9mSMlv+jYNe75tnrx/SQzw== From: Ben Walsh To: Tzung-Bi Shih Cc: Dan Carpenter , Benson Leung , Guenter Roeck , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH] platform/chrome: cros_ec_lpc: Fix error code in cros_ec_lpc_mec_read_bytes() In-Reply-To: References: <87sexgrdk4.fsf@jubnut.com> Date: Thu, 13 Jun 2024 20:14:14 +0100 Message-ID: <87o784ac55.fsf@jubnut.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Queue-Id: 4W0XCF1gwBz9sxf Tzung-Bi Shih writes: > On Thu, Jun 13, 2024 at 05:51:39PM +0100, Ben Walsh wrote: >> >> Thanks for fixing this! Unfortunately `in_range` returns -EINVAL if >> length == 0 (see the definition of `fwk_ec_lpc_mec_in_range`). I'm sure >> this broke something in my testing, but I can't find what it was now. > > Somewhere like [1] could accidentally get the -EINVAL. > > [1]: https://elixir.bootlin.com/linux/v6.9/source/drivers/platform/chrome/cros_ec_lpc.c#L232 Yes. It turns out I'm getting it in: cros_ec_query_all -> cros_ec_proto_info -> ... -> cros_ec_pkt_xfer_lpc /* Read response and update checksum */ ret = cros_ec_lpc_ops.read(EC_LPC_ADDR_HOST_PARAM, args.data_size, ^^^^^^^^^^^^^^^ msg->data); (as Dan suggested in his email). >> or 2. Put in a check for length == 0. >> >> or 3. Change the logic in `fwk_ec_lpc_mec_in_range`. Although I'm not >> sure what the correct answer is to "zero length is in range?" >> >> I prefer option 2. What do you think? > > How about drop the length check at [2]? > > [2]: https://elixir.bootlin.com/linux/v6.9/source/drivers/platform/chrome/cros_ec_lpc_mec.c#L44 > This works, but we still end up calling cros_ec_lpc_io_bytes_mec() with zero length. Although this seems to work fine, we could put a length check at the top of cros_ec_lpc_read_bytes() to avoid it. >> >> Dan Carpenter writes: >> >> > We changed these functions to returning negative error codes, but this >> > first error path was accidentally overlooked. It leads to a Smatch >> > warning: >> > >> > drivers/platform/chrome/cros_ec_lpc.c:181 ec_response_timed_out() >> > error: uninitialized symbol 'data'. >> > >> > Fix this by returning the error code instead of success. >> > >> > Fixes: 68dbac0a58ef ("platform/chrome: cros_ec_lpc: MEC access can return error code") >> > Signed-off-by: Dan Carpenter >> > --- >> > drivers/platform/chrome/cros_ec_lpc.c | 4 ++-- >> > 1 file changed, 2 insertions(+), 2 deletions(-) >> > >> > diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c >> > index ebe9fb143840..f0470248b109 100644 >> > --- a/drivers/platform/chrome/cros_ec_lpc.c >> > +++ b/drivers/platform/chrome/cros_ec_lpc.c >> > @@ -139,7 +139,7 @@ static int cros_ec_lpc_mec_read_bytes(unsigned int offset, unsigned int length, >> > int in_range = cros_ec_lpc_mec_in_range(offset, length); >> > >> > if (in_range < 0) >> > - return 0; >> > + return in_range; >> > >> > return in_range ? >> > cros_ec_lpc_io_bytes_mec(MEC_IO_READ, >> > @@ -158,7 +158,7 @@ static int cros_ec_lpc_mec_write_bytes(unsigned int offset, unsigned int length, >> > int in_range = cros_ec_lpc_mec_in_range(offset, length); >> > >> > if (in_range < 0) >> > - return 0; >> > + return in_range; >> > >> > return in_range ? >> > cros_ec_lpc_io_bytes_mec(MEC_IO_WRITE, >> > -- >> > 2.43.0 >>