From patchwork Tue Dec 22 12:27:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 7904421 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D2CE09F1AF for ; Tue, 22 Dec 2015 12:30:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DD69F20462 for ; Tue, 22 Dec 2015 12:30:43 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E468020392 for ; Tue, 22 Dec 2015 12:30:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aBM4I-0006Be-89; Tue, 22 Dec 2015 12:29:30 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aBM3L-0005Nl-95 for linux-arm-kernel@lists.infradead.org; Tue, 22 Dec 2015 12:28:33 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B38F4E5; Tue, 22 Dec 2015 04:27:47 -0800 (PST) Received: from e104803-lin.lan (unknown [10.1.203.153]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F34FC3F308; Tue, 22 Dec 2015 04:28:11 -0800 (PST) From: Andre Przywara To: Maxime Ripard , Chen-Yu Tsai , arnd@arndb.de Subject: [RFC PATCH 2/5] crypto: sunxi-ss: fix min3() call to match types Date: Tue, 22 Dec 2015 12:27:44 +0000 Message-Id: <1450787267-26836-3-git-send-email-andre.przywara@arm.com> X-Mailer: git-send-email 2.5.1 In-Reply-To: <1450787267-26836-1-git-send-email-andre.przywara@arm.com> References: <1450787267-26836-1-git-send-email-andre.przywara@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151222_042831_582111_E9650C1D X-CRM114-Status: GOOD ( 11.93 ) X-Spam-Score: -6.9 (------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Herbert Xu , marc.zyngier@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe , linux-crypto@vger.kernel.org, "David S. Miller" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The min3() macro expects all arguments to be of the same type (or size at least). While two arguments are ints or u32s, one is size_t, which does not match on 64-bit architectures. Cast the size_t to u32 to make min3() happy. In this context here the length should never exceed 32 bits anyway. Signed-off-by: Andre Przywara --- drivers/crypto/sunxi-ss/sun4i-ss-cipher.c | 12 ++++++------ drivers/crypto/sunxi-ss/sun4i-ss-hash.c | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c index a19ee12..b3bc7bd 100644 --- a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c @@ -79,7 +79,7 @@ static int sun4i_ss_opti_poll(struct ablkcipher_request *areq) oi = 0; oo = 0; do { - todo = min3(rx_cnt, ileft, (mi.length - oi) / 4); + todo = min3(rx_cnt, ileft, (u32)(mi.length - oi) / 4); if (todo > 0) { ileft -= todo; writesl(ss->base + SS_RXFIFO, mi.addr + oi, todo); @@ -94,7 +94,7 @@ static int sun4i_ss_opti_poll(struct ablkcipher_request *areq) rx_cnt = SS_RXFIFO_SPACES(spaces); tx_cnt = SS_TXFIFO_SPACES(spaces); - todo = min3(tx_cnt, oleft, (mo.length - oo) / 4); + todo = min3(tx_cnt, oleft, (u32)(mo.length - oo) / 4); if (todo > 0) { oleft -= todo; readsl(ss->base + SS_TXFIFO, mo.addr + oo, todo); @@ -216,7 +216,7 @@ static int sun4i_ss_cipher_poll(struct ablkcipher_request *areq) * todo is the number of consecutive 4byte word that we * can read from current SG */ - todo = min3(rx_cnt, ileft / 4, (mi.length - oi) / 4); + todo = min3(rx_cnt, ileft / 4, (u32)(mi.length - oi) / 4); if (todo > 0 && ob == 0) { writesl(ss->base + SS_RXFIFO, mi.addr + oi, todo); @@ -231,7 +231,7 @@ static int sun4i_ss_cipher_poll(struct ablkcipher_request *areq) * pass, so it is why we min() with rx_cnt */ todo = min3(rx_cnt * 4 - ob, ileft, - mi.length - oi); + (u32)mi.length - oi); memcpy(buf + ob, mi.addr + oi, todo); ileft -= todo; oi += todo; @@ -260,7 +260,7 @@ static int sun4i_ss_cipher_poll(struct ablkcipher_request *areq) if (tx_cnt == 0) continue; /* todo in 4bytes word */ - todo = min3(tx_cnt, oleft / 4, (mo.length - oo) / 4); + todo = min3(tx_cnt, oleft / 4, (u32)(mo.length - oo) / 4); if (todo > 0) { readsl(ss->base + SS_TXFIFO, mo.addr + oo, todo); oleft -= todo * 4; @@ -284,7 +284,7 @@ static int sun4i_ss_cipher_poll(struct ablkcipher_request *areq) * no more than remaining buffer * no need to test against oleft */ - todo = min(mo.length - oo, obl - obo); + todo = min((u32)mo.length - oo, obl - obo); memcpy(mo.addr + oo, bufo + obo, todo); oleft -= todo; obo += todo; diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-hash.c b/drivers/crypto/sunxi-ss/sun4i-ss-hash.c index ff80314..cd29009 100644 --- a/drivers/crypto/sunxi-ss/sun4i-ss-hash.c +++ b/drivers/crypto/sunxi-ss/sun4i-ss-hash.c @@ -245,7 +245,7 @@ int sun4i_hash_update(struct ahash_request *areq) */ while (op->len < 64 && i < end) { /* how many bytes we can read from current SG */ - in_r = min3(mi.length - in_i, end - i, + in_r = min3((u32)mi.length - in_i, end - i, 64 - op->len); memcpy(op->buf + op->len, mi.addr + in_i, in_r); op->len += in_r; @@ -266,8 +266,8 @@ int sun4i_hash_update(struct ahash_request *areq) } if (mi.length - in_i > 3 && i < end) { /* how many bytes we can read from current SG */ - in_r = min3(mi.length - in_i, areq->nbytes - i, - ((mi.length - in_i) / 4) * 4); + in_r = min3((u32)mi.length - in_i, areq->nbytes - i, + ((u32)(mi.length - in_i) / 4) * 4); /* how many bytes we can write in the device*/ todo = min3((u32)(end - i) / 4, rx_cnt, (u32)in_r / 4); writesl(ss->base + SS_RXFIFO, mi.addr + in_i, todo); @@ -289,7 +289,7 @@ int sun4i_hash_update(struct ahash_request *areq) if ((areq->nbytes - i) < 64) { while (i < areq->nbytes && in_i < mi.length && op->len < 64) { /* how many bytes we can read from current SG */ - in_r = min3(mi.length - in_i, areq->nbytes - i, + in_r = min3((u32)mi.length - in_i, areq->nbytes - i, 64 - op->len); memcpy(op->buf + op->len, mi.addr + in_i, in_r); op->len += in_r;