android_pipe: don't be clever with #define offsets
authorAlex Bennée <alex.bennee@linaro.org>
Thu, 19 Jun 2014 14:05:27 +0000 (15:05 +0100)
committerGreg Hackmann <ghackmann@google.com>
Tue, 29 Jul 2014 19:50:09 +0000 (12:50 -0700)
You just make it harder to figure out when commands are being used.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Conflicts:
drivers/platform/goldfish/goldfish_pipe.c

Change-Id: I0ed4f1cba98116d0b0c3936e8b232e45d9beaa7a

drivers/platform/goldfish/goldfish_pipe.c

index 670b9b94f74bdf6919a5fe06b10c22cc0889180f..00b10952dfbd2f0dbbfcb4cfd942c4e63f1140d1 100644 (file)
 #define CMD_WRITE_BUFFER       4  /* send a user buffer to the emulator */
 #define CMD_WAKE_ON_WRITE      5  /* tell the emulator to wake us when writing
                                     is possible */
-
-/* The following commands are related to read operations, they must be
- * listed in the same order than the corresponding write ones, since we
- * will use (CMD_READ_BUFFER - CMD_WRITE_BUFFER) as a special offset
- * in goldfish_pipe_read_write() below.
- */
 #define CMD_READ_BUFFER        6  /* receive a user buffer from the emulator */
 #define CMD_WAKE_ON_READ       7  /* tell the emulator to wake us when reading
                                   * is possible */
@@ -279,8 +273,6 @@ static ssize_t goldfish_pipe_read_write(struct file *filp, char __user *buffer,
        unsigned long irq_flags;
        struct goldfish_pipe *pipe = filp->private_data;
        struct goldfish_pipe_dev *dev = pipe->dev;
-       const int cmd_offset = is_write ? 0
-                                       : (CMD_READ_BUFFER - CMD_WRITE_BUFFER);
        unsigned long address, address_end;
        int ret = 0;
 
@@ -332,8 +324,9 @@ static ssize_t goldfish_pipe_read_write(struct file *filp, char __user *buffer,
 
                /* Now, try to transfer the bytes in the current page */
                spin_lock_irqsave(&dev->lock, irq_flags);
-               if (access_with_param(dev, CMD_WRITE_BUFFER + cmd_offset,
-                               address, avail, pipe, &status)) {
+               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);
@@ -343,8 +336,8 @@ static ssize_t goldfish_pipe_read_write(struct file *filp, char __user *buffer,
 #ifdef CONFIG_64BIT
                        writel((u32)((u64)address >> 32), dev->base + PIPE_REG_ADDRESS_HIGH);
 #endif
-                       writel(CMD_WRITE_BUFFER + cmd_offset,
-                                       dev->base + PIPE_REG_COMMAND);
+                       writel(is_write ? CMD_WRITE_BUFFER : CMD_READ_BUFFER,
+                               dev->base + PIPE_REG_COMMAND);
                        status = readl(dev->base + PIPE_REG_STATUS);
                }
                spin_unlock_irqrestore(&dev->lock, irq_flags);
@@ -380,7 +373,8 @@ static ssize_t goldfish_pipe_read_write(struct file *filp, char __user *buffer,
                set_bit(wakeBit, &pipe->flags);
 
                /* Tell the emulator we're going to wait for a wake event */
-               goldfish_cmd(pipe, CMD_WAKE_ON_WRITE + cmd_offset);
+               goldfish_cmd(pipe,
+                            is_write ? CMD_WAKE_ON_WRITE : CMD_WAKE_ON_READ);
 
                /* Unlock the pipe, then wait for the wake signal */
                mutex_unlock(&pipe->lock);