Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2591097iof; Wed, 8 Jun 2022 08:06:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx20858q5bSuiyQ2imT3F5lGbzxJbleckkeUEkPPXmHxIyIicJO1EA8Lz3FYe4KB+QlM23P X-Received: by 2002:a63:fa15:0:b0:3fd:9170:9496 with SMTP id y21-20020a63fa15000000b003fd91709496mr16797665pgh.162.1654700770634; Wed, 08 Jun 2022 08:06:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654700770; cv=none; d=google.com; s=arc-20160816; b=zd+p8Ieeg+br7S61uRE5cMSoty6/MlgRZ4meg9ANimqKvbN6hDDLtP8/Cs9RBAvSH5 UH8EgJGBv5uQinD5lrgG3WaBGKIEkF31I+M+edJCkxJnutlaQKgRg5LkEImnZgTqJ9fg uAsDsZyKkVX7RgXbF/2VVsEKjGWJ14c2hxIHpjRFC3FD2I7T/GAGLBlWQokLRmVe6YV2 kdb9i0F2XGqFPS+8V28a93iTJoHbCSrmv/Q+uRyFioSgLkQqVzSIiKw8DDwhgduqxZhb RdQvJRxhIoghiWJN40laSgiqPC6YikQjLQacrfjfctOTBVhIKREFWKa/zG3TyhcODg8K KNzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=oIgzWiqZ9B5DH/Ah6uNm4nobex6Dnfmxiak8xN0J0Rg=; b=X/mh4AUjKnM8PbjJf3YWLj5OzVAHvycZmbS1W4IRZFiFQS+yreEXtWQhNxnafr4z9f 6hc16+OehpZJPU6blj4Gbi++1+wqehFwL+oYJrGfw3C72/dVA3Bpbz9p52V1bKlCUy0t 40wNI5in+bpJMt4qedqNOVaBkSMBlddH+zewuLz65HgmwVw1OCFbvey1/xDGHAkJEodD IJpVRVO25Gk+T+SGvxqvnfGKOdS2XhBuOM06ClzaDlB3mMBoBGD5u193o2zqBw8+lArP V0/c+tAT4thdiIdXAXTCXbO4JaSv4pPNBO6J1qzdx/Tj7G3/pxmBYpwILlSQRPtXlXHz Acvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=dWpsiqdR; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l198-20020a633ecf000000b003f63a63a102si27517709pga.251.2022.06.08.08.06.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 08:06:10 -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=@google.com header.s=20210112 header.b=dWpsiqdR; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8017FA0D25; Wed, 8 Jun 2022 07:38:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241537AbiFHOhe (ORCPT + 99 others); Wed, 8 Jun 2022 10:37:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241508AbiFHOhb (ORCPT ); Wed, 8 Jun 2022 10:37:31 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9316950B3E for ; Wed, 8 Jun 2022 07:37:24 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id v25so27391427eda.6 for ; Wed, 08 Jun 2022 07:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oIgzWiqZ9B5DH/Ah6uNm4nobex6Dnfmxiak8xN0J0Rg=; b=dWpsiqdRek7kuhblNqCkOUDbqDqFCbD401L+uVtIYl+aV6TVlPNqrWftvFHLbeyON5 /U5PIaeZPpZd+M8qlIkzZozaULrWD2keeY4M9a31K0N6odL1/my2Qw2YQV8HB8htGDcR +jccJDDPU3uc2BCvmGrl8TA11HMeBCOYGZzZKiEgxnzBlXor0O+x6oND7ZjIBYBTsj6h lt8BNSfH347kyyDE5Ty6IFg6JqKSevWLqGN2FLDmV0r/kE768ujIgSNxcbs4fdtSqcsQ yqjh88Ud3fhocxI54S2Ky5W9BnutWGyl9W9+Xk46rAIi781BoIyGzdJwaob1bhjPzgu8 PFdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oIgzWiqZ9B5DH/Ah6uNm4nobex6Dnfmxiak8xN0J0Rg=; b=BjR6PYzc8ih5uwrtfJeqhWNkba8PtcfQTWFbWCClEZ5r4OlE6vtIw5gWMJ3fZxqE+S ik/gDigvga31T9/NJ0toW1JCgPB/c61He9W+R5sqbwMQGqO6u3GK9M/aTIRkU5Vt0gW9 p5B4zuN/zbPdcteGWEWH//cM9KQpx+Tnf8NnviWdcu8m67zk/5thh+GCkFi0Z04uuzWh Te7O/rbsPv2V+ptJkLizCcf5Q5yWndEePYgCrCd4J/LF/Y6Yg5M7c2cYNrMc/6rtI177 oQ1WgVb6Ezgx3TWJ1/0OpmTJveyqbeA3j9hPvF9T2KPJRq2YXTayeFeP//D6wN4OBTIr MQYA== X-Gm-Message-State: AOAM533jS3NW5bPEE3ONjTYnCSFuYNO2QrH4UUEzjXDjtrx1xy2cXq9T dBata3hRoY6SKkPXJA8hdw1SCiTMZeUc4IGZDHI8rB9nk3Sdiw== X-Received: by 2002:a05:6402:3688:b0:42d:d3ba:4725 with SMTP id ej8-20020a056402368800b0042dd3ba4725mr40113923edb.212.1654699042272; Wed, 08 Jun 2022 07:37:22 -0700 (PDT) MIME-Version: 1.0 References: <20220607145639.2362750-1-tzungbi@kernel.org> <20220607145639.2362750-9-tzungbi@kernel.org> In-Reply-To: From: Guenter Roeck Date: Wed, 8 Jun 2022 07:37:10 -0700 Message-ID: Subject: Re: [PATCH v2 08/15] platform/chrome: cros_ec_proto: handle empty payload in getting proto info To: Tzung-Bi Shih Cc: Benson Leung , Guenter Roeck , "open list:CHROME HARDWARE PLATFORM SUPPORT" , linux-kernel Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 On Tue, Jun 7, 2022 at 7:17 PM Tzung-Bi Shih wrote: > > On Tue, Jun 07, 2022 at 11:47:56AM -0700, Guenter Roeck wrote: > > On Tue, Jun 7, 2022 at 7:57 AM Tzung-Bi Shih wrote: > > > > > > cros_ec_get_proto_info() expects to receive > > > sizeof(struct ec_response_get_protocol_info) from send_command(). The > > > payload is valid only if the return value is positive. > > > > > > Add Kunit tests for returning 0 in send_command() and handle the case in > > > cros_ec_get_proto_info(). > > > > > That should be two separate patches. > > Ack, will separate them in next version. I put them together because I wrote > Kunit test first to make sure the second half takes effect (somehow TDD). > > Could I still put the Kunit patch first (even if it introduces Kunit test > failure)? > Sorry, I am running behind with e-mails. If you want to, but why not let the fix come first ? If the unit test patch is first, mayle add a note after --- indicating that it is expected to fail and will be fixed with the next patch. Thanks, Guenter > > > > > Signed-off-by: Tzung-Bi Shih > > > --- > > > No v1. New in the series. > > > > > > drivers/platform/chrome/cros_ec_proto.c | 5 + > > > drivers/platform/chrome/cros_ec_proto_test.c | 132 +++++++++++++++++++ > > > 2 files changed, 137 insertions(+) > > > > > > diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c > > > index 893b76703da6..6f5be9e5ede4 100644 > > > --- a/drivers/platform/chrome/cros_ec_proto.c > > > +++ b/drivers/platform/chrome/cros_ec_proto.c > > > @@ -314,6 +314,11 @@ static int cros_ec_get_proto_info(struct cros_ec_device *ec_dev, int devidx) > > > goto exit; > > > } > > > > > > + if (ret == 0) { > > > + ret = -EPROTO; > > > + goto exit; > > > + } > > > + > > > > I think you can move that into the if() statement above (which already > > checks for ret >=0), > > making it a special case of that situation. > > Nope, there is no "ret >= 0" (you could be confusing with > cros_ec_get_host_event_wake_mask()). > > The result flow roughly like: > > ret = send_command(...); > if (ret < 0) > goto exit; > > mapped = cros_ec_map_error(...); > if (mapped) { > ... > goto exit; > } > > if (ret == 0) { > ... > goto exit; > }