Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp7008261ybn; Mon, 30 Sep 2019 07:18:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNN/46+oqFl3QM3h7q8eIhuaNwlKvRskhRO0cHbwjwWeidC1V4dECfKkqlG7YeUcpEEY7Z X-Received: by 2002:a05:6402:1202:: with SMTP id c2mr19296075edw.190.1569853095680; Mon, 30 Sep 2019 07:18:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569853095; cv=none; d=google.com; s=arc-20160816; b=v05jAn1xhA+pQEeRSQltrJQ/zvEzOcibZchwSV7VBVB6XR0IJMRQTF9fKZ9azfbl6H G5bk9ykGZXlpSQn3dF/VsukpDKOKksBG0A9dLfFsFuZijXhko8KgNHRLVsSsdHGshri8 Cn5g0NyH9EZ/cP/JKcOpVWQxp45tinTiGTdRCrNz1wCfT3QR1REvZj02FTJyre32u28P 1e149+BuXkNpKBZA8AnaM6WVbivWXc/oZpj7SjyASxpzTIibiEcsvsucJ+VJQ4uqLsEH ZXWCbGKHbXSYKEqkYJoJUXWAo1asdvIlUeoGpQIp+lrs80eFQR01Q5NmaJhqpeXhQYp9 6LQw== 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:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=EkcPDYWVIyVW/5XqI9/HzZw8dAI5XUzCczXG556Ykw8=; b=FwSmHS+mGtEZ0i/9jcYW59q9LkY9r6okNIAX6PlkoJ8NQrgY1Yd3QYUFFwsAURTN7t mea+xjXOHjBhlZ31zOFzLshcOCybV6YrxooPucAF4O7zSIvzHnTrPt5Mo7zqyKy1zE04 UlhmUigG2K/BrD1ezS3b0UuHLAdQ4vrpFFFQROVOGZR85+dEujJxpF6mjVPZeEYC4KE/ d4Vowl4x5tnyKeD5yKlXmFmr1QkugH4VgrTeTbD2JhHv5WAzx04KeezVBtax1G9PJSp/ PARFrOoW841V1zjvvI0DmCLL64pZIwkNx3jC6Xwvwka5r8Vmq2/ugVunLlG07RIgQROa pHWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4si6807494eji.316.2019.09.30.07.17.43; Mon, 30 Sep 2019 07:18:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731561AbfI3ORX (ORCPT + 99 others); Mon, 30 Sep 2019 10:17:23 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57312 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731547AbfI3ORX (ORCPT ); Mon, 30 Sep 2019 10:17:23 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id A81C2B0F50BE9C3454C1; Mon, 30 Sep 2019 22:17:18 +0800 (CST) Received: from localhost (10.202.226.61) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.439.0; Mon, 30 Sep 2019 22:17:11 +0800 Date: Mon, 30 Sep 2019 15:17:02 +0100 From: Jonathan Cameron To: Tian Tao CC: , , , , Subject: Re: [PATCH] crypto: fix comparison of unsigned expression warnings Message-ID: <20190930151702.0000131f@huawei.com> In-Reply-To: <1569833361-47224-1-git-send-email-tiantao6@huawei.com> References: <1569833361-47224-1-git-send-email-tiantao6@huawei.com> Organization: Huawei X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.61] X-CFilter-Loop: Reflected Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Mon, 30 Sep 2019 16:49:21 +0800 Tian Tao wrote: > This patch fixes the following warnings: > drivers/crypto/ccree/cc_aead.c:630:5-12: WARNING: Unsigned expression > compared with zero: seq_len > 0 > > Signed-off-by: Tian Tao Apologies, I should have looked into this in more depth when you asked me about it earlier rather than assuming it was 'obviously' the right fix. It's more complex than I expected given the warning, which I note is > 0 so it's not always true. I'm curious, which compiler generates that warning? So there are two ways seq_len can be set to non 0, hmac_setkey which returns a signed int, but one that is reality is >= 0. The other is xcbc_setkey which returns an unsigned int. So I would suggest that in addition to what you have here, a change to the return type of hmac_setkey in order to make it clear that never returns a negative anyway. Can also use if (seq_len) rather than if (seq_len > 0) Thanks, Jonathan > --- > drivers/crypto/ccree/cc_aead.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/crypto/ccree/cc_aead.c b/drivers/crypto/ccree/cc_aead.c > index d3e8faa..b19291d 100644 > --- a/drivers/crypto/ccree/cc_aead.c > +++ b/drivers/crypto/ccree/cc_aead.c > @@ -546,7 +546,7 @@ static int cc_aead_setkey(struct crypto_aead *tfm, const u8 *key, > struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm); > struct cc_crypto_req cc_req = {}; > struct cc_hw_desc desc[MAX_AEAD_SETKEY_SEQ]; > - unsigned int seq_len = 0; > + int seq_len = 0; > struct device *dev = drvdata_to_dev(ctx->drvdata); > const u8 *enckey, *authkey; > int rc;