Skip to contentSkip to conversation

spi: Use %u for unsigned int, %zu for size_t

PATCH In review Thierry Reding 2 participants 4 messages Feb 18, 2016 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 spi: Use %u for unsigned int, %zu for size_t

From: Thierry Reding <[email protected]>

When printing unsigned int it is more idiomatic to use %u, for size_t the correct specifier is %zu (see Documentation/printk-formats.txt).

GCC only warns about the latter, but fixing up the former while at it for consistency.

---
 drivers/spi/spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi.c +1 -1
index f6c76be39e96..f123f9f4d779 100644
@@ -2276,7 +2276,7 @@ static int __spi_split_transfer_maxsize(struct spi_master *master,
 
 	/* warn once about this fact that we are splitting a transfer */
 	dev_warn_once(&msg->spi->dev,
-		      "spi_transfer of length %i exceed max length of %i - needed to split transfers\n",
+		      "spi_transfer of length %u exceed max length of %zu - needed to split transfers\n",
 		      xfer->len, maxsize);
 
 	/* calculate how many we have to replace */
Signature · 6 lines
2.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

PATCH 2/2 spi: Prevent a type mismatch warning using min_t()

From: Thierry Reding <[email protected]>

The min_t() variant of the min() macro uses an explicit cast to the type given in the first argument and can be used to avoid a compiler warning if both types differ (f.e. in signedness).

---
 drivers/spi/spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi.c +1 -1
index f123f9f4d779..fe001ec4471e 100644
@@ -2301,7 +2301,7 @@ static int __spi_split_transfer_maxsize(struct spi_master *master,
 	/* the first transfer just needs the length modified, so we
 	 * run it outside the loop
 	 */
-	xfers[0].len = min(maxsize, xfer[0].len);
+	xfers[0].len = min_t(size_t, maxsize, xfer[0].len);
 
 	/* all the others need rx_buf/tx_buf also set */
 	for (i = 1, offset = maxsize; i < count; offset += maxsize, i++) {
Signature · 1 line
2.7.1
maintainer
#2 lore raw
In reply to Thierry Reding
Quoted 4 lines · Thierry Reding

From: Thierry Reding <[email protected]>

When printing unsigned int it is more idiomatic to use %u, for size_t the correct specifier is %zu (see Documentation/printk-formats.txt).

These don't apply against current code, please check and resend. Fabio sent some similar patches the other day.

#3 lore raw
Quoted 8 lines · Mark Brown
Quoted 4 lines · Thierry Reding

From: Thierry Reding <[email protected]>

When printing unsigned int it is more idiomatic to use %u, for size_t the correct specifier is %zu (see Documentation/printk-formats.txt).

These don't apply against current code, please check and resend. Fabio sent some similar patches the other day.

I started seeing this two days ago and didn't submit because I assumed somebody else already had. When it didn't filter out on top of today's -next I decided to send out.

I do see that Fabio's fixes went into your tree yesterday, possibly not quite in time to make today's -next. Both his patches fix the same warnings that mine did. The only thing missing seems to be the %i -> %u conversion, but I don't think I'll respin just for that.

Thierry