From 064fb5d8f10e6bfdec2f17c107de02d2b5adaece Mon Sep 17 00:00:00 2001 From: Christoffer Dall Date: Thu, 30 Oct 2014 11:25:59 +0100 Subject: [PATCH] goldfish_pipe: Squash warnings on 32-bit systems The goldfish_pipe driver casts a pointer to a (u64), but this will generate a warning on 32-bit systems, because we are casting a pointer to a type with a different size. Instead, cast the pointer to an unsigned long, which will work on both 32-bit and 64-bit systems, and then cast that to a 32-bit value which the backend expects. Also wrap this in a pipe_id() function to make it clear that we are not expecting the backend to use the pointer for anything but that we are merely using it as an identifier. Perhaps it would be possible to use a simple running allocation scheme of IDs instead. Signed-off-by: Christoffer Dall --- drivers/platform/goldfish/goldfish_pipe.c | 36 +++++++++++++++-------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c index adda434c1a6..517813cd2d6 100644 --- a/drivers/platform/goldfish/goldfish_pipe.c +++ b/drivers/platform/goldfish/goldfish_pipe.c @@ -149,6 +149,25 @@ enum { BIT_WAKE_ON_READ = 2, /* want to be woken on reads */ }; +static unsigned long pipe_id(struct goldfish_pipe *pipe) +{ + /* + * We use the pointer address to the goldfish_pipe struct as a unique + * identifier for the pipe in the backend; the backend doesn't + * acutally know or assume this is a pointer. + */ + return (unsigned long)pipe; +} + +static void set_pipe_channel(struct goldfish_pipe *pipe) +{ + struct goldfish_pipe_dev *dev = pipe->dev; + + writel((u32)pipe_id(pipe), dev->base + PIPE_REG_CHANNEL); +#ifdef CONFIG_64BIT + writel((u32)(pipe_id(pipe) >> 32), dev->base + PIPE_REG_CHANNEL_HIGH); +#endif +} static u32 goldfish_cmd_status(struct goldfish_pipe *pipe, u32 cmd) { @@ -157,10 +176,7 @@ static u32 goldfish_cmd_status(struct goldfish_pipe *pipe, u32 cmd) struct goldfish_pipe_dev *dev = pipe->dev; spin_lock_irqsave(&dev->lock, flags); - writel((u32)(u64)pipe, dev->base + PIPE_REG_CHANNEL); -#ifdef CONFIG_64BIT - writel((u32)((u64)pipe >> 32), dev->base + PIPE_REG_CHANNEL_HIGH); -#endif + set_pipe_channel(pipe); writel(cmd, dev->base + PIPE_REG_COMMAND); status = readl(dev->base + PIPE_REG_STATUS); spin_unlock_irqrestore(&dev->lock, flags); @@ -173,10 +189,7 @@ static void goldfish_cmd(struct goldfish_pipe *pipe, u32 cmd) struct goldfish_pipe_dev *dev = pipe->dev; spin_lock_irqsave(&dev->lock, flags); - writel((u32)(u64)pipe, dev->base + PIPE_REG_CHANNEL); -#ifdef CONFIG_64BIT - writel((u32)((u64)pipe >> 32), dev->base + PIPE_REG_CHANNEL_HIGH); -#endif + set_pipe_channel(pipe); writel(cmd, dev->base + PIPE_REG_COMMAND); spin_unlock_irqrestore(&dev->lock, flags); } @@ -251,7 +264,7 @@ static int access_with_param(struct goldfish_pipe_dev *dev, const int cmd, return -1; aps->result = INITIAL_BATCH_RESULT; - aps->channel = (unsigned long)pipe; + aps->channel = pipe_id(pipe); aps->size = avail; aps->address = address; aps->cmd = cmd; @@ -319,10 +332,7 @@ static ssize_t goldfish_pipe_read_write(struct file *filp, char __user *buffer, if (access_with_param(dev, is_write ? CMD_WRITE_BUFFER : CMD_READ_BUFFER, address, avail, pipe, &status)) { - writel((u32)(u64)pipe, dev->base + PIPE_REG_CHANNEL); -#ifdef CONFIG_64BIT - writel((u32)((u64)pipe >> 32), dev->base + PIPE_REG_CHANNEL_HIGH); -#endif + set_pipe_channel(pipe); writel(avail, dev->base + PIPE_REG_SIZE); writel(address, dev->base + PIPE_REG_ADDRESS); #ifdef CONFIG_64BIT -- 2.34.1