staging: most: usb: replace code to calculate array index
authorChristian Gromm <christian.gromm@microchip.com>
Wed, 27 May 2020 09:06:24 +0000 (11:06 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 27 May 2020 10:26:12 +0000 (12:26 +0200)
This patch removes the expression that makes use of a priori knowledge
about channel numbers to calculate an array index.
The expression 'peer = 1 - channel' utilizes the fact that an USB interface
that operates on the asynchronous data of the Network only has two
endpoints. Hence, channel being 0 or 1. The replacement is more simple and
less confusing when reading the code.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/1590570387-27069-8-git-send-email-christian.gromm@microchip.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/most/usb/usb.c

index 03318def82bdfbcd93d6228ea8004bf4dc722d15..468aabfc7c4f4fbca4a1d559fa7bb6f7c3073e09 100644 (file)
@@ -729,6 +729,8 @@ static void wq_clear_halt(struct work_struct *wq_obj)
        struct most_dev *mdev = clear_work->mdev;
        unsigned int channel = clear_work->channel;
        int pipe = clear_work->pipe;
+       int snd_pipe;
+       int peer;
 
        mutex_lock(&mdev->io_mutex);
        most_stop_enqueue(&mdev->iface, channel);
@@ -746,9 +748,12 @@ static void wq_clear_halt(struct work_struct *wq_obj)
         */
        if (mdev->conf[channel].data_type == MOST_CH_ASYNC &&
            mdev->conf[channel].direction == MOST_CH_RX) {
-               int peer = 1 - channel;
-               int snd_pipe = usb_sndbulkpipe(mdev->usb_device,
-                                              mdev->ep_address[peer]);
+               if (channel == 0)
+                       peer = 1;
+               else
+                       peer = 0;
+               snd_pipe = usb_sndbulkpipe(mdev->usb_device,
+                                          mdev->ep_address[peer]);
                usb_clear_halt(mdev->usb_device, snd_pipe);
        }
        mdev->is_channel_healthy[channel] = true;