diff options
author | Brian Norris <computersforpeace@gmail.com> | 2014-04-11 15:15:32 -0400 |
---|---|---|
committer | Brian Norris <computersforpeace@gmail.com> | 2014-04-17 00:59:23 -0400 |
commit | 38e2eee9abf202b5edad73eb0288e0a4dfaacfca (patch) | |
tree | 43075d5e52e917725e7646d7177a104b3417af3c | |
parent | a965d04c977096ff91f12f96eb7b35b7b03af48c (diff) |
mtd: st_spi_fsm: correct type issues
Compile-testing for a 64-bit arch uncovers several bad casts:
In file included from include/linux/linkage.h:4:0,
from include/linux/kernel.h:6,
from drivers/mtd/devices/st_spi_fsm.c:15:
drivers/mtd/devices/st_spi_fsm.c: In function ‘stfsm_read_fifo’:
drivers/mtd/devices/st_spi_fsm.c:758:11: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
BUG_ON((((uint32_t)buf) & 0x3) || (size & 0x3));
...
Use uintptr_t instead of uint32_t, since it's guaranteed to be
pointer-sized.
We also see this warning, if size_t is not 32 bits wide:
In file included from drivers/mtd/devices/st_spi_fsm.c:15:0:
drivers/mtd/devices/st_spi_fsm.c: In function ‘stfsm_mtd_write’:
include/linux/kernel.h:712:17: warning: comparison of distinct pointer types lacks a cast [enabled by default]
(void) (&_min1 == &_min2); \
^
drivers/mtd/devices/st_spi_fsm.c:1704:11: note: in expansion of macro ‘min’
bytes = min(FLASH_PAGESIZE - page_offs, len);
^
Just use min_t() to force the type conversion, since we don't really
want to upgrade 'page_offs' and 'bytes' to size_t; they only should be
handling <= 256 byte offsets.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Acked-by: Lee Jones <lee.jones@linaro.org>
-rw-r--r-- | drivers/mtd/devices/st_spi_fsm.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index 7cc49ba78f68..f97fe144077d 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c | |||
@@ -755,7 +755,7 @@ static void stfsm_read_fifo(struct stfsm *fsm, uint32_t *buf, uint32_t size) | |||
755 | 755 | ||
756 | dev_dbg(fsm->dev, "Reading %d bytes from FIFO\n", size); | 756 | dev_dbg(fsm->dev, "Reading %d bytes from FIFO\n", size); |
757 | 757 | ||
758 | BUG_ON((((uint32_t)buf) & 0x3) || (size & 0x3)); | 758 | BUG_ON((((uintptr_t)buf) & 0x3) || (size & 0x3)); |
759 | 759 | ||
760 | while (remaining) { | 760 | while (remaining) { |
761 | for (;;) { | 761 | for (;;) { |
@@ -779,7 +779,7 @@ static int stfsm_write_fifo(struct stfsm *fsm, const uint32_t *buf, | |||
779 | 779 | ||
780 | dev_dbg(fsm->dev, "writing %d bytes to FIFO\n", size); | 780 | dev_dbg(fsm->dev, "writing %d bytes to FIFO\n", size); |
781 | 781 | ||
782 | BUG_ON((((uint32_t)buf) & 0x3) || (size & 0x3)); | 782 | BUG_ON((((uintptr_t)buf) & 0x3) || (size & 0x3)); |
783 | 783 | ||
784 | writesl(fsm->base + SPI_FAST_SEQ_DATA_REG, buf, words); | 784 | writesl(fsm->base + SPI_FAST_SEQ_DATA_REG, buf, words); |
785 | 785 | ||
@@ -1474,7 +1474,7 @@ static int stfsm_read(struct stfsm *fsm, uint8_t *buf, uint32_t size, | |||
1474 | read_mask = (data_pads << 2) - 1; | 1474 | read_mask = (data_pads << 2) - 1; |
1475 | 1475 | ||
1476 | /* Handle non-aligned buf */ | 1476 | /* Handle non-aligned buf */ |
1477 | p = ((uint32_t)buf & 0x3) ? (uint8_t *)page_buf : buf; | 1477 | p = ((uintptr_t)buf & 0x3) ? (uint8_t *)page_buf : buf; |
1478 | 1478 | ||
1479 | /* Handle non-aligned size */ | 1479 | /* Handle non-aligned size */ |
1480 | size_ub = (size + read_mask) & ~read_mask; | 1480 | size_ub = (size + read_mask) & ~read_mask; |
@@ -1496,7 +1496,7 @@ static int stfsm_read(struct stfsm *fsm, uint8_t *buf, uint32_t size, | |||
1496 | } | 1496 | } |
1497 | 1497 | ||
1498 | /* Handle non-aligned buf */ | 1498 | /* Handle non-aligned buf */ |
1499 | if ((uint32_t)buf & 0x3) | 1499 | if ((uintptr_t)buf & 0x3) |
1500 | memcpy(buf, page_buf, size); | 1500 | memcpy(buf, page_buf, size); |
1501 | 1501 | ||
1502 | /* Wait for sequence to finish */ | 1502 | /* Wait for sequence to finish */ |
@@ -1538,7 +1538,7 @@ static int stfsm_write(struct stfsm *fsm, const uint8_t *buf, | |||
1538 | write_mask = (data_pads << 2) - 1; | 1538 | write_mask = (data_pads << 2) - 1; |
1539 | 1539 | ||
1540 | /* Handle non-aligned buf */ | 1540 | /* Handle non-aligned buf */ |
1541 | if ((uint32_t)buf & 0x3) { | 1541 | if ((uintptr_t)buf & 0x3) { |
1542 | memcpy(page_buf, buf, size); | 1542 | memcpy(page_buf, buf, size); |
1543 | p = (uint8_t *)page_buf; | 1543 | p = (uint8_t *)page_buf; |
1544 | } else { | 1544 | } else { |
@@ -1701,7 +1701,7 @@ static int stfsm_mtd_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
1701 | 1701 | ||
1702 | while (len) { | 1702 | while (len) { |
1703 | /* Write up to page boundary */ | 1703 | /* Write up to page boundary */ |
1704 | bytes = min(FLASH_PAGESIZE - page_offs, len); | 1704 | bytes = min_t(size_t, FLASH_PAGESIZE - page_offs, len); |
1705 | 1705 | ||
1706 | ret = stfsm_write(fsm, b, bytes, to); | 1706 | ret = stfsm_write(fsm, b, bytes, to); |
1707 | if (ret) | 1707 | if (ret) |