Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2230525imu; Sun, 18 Nov 2018 19:08:24 -0800 (PST) X-Google-Smtp-Source: AJdET5fUwdlar1l70rhxieia0cTEdj3kRyOZPdFbOiy8I/ED2/SSEBz7VDekJ/T2dGsTxw6qK69a X-Received: by 2002:a63:1f4e:: with SMTP id q14mr17886337pgm.88.1542596904454; Sun, 18 Nov 2018 19:08:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542596904; cv=none; d=google.com; s=arc-20160816; b=o8HFqxS3+uGDz+6+ZA7K5uZX8wPi2jPYN4/GgwVSmXhDH68tL9JMMGCIG/Aa0rITe2 +7CRfjflsBPGv0mjI/NTkNQHRFrgf2HIduh6vWD+pZU+ZR0rp3zCO6y+SbLDSCurlkZM UP93LwYFuj73qLYPQz+X95fTmC2TwSEl8hqJOiEM9NQEvaff4So7sxOvXNo70Hnz/BNO KQR2bQFVtc89/ukR1efOU3JlmLJBHqmzmYVn96nXHAD0Oxzld78rSKMpm0t8yXUKgAsT c6G3US205bCZe7LrXtwQLVwhS/wHy6fFQSEpWUGyiOnlDLin/KO7M/nDLH4AYDQmerho Sv8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject; bh=WluGKcKAg+/q9+zkonysnzLqhxWCSf7ANgt9F2bTP0I=; b=R9rwlZh7VI+9KKfTBy3U9OpyZFTz+YENGlI0k9CSKQs6KWT20g0jXOOFuIKYOamdOW qSER37p5N4RyrUrGRGId7txWt5M2Nb/KgpTUnJlNwGPdlK1IlgwGpRNEmoCht0JYS+ah kLcgwJil+MWFMlBb6ptHbU0Ul9TOVkSdsdjS+q7YQhkbqlEy9NG5OQnQ+cn2OApS/Siz osMlRD+b/HjRDmzSlL58HW0RZ22Gfhmc387a2LRAkGWMQH5KrLD9r7nNuLbr7MbF784y yGoyUC+3AQIt50ch8P3zY1mT9qbZo3NbPmW62+fC2wXOqGspHF468OEasTBuWL3WPGNn 5eTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y17si10370407pgh.353.2018.11.18.19.08.09; Sun, 18 Nov 2018 19:08:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728287AbeKSN1d (ORCPT + 99 others); Mon, 19 Nov 2018 08:27:33 -0500 Received: from mga17.intel.com ([192.55.52.151]:14766 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726975AbeKSN1d (ORCPT ); Mon, 19 Nov 2018 08:27:33 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Nov 2018 19:05:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,250,1539673200"; d="scan'208";a="101332823" Received: from ltchung-mobl1.amr.corp.intel.com (HELO tstruk-mobl1.jf.intel.com) ([10.254.4.5]) by orsmga003.jf.intel.com with ESMTP; 18 Nov 2018 19:05:21 -0800 Subject: Re: [PATCH v4 2/2] tpm: add support for partial reads To: Jarkko Sakkinen Cc: jgg@ziepe.ca, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org References: <154239067364.2880.13752725056462237016.stgit@tstruk-mobl1.jf.intel.com> <154239071144.2924.17574189056250189697.stgit@tstruk-mobl1.jf.intel.com> <20181118074832.GG5897@linux.intel.com> From: Tadeusz Struk Openpgp: preference=signencrypt Autocrypt: addr=tadeusz.struk@intel.com; prefer-encrypt=mutual; keydata= xsDiBEiLICMRBADteQacQxypsuFvAw6IwYzbD8pgQi+kLYBcqfGgVAUN/cO+sLl6u1lVdaDB fhAArdbV9lpoqcWnmhQFTb4A+W569EpydBr6nuatWkEB+fmmx8YoUtuZfXt7v+1l1rc09kaW LY+TkwQkvFCeuvdasgmBLnmRWymEGWi1E12hUgTw/wCgtK24geC7XkiuANMv0gpr+raOgQMD /2yJZ0SeXQApWyTRaeIYN8GgYHZTWuBp/ofN+viEkhrDxahcaGPP5B/Nv6VS1+M0e5m8OzHj qPUbgfyOeJcslC5aoZdqqqzVWVLaA/+Jy+O+6T3k3R/IryVVATldBlwnGFDhET0mKQsd15zt cIdQBBbfSFR5VlugZuWV5q442IpPA/4g7nen9FFPxh45Te8D54hAsOCywjm6xUE0UJGYHeJ/ MXCPtuXfVCbYcOxZVH7kUS2Vtk5d3bF40IE2WnVq1ZScNANF4ZjikxYhYGfNWX3HXak1gSoj UrY87rMSjPIAry4L0BoIx2qgL/k4iV/3QcXL4t5wosU0iw++suf1zGGcKM0gVGFkZXVzeiBT dHJ1ayA8dHN0cnVrQGdtYWlsLmNvbT7CYwQTEQIAIwIbAwYLCQgHAwIEFQIIAwQWAgMBAh4B AheABQJQTjJTAhkBAAoJEDFswfskq9xyqvcAoI2nsaUCX8ZGbu+Jhq+++qlBFJ2rAJ983RoO R2ofHhn3g3Qi4K34tw0l087BTQRauzUlARAAqkWRL/InEPnoGMg/gw/CRaDBaIBgMsvIcghI 7xevIzpleXt6jKHghSBooH+zaT7qi4u2gkgPn4odsER3Rm94XgrZJgoqls6EpKMWpJNGP4HT eYgykhfsZOLX8ijUbjTM/Sm/dZVo6aYoBL2+ciJwyl+Zt3Mp6un3/GWu6cA9005V50pRqO7j PTlVCHi2bedcEEf5DDsYJv/3Oz8/4LpSf6BL6BltjeZVa2y03dTMmD031JTH+OuyJm1yh72Z HWxhlYNXOv6uFJJVr+paQjrAsBVIYKhK24bD+uGJxLm8AN9i7/Si+2YeSsXvKUhk9mIoFBnU VFo63cziRTcpRu/kXgDAbujwN88qytEcvhEZHS6B9vdws+lhTpolEjkLCkz0Y59z4Fs9srKy QkRN+wtdiLgrwyDW3ryAKxcDmOumGWebDxpaOI/pBhrlS93HmDlvj7JmgTUU4a/NhwI3dXh5 pn8FZzZyVXe3Kc3bu5T3UAC7uztinsAvCJQS6jGZWrXmXkqYkaLXQOw61eInWjr01zE/zDbE mdJPM0+va/gtZx9TtGxr4PpjbqswqCiubLDZXZHh5uqArPv/i+E8aXIsNSTN6Rrqs1j9YgDN ALksibv6+tXH3sOlCUgjuZgJH3+s/mnaAtiV2rZ/WlH15d6nd0uiDSZrKhlR+g4NHMh1ztEA EQEAAcJPBBgRAgAPBQJauzUlAhsMBQkJZgGAAAoJEDFswfskq9xyfv8AoI8aPrJCoM0h5WOP kKxMmPEPHzUNAJ9jBBYXhX1CWg+IhI7i/fLlI0vwCA== Message-ID: <90072f09-6388-b1f7-387b-42f056f8893d@intel.com> Date: Sun, 18 Nov 2018 19:05:19 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <20181118074832.GG5897@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/17/18 11:48 PM, Jarkko Sakkinen wrote: >> + if (priv->transmit_result || priv->partial_data) { >> + if (*off == 0) >> + priv->partial_data = priv->transmit_result; >> + >> + ret_size = min_t(ssize_t, size, priv->partial_data); >> + if (ret_size <= 0) { > When ret_size < 0? Shouldn't this be just "if (!ret_size)"? What we want to check here is if ret_size is positive, which is a valid value, or if it is negative or zero, which is an invalid value, so in this case (!ret_size) will not work. > >> /* Holds the resul of the last successful call to tpm_transmit() */ >> size_t transmit_result; >> + /* Holds the count how much of the response is still unread */ >> + size_t partial_data; > I'm otherwise happy how this look like but why call it partial_data. > You cannot really tell from the name anything about its contents as > data is very abstract term. so I will rename these two to response_length and response_length_rem, how does this sound? > BTW, why you need the new variable anyway and not just decrease the > variable where the length is original stored? We need to have two variables, otherwise how do we tell if some part of response was consumed to allow sending a new command? The transmit_result is used for that. If it is zero then one can transmit a new command even if the whole response is not consumed. The new variable tracks how much of the response is still to be read. Thanks, -- Tadeusz