Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2417857iof; Wed, 8 Jun 2022 04:41:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyecLP+sEeoZ8a5j7IP7vKBYynCqnSvicSRUnyZxDsgtaun4lVeXkfYRNYzIznKB7bkPcyU X-Received: by 2002:a17:90b:2247:b0:1e8:9f24:269a with SMTP id hk7-20020a17090b224700b001e89f24269amr9705113pjb.14.1654688506905; Wed, 08 Jun 2022 04:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654688506; cv=none; d=google.com; s=arc-20160816; b=TkZutaVOGCCCaGlLlCsCNCOkFFZWk89ZP1TIRLKeop+82qOwq93tQc/TFBdOGTApuF sLez3C9Ipgb0vgBHl6p9doYGcIEu7kDIcUM6jpUCQAEZ5ulTBcRX3soGfNe9g6qtPYYI eAZS0xIOabYjSPsb2+JSWw8TeMrwl62pDVhGfqy/wR+1VQ9MPO9WO8esb3rrdU6NUiWi s4jxu+zC2tY43LLiN0FMSx5jZrukpPd+cY/m72pd3AV8bG175XDT4o+atZGqsartrsnI vPn7rqM1MvuaiISTzyHU5JXEi/yUpMcLpDpyCRBArkKwIJ9mVARoHeDwOhlF7Ka3HBGT 12KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PX4POaUFT7UXHLMx+DdeEi3EBVpf3Q9Jhz6TnRLwVBg=; b=kcthmYOMSTLmuq1V+XTMdkCXKZS+JAQ/mMReETaT8YtHpc9PgxRHw2UcmhMv8b29mg DPi0IQCT8uF8B5y4SljtE9C/S5xHHdUa9lOxUbD54IUkTLDeMA76DG0ByZtpFSDBnTcO pymt7F5/cE3ORLZRfjSp3SJJR4jXFf5GzKY43wrbIUX93Xxv43cRFzyq79lZy504eQTA AOTIg++RYR90yFhJfYYqlC9wXJYq6J8r3770WyZKXEOS+TBrfqmWTtEIMjknTzF9g2Z4 y8VDRyzWu/aSkNhWlTwBqG5XP4VrlH1A7f1TO3ITGt5B9KQf0pFZT1z5NVSgzg5N8NRl EkTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i5ZVUNYs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u21-20020a056a00125500b005186df822dfsi2153687pfi.378.2022.06.08.04.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 04:41:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i5ZVUNYs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AE37A23236C; Wed, 8 Jun 2022 04:10:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236967AbiFHLJg (ORCPT + 99 others); Wed, 8 Jun 2022 07:09:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237848AbiFHLIQ (ORCPT ); Wed, 8 Jun 2022 07:08:16 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C2721F98C2 for ; Wed, 8 Jun 2022 04:08:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 400B3B826F0 for ; Wed, 8 Jun 2022 11:08:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BB26C341C0; Wed, 8 Jun 2022 11:08:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654686483; bh=jPByg0s6gOr1IG5nl89kHVvmg5BipfwdxFF0RGN3acs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i5ZVUNYsG8FbqIVev1zST5myOazD0Q76aCA35UkOpKrYc3QVNjXK4H0dmNaY9bGfV aomS/ku9QhTOBUhbdPgM4fkizvxRDg3uj7hDBKEqv4LNLl2c3GYkB11zXWYNrDHi/p z5w4ZIoxJLXhv+/Si/vdYnWStxtH1lO7EAdu8vS9aMXn5OEetYY5J/K1zts0lo0WNn 9G9nHMAovv9zEqM6Ons/S+U+DUzbsbXlBoQm9xE/Pe8bfNXngz/128Lr+7s5K4+G57 bMwqhReIpjUvaJWTJYtdJ/o6Qblxi+U2cJDDnwb+QJZTi203HUnRZaH+6vVTzErSp8 ke3iagvJjarqg== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 12/23] platform/chrome: cros_ec_proto: handle empty payload in getting info legacy Date: Wed, 8 Jun 2022 11:07:23 +0000 Message-Id: <20220608110734.2928245-13-tzungbi@kernel.org> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog In-Reply-To: <20220608110734.2928245-1-tzungbi@kernel.org> References: <20220608110734.2928245-1-tzungbi@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org cros_ec_get_proto_info_legacy() expects to receive sizeof(struct ec_response_hello) from send_command(). The payload is valid only if the return value is positive. Return -EPROTO if send_command() returns 0 in cros_ec_get_proto_info_legacy(). Signed-off-by: Tzung-Bi Shih --- Changes from v2: - Separate Kunit test to another patch. drivers/platform/chrome/cros_ec_proto.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index 04b9704ed302..473654f50bca 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -356,7 +356,7 @@ static int cros_ec_get_proto_info_legacy(struct cros_ec_device *ec_dev) struct cros_ec_command *msg; struct ec_params_hello *params; struct ec_response_hello *response; - int ret; + int ret, mapped; ec_dev->proto_version = 2; @@ -377,12 +377,18 @@ static int cros_ec_get_proto_info_legacy(struct cros_ec_device *ec_dev) goto exit; } - ret = cros_ec_map_error(msg->result); - if (ret) { + mapped = cros_ec_map_error(msg->result); + if (mapped) { + ret = mapped; dev_err(ec_dev->dev, "EC responded to v2 hello with error: %d\n", msg->result); goto exit; } + if (ret == 0) { + ret = -EPROTO; + goto exit; + } + response = (struct ec_response_hello *)msg->data; if (response->out_data != 0xa1b2c3d4) { dev_err(ec_dev->dev, -- 2.36.1.255.ge46751e96f-goog