Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: goldfish: Fix pointer cast for 32 bits

As the first argument of gf_write64() was of type unsigned long, and as
some calls to gf_write64() were casting the first argument from void *
to u64 the compiler and/or sparse were printing warnings for casts of
wrong sizes when compiling for i386.

This patch changes the type of the first argument of gf_write64() to
const void *, and update calls to the function. This change fixed the
warnings and allowed to remove casts from 3 calls to gf_write64().

In addition gf_write64() was renamed to gf_write_ptr() as the name was
misleading because it only writes 32 bits on 32 bit systems.

gf_write_dma_addr() was added to handle dma_addr_t values which is
used at drivers/staging/goldfish/goldfish_audio.c.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Peter Senna Tschudin and committed by
Greg Kroah-Hartman
07d783fd e97bc8b2

+28 -17
+9 -9
drivers/platform/goldfish/goldfish_pipe.c
··· 158 158 struct goldfish_pipe_dev *dev = pipe->dev; 159 159 160 160 spin_lock_irqsave(&dev->lock, flags); 161 - gf_write64((u64)(unsigned long)pipe, dev->base + PIPE_REG_CHANNEL, 162 - dev->base + PIPE_REG_CHANNEL_HIGH); 161 + gf_write_ptr(pipe, dev->base + PIPE_REG_CHANNEL, 162 + dev->base + PIPE_REG_CHANNEL_HIGH); 163 163 writel(cmd, dev->base + PIPE_REG_COMMAND); 164 164 status = readl(dev->base + PIPE_REG_STATUS); 165 165 spin_unlock_irqrestore(&dev->lock, flags); ··· 172 172 struct goldfish_pipe_dev *dev = pipe->dev; 173 173 174 174 spin_lock_irqsave(&dev->lock, flags); 175 - gf_write64((u64)(unsigned long)pipe, dev->base + PIPE_REG_CHANNEL, 176 - dev->base + PIPE_REG_CHANNEL_HIGH); 175 + gf_write_ptr(pipe, dev->base + PIPE_REG_CHANNEL, 176 + dev->base + PIPE_REG_CHANNEL_HIGH); 177 177 writel(cmd, dev->base + PIPE_REG_COMMAND); 178 178 spin_unlock_irqrestore(&dev->lock, flags); 179 179 } ··· 327 327 spin_lock_irqsave(&dev->lock, irq_flags); 328 328 if (access_with_param(dev, CMD_WRITE_BUFFER + cmd_offset, 329 329 address, avail, pipe, &status)) { 330 - gf_write64((u64)(unsigned long)pipe, 331 - dev->base + PIPE_REG_CHANNEL, 332 - dev->base + PIPE_REG_CHANNEL_HIGH); 330 + gf_write_ptr(pipe, dev->base + PIPE_REG_CHANNEL, 331 + dev->base + PIPE_REG_CHANNEL_HIGH); 333 332 writel(avail, dev->base + PIPE_REG_SIZE); 334 - gf_write64(address, dev->base + PIPE_REG_ADDRESS, 335 - dev->base + PIPE_REG_ADDRESS_HIGH); 333 + gf_write_ptr((void *)address, 334 + dev->base + PIPE_REG_ADDRESS, 335 + dev->base + PIPE_REG_ADDRESS_HIGH); 336 336 writel(CMD_WRITE_BUFFER + cmd_offset, 337 337 dev->base + PIPE_REG_COMMAND); 338 338 status = readl(dev->base + PIPE_REG_STATUS);
+1 -1
drivers/staging/goldfish/goldfish_audio.c
··· 63 63 #define AUDIO_READ(data, addr) (readl(data->reg_base + addr)) 64 64 #define AUDIO_WRITE(data, addr, x) (writel(x, data->reg_base + addr)) 65 65 #define AUDIO_WRITE64(data, addr, addr2, x) \ 66 - (gf_write64((u64)(x), data->reg_base + addr, data->reg_base+addr2)) 66 + (gf_write_dma_addr((x), data->reg_base + addr, data->reg_base+addr2)) 67 67 68 68 /* 69 69 * temporary variable used between goldfish_audio_probe() and
+1 -1
drivers/staging/goldfish/goldfish_nand.c
··· 87 87 writel((u32)(addr >> 32), base + NAND_ADDR_HIGH); 88 88 writel((u32)addr, base + NAND_ADDR_LOW); 89 89 writel(len, base + NAND_TRANSFER_SIZE); 90 - gf_write64((u64)ptr, base + NAND_DATA, base + NAND_DATA_HIGH); 90 + gf_write_ptr(ptr, base + NAND_DATA, base + NAND_DATA_HIGH); 91 91 writel(cmd, base + NAND_COMMAND); 92 92 rv = readl(base + NAND_RESULT); 93 93 }
+2 -2
drivers/tty/goldfish.c
··· 59 59 struct goldfish_tty *qtty = &goldfish_ttys[line]; 60 60 void __iomem *base = qtty->base; 61 61 spin_lock_irqsave(&qtty->lock, irq_flags); 62 - gf_write64((u64)buf, base + GOLDFISH_TTY_DATA_PTR, 62 + gf_write_ptr(buf, base + GOLDFISH_TTY_DATA_PTR, 63 63 base + GOLDFISH_TTY_DATA_PTR_HIGH); 64 64 writel(count, base + GOLDFISH_TTY_DATA_LEN); 65 65 writel(GOLDFISH_TTY_CMD_WRITE_BUFFER, base + GOLDFISH_TTY_CMD); ··· 81 81 82 82 count = tty_prepare_flip_string(&qtty->port, &buf, count); 83 83 spin_lock_irqsave(&qtty->lock, irq_flags); 84 - gf_write64((u64)buf, base + GOLDFISH_TTY_DATA_PTR, 84 + gf_write_ptr(buf, base + GOLDFISH_TTY_DATA_PTR, 85 85 base + GOLDFISH_TTY_DATA_PTR_HIGH); 86 86 writel(count, base + GOLDFISH_TTY_DATA_LEN); 87 87 writel(GOLDFISH_TTY_CMD_READ_BUFFER, base + GOLDFISH_TTY_CMD);
+15 -4
include/linux/goldfish.h
··· 3 3 4 4 /* Helpers for Goldfish virtual platform */ 5 5 6 - static inline void gf_write64(unsigned long data, 7 - void __iomem *portl, void __iomem *porth) 6 + static inline void gf_write_ptr(const void *ptr, void __iomem *portl, 7 + void __iomem *porth) 8 8 { 9 - writel((u32)data, portl); 9 + writel((u32)(unsigned long)ptr, portl); 10 10 #ifdef CONFIG_64BIT 11 - writel(data>>32, porth); 11 + writel((unsigned long)ptr >> 32, porth); 12 12 #endif 13 13 } 14 + 15 + static inline void gf_write_dma_addr(const dma_addr_t addr, 16 + void __iomem *portl, 17 + void __iomem *porth) 18 + { 19 + writel((u32)addr, portl); 20 + #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT 21 + writel(addr >> 32, porth); 22 + #endif 23 + } 24 + 14 25 15 26 #endif /* __LINUX_GOLDFISH_H */