Skip to content

Commit 2cca486

Browse files
William Zhangbroonie
authored andcommitted
spi: bcm63xx-hsspi: bcmbca-hsspi: fix _be16 type usage
sparse tool report warnings: drivers/spi/spi-bcm63xx-hsspi.c:197:31: sparse: sparse: cast from restricted __be16. The controller requires big endian 16 bit data. Define an intermediate u16 value and use __be16 piointer dereferncing for the data to avoid directly casting to u16 and sparse warning. Fixes: 85a84a6 ("spi: bcm63xx-hsspi: Endianness fix for ARM based SoC") Reported-by: kernel test robot <[email protected]> Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Signed-off-by: William Zhang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 8032359 commit 2cca486

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

drivers/spi/spi-bcm63xx-hsspi.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ static int bcm63xx_hsspi_do_prepend_txrx(struct spi_device *spi,
350350
{
351351
struct bcm63xx_hsspi *bs = spi_master_get_devdata(spi->master);
352352
unsigned int chip_select = spi->chip_select;
353-
u16 opcode = 0;
353+
u16 opcode = 0, val;
354354
const u8 *tx = t->tx_buf;
355355
u8 *rx = t->rx_buf;
356356
u32 reg = 0;
@@ -401,7 +401,8 @@ static int bcm63xx_hsspi_do_prepend_txrx(struct spi_device *spi,
401401
memcpy_toio(bs->fifo + HSSPI_OPCODE_LEN + bs->prepend_cnt, tx,
402402
t->len);
403403

404-
__raw_writew((u16)cpu_to_be16(opcode | t->len), bs->fifo);
404+
*(__be16 *)(&val) = cpu_to_be16(opcode | t->len);
405+
__raw_writew(val, bs->fifo);
405406
/* enable interrupt */
406407
if (bs->wait_mode == HSSPI_WAIT_MODE_INTR)
407408
__raw_writel(HSSPI_PINGx_CMD_DONE(0), bs->regs + HSSPI_INT_MASK_REG);
@@ -468,7 +469,7 @@ static int bcm63xx_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t)
468469
{
469470
struct bcm63xx_hsspi *bs = spi_master_get_devdata(spi->master);
470471
unsigned int chip_select = spi->chip_select;
471-
u16 opcode = 0;
472+
u16 opcode = 0, val;
472473
int pending = t->len;
473474
int step_size = HSSPI_BUFFER_LEN;
474475
const u8 *tx = t->tx_buf;
@@ -511,7 +512,8 @@ static int bcm63xx_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t)
511512
tx += curr_step;
512513
}
513514

514-
__raw_writew((u16)cpu_to_be16(opcode | curr_step), bs->fifo);
515+
*(__be16 *)(&val) = cpu_to_be16(opcode | curr_step);
516+
__raw_writew(val, bs->fifo);
515517

516518
/* enable interrupt */
517519
if (bs->wait_mode == HSSPI_WAIT_MODE_INTR)

drivers/spi/spi-bcmbca-hsspi.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static int bcmbca_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t,
252252
{
253253
struct bcmbca_hsspi *bs = spi_master_get_devdata(spi->master);
254254
unsigned int chip_select = spi->chip_select;
255-
u16 opcode = 0;
255+
u16 opcode = 0, val;
256256
int pending = t->len;
257257
int step_size = HSSPI_BUFFER_LEN;
258258
const u8 *tx = t->tx_buf;
@@ -292,7 +292,9 @@ static int bcmbca_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t,
292292
memcpy_toio(bs->fifo + HSSPI_OPCODE_LEN, tx, curr_step);
293293
tx += curr_step;
294294
}
295-
__raw_writew((u16)cpu_to_be16(opcode | curr_step), bs->fifo);
295+
296+
*(__be16 *)(&val) = cpu_to_be16(opcode | curr_step);
297+
__raw_writew(val, bs->fifo);
296298

297299
/* enable interrupt */
298300
if (bs->wait_mode == HSSPI_WAIT_MODE_INTR)

0 commit comments

Comments
 (0)