linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 2/5] crypto: sunxi-ss: fix min3() call to match types
       [not found] <1450787267-26836-1-git-send-email-andre.przywara@arm.com>
@ 2015-12-22 12:27 ` Andre Przywara
       [not found]   ` <1450787267-26836-3-git-send-email-andre.przywara-5wv7dgnIgG8@public.gmane.org>
  2016-01-04 14:20   ` Uwe Kleine-König
  2015-12-22 12:27 ` [RFC PATCH 3/5] crypto: sunxi-ss: fix dev_dbg() output type Andre Przywara
  1 sibling, 2 replies; 8+ messages in thread
From: Andre Przywara @ 2015-12-22 12:27 UTC (permalink / raw)
  To: Maxime Ripard, Chen-Yu Tsai, arnd
  Cc: marc.zyngier, catalin.marinas, will.deacon, linux-sunxi,
	linux-arm-kernel, linux-kernel, Corentin Labbe, Herbert Xu,
	David S. Miller, linux-crypto

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 <andre.przywara@arm.com>
---
 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;
-- 
2.5.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RFC PATCH 3/5] crypto: sunxi-ss: fix dev_dbg() output type
       [not found] <1450787267-26836-1-git-send-email-andre.przywara@arm.com>
  2015-12-22 12:27 ` [RFC PATCH 2/5] crypto: sunxi-ss: fix min3() call to match types Andre Przywara
@ 2015-12-22 12:27 ` Andre Przywara
       [not found]   ` <1450787267-26836-4-git-send-email-andre.przywara-5wv7dgnIgG8@public.gmane.org>
  2015-12-27 22:05   ` Maxime Ripard
  1 sibling, 2 replies; 8+ messages in thread
From: Andre Przywara @ 2015-12-22 12:27 UTC (permalink / raw)
  To: Maxime Ripard, Chen-Yu Tsai, arnd
  Cc: marc.zyngier, catalin.marinas, will.deacon, linux-sunxi,
	linux-arm-kernel, linux-kernel, Corentin Labbe, Herbert Xu,
	David S. Miller, linux-crypto

The length parameter in this dev_dbg() call is actually a size_t,
so use the proper type to avoid warnings when compiling for 64-bit
architectures.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 drivers/crypto/sunxi-ss/sun4i-ss-cipher.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
index b3bc7bd..af2690c 100644
--- a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
@@ -251,7 +251,7 @@ static int sun4i_ss_cipher_poll(struct ablkcipher_request *areq)
 		spaces = readl(ss->base + SS_FCSR);
 		rx_cnt = SS_RXFIFO_SPACES(spaces);
 		tx_cnt = SS_TXFIFO_SPACES(spaces);
-		dev_dbg(ss->dev, "%x %u/%u %u/%u cnt=%u %u/%u %u/%u cnt=%u %u %u\n",
+		dev_dbg(ss->dev, "%x %u/%zu %u/%u cnt=%u %u/%zu %u/%u cnt=%u %u %u\n",
 			mode,
 			oi, mi.length, ileft, areq->nbytes, rx_cnt,
 			oo, mo.length, oleft, areq->nbytes, tx_cnt,
-- 
2.5.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 2/5] crypto: sunxi-ss: fix min3() call to match types
       [not found]   ` <1450787267-26836-3-git-send-email-andre.przywara-5wv7dgnIgG8@public.gmane.org>
@ 2015-12-22 22:06     ` Arnd Bergmann
       [not found]       ` <201512222306.58681.arnd-r2nGTMty4D4@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Arnd Bergmann @ 2015-12-22 22:06 UTC (permalink / raw)
  To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: Andre Przywara, Maxime Ripard, Chen-Yu Tsai, Herbert Xu,
	marc.zyngier-5wv7dgnIgG8, catalin.marinas-5wv7dgnIgG8,
	will.deacon-5wv7dgnIgG8, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Corentin Labbe,
	linux-crypto-u79uwXL29TY76Z2rM5mHXA, David S. Miller

On Tuesday 22 December 2015, Andre Przywara wrote:
> 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 <andre.przywara-5wv7dgnIgG8@public.gmane.org>

Looks correct, but a bit ugly. Could we avoid the casts by using
temporary variables to keep the size_t based data?

	Arnd

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 3/5] crypto: sunxi-ss: fix dev_dbg() output type
       [not found]   ` <1450787267-26836-4-git-send-email-andre.przywara-5wv7dgnIgG8@public.gmane.org>
@ 2015-12-22 22:07     ` Arnd Bergmann
  2015-12-24 12:56     ` Corentin LABBE
  1 sibling, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2015-12-22 22:07 UTC (permalink / raw)
  To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: Andre Przywara, Maxime Ripard, Chen-Yu Tsai, Herbert Xu,
	marc.zyngier-5wv7dgnIgG8, catalin.marinas-5wv7dgnIgG8,
	will.deacon-5wv7dgnIgG8, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Corentin Labbe,
	linux-crypto-u79uwXL29TY76Z2rM5mHXA, David S. Miller

On Tuesday 22 December 2015, Andre Przywara wrote:
> The length parameter in this dev_dbg() call is actually a size_t,
> so use the proper type to avoid warnings when compiling for 64-bit
> architectures.
> 
> Signed-off-by: Andre Przywara <andre.przywara-5wv7dgnIgG8@public.gmane.org>

Acked-by: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 2/5] crypto: sunxi-ss: fix min3() call to match types
       [not found]       ` <201512222306.58681.arnd-r2nGTMty4D4@public.gmane.org>
@ 2015-12-23  0:07         ` André Przywara
  0 siblings, 0 replies; 8+ messages in thread
From: André Przywara @ 2015-12-23  0:07 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: Maxime Ripard, Chen-Yu Tsai, Herbert Xu, marc.zyngier-5wv7dgnIgG8,
	catalin.marinas-5wv7dgnIgG8, will.deacon-5wv7dgnIgG8,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Corentin Labbe,
	linux-crypto-u79uwXL29TY76Z2rM5mHXA, David S. Miller

Hi Arnd,
On 12/22/15 22:06, Arnd Bergmann wrote:
> On Tuesday 22 December 2015, Andre Przywara wrote:
>> 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 <andre.przywara-5wv7dgnIgG8@public.gmane.org>
> 
> Looks correct, but a bit ugly. Could we avoid the casts by using
> temporary variables to keep the size_t based data?

I guess this gets even uglier, but I found a better solution by
promoting the other involved variables to size_t in this function. This
works nicely for most of the cases, I just need two size_t casts now.
Will send an updated version soon.

Cheers,
Andre.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 3/5] crypto: sunxi-ss: fix dev_dbg() output type
       [not found]   ` <1450787267-26836-4-git-send-email-andre.przywara-5wv7dgnIgG8@public.gmane.org>
  2015-12-22 22:07     ` Arnd Bergmann
@ 2015-12-24 12:56     ` Corentin LABBE
  1 sibling, 0 replies; 8+ messages in thread
From: Corentin LABBE @ 2015-12-24 12:56 UTC (permalink / raw)
  To: Andre Przywara, Maxime Ripard, Chen-Yu Tsai, arnd-r2nGTMty4D4
  Cc: marc.zyngier-5wv7dgnIgG8, catalin.marinas-5wv7dgnIgG8,
	will.deacon-5wv7dgnIgG8, linux-sunxi-/JYPxA39Uh5TLH3MbocFFw,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Herbert Xu, David S. Miller,
	linux-crypto-u79uwXL29TY76Z2rM5mHXA

Le 22/12/2015 13:27, Andre Przywara a écrit :
> The length parameter in this dev_dbg() call is actually a size_t,
> so use the proper type to avoid warnings when compiling for 64-bit
> architectures.
> 
> Signed-off-by: Andre Przywara <andre.przywara-5wv7dgnIgG8@public.gmane.org>
> ---
>  drivers/crypto/sunxi-ss/sun4i-ss-cipher.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
> index b3bc7bd..af2690c 100644
> --- a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
> +++ b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
> @@ -251,7 +251,7 @@ static int sun4i_ss_cipher_poll(struct ablkcipher_request *areq)
>  		spaces = readl(ss->base + SS_FCSR);
>  		rx_cnt = SS_RXFIFO_SPACES(spaces);
>  		tx_cnt = SS_TXFIFO_SPACES(spaces);
> -		dev_dbg(ss->dev, "%x %u/%u %u/%u cnt=%u %u/%u %u/%u cnt=%u %u %u\n",
> +		dev_dbg(ss->dev, "%x %u/%zu %u/%u cnt=%u %u/%zu %u/%u cnt=%u %u %u\n",
>  			mode,
>  			oi, mi.length, ileft, areq->nbytes, rx_cnt,
>  			oo, mo.length, oleft, areq->nbytes, tx_cnt,
> 

Acked-by: LABBE Corentin <clabbe.montjoie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

-- 
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 3/5] crypto: sunxi-ss: fix dev_dbg() output type
  2015-12-22 12:27 ` [RFC PATCH 3/5] crypto: sunxi-ss: fix dev_dbg() output type Andre Przywara
       [not found]   ` <1450787267-26836-4-git-send-email-andre.przywara-5wv7dgnIgG8@public.gmane.org>
@ 2015-12-27 22:05   ` Maxime Ripard
  1 sibling, 0 replies; 8+ messages in thread
From: Maxime Ripard @ 2015-12-27 22:05 UTC (permalink / raw)
  To: Andre Przywara
  Cc: Chen-Yu Tsai, arnd, marc.zyngier, catalin.marinas, will.deacon,
	linux-sunxi, linux-arm-kernel, linux-kernel, Corentin Labbe,
	Herbert Xu, David S. Miller, linux-crypto

[-- Attachment #1: Type: text/plain, Size: 478 bytes --]

On Tue, Dec 22, 2015 at 12:27:45PM +0000, Andre Przywara wrote:
> The length parameter in this dev_dbg() call is actually a size_t,
> so use the proper type to avoid warnings when compiling for 64-bit
> architectures.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>

Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Thanks!
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 2/5] crypto: sunxi-ss: fix min3() call to match types
  2015-12-22 12:27 ` [RFC PATCH 2/5] crypto: sunxi-ss: fix min3() call to match types Andre Przywara
       [not found]   ` <1450787267-26836-3-git-send-email-andre.przywara-5wv7dgnIgG8@public.gmane.org>
@ 2016-01-04 14:20   ` Uwe Kleine-König
  1 sibling, 0 replies; 8+ messages in thread
From: Uwe Kleine-König @ 2016-01-04 14:20 UTC (permalink / raw)
  To: Andre Przywara
  Cc: Maxime Ripard, Chen-Yu Tsai, arnd, Herbert Xu, marc.zyngier,
	catalin.marinas, will.deacon, linux-kernel, linux-sunxi,
	Corentin Labbe, linux-crypto, David S. Miller, linux-arm-kernel

On Tue, Dec 22, 2015 at 12:27:44PM +0000, Andre Przywara wrote:
> 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 <andre.przywara@arm.com>
> ---
>  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);

For this case the min function has a min_t variant to specify the
argument. What about introducing min3_t?

BTW, I don't understand why min3(x, y, z) isn't just defined as

	#define min3(x, y, z) min(min(x, y), z)

but instead as:

	#define min3(x, y, z) min((typeof(x))min(x, y), z)

. I thought min(x, y) has the same type as x anyhow?

Best regards
Uwe


-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-01-04 14:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1450787267-26836-1-git-send-email-andre.przywara@arm.com>
2015-12-22 12:27 ` [RFC PATCH 2/5] crypto: sunxi-ss: fix min3() call to match types Andre Przywara
     [not found]   ` <1450787267-26836-3-git-send-email-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2015-12-22 22:06     ` Arnd Bergmann
     [not found]       ` <201512222306.58681.arnd-r2nGTMty4D4@public.gmane.org>
2015-12-23  0:07         ` André Przywara
2016-01-04 14:20   ` Uwe Kleine-König
2015-12-22 12:27 ` [RFC PATCH 3/5] crypto: sunxi-ss: fix dev_dbg() output type Andre Przywara
     [not found]   ` <1450787267-26836-4-git-send-email-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2015-12-22 22:07     ` Arnd Bergmann
2015-12-24 12:56     ` Corentin LABBE
2015-12-27 22:05   ` Maxime Ripard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).