]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
staging: gpib: Use min for calculating transfer length
authorDave Penkler <dpenkler@gmail.com>
Mon, 20 Jan 2025 14:50:30 +0000 (15:50 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 3 Feb 2025 15:06:30 +0000 (16:06 +0100)
In the accel read and write functions the transfer length
was being calculated by an if statement setting it to
the lesser of the remaining bytes to read/write and the
fifo size.

Replace both instances with min() which is clearer and
more compact.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@inria.fr>
Closes: https://lore.kernel.org/r/202501182153.qHfL4Fbc-lkp@intel.com/
Signed-off-by: Dave Penkler <dpenkler@gmail.com>
Link: https://lore.kernel.org/r/20250120145030.29684-1-dpenkler@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/gpib/agilent_82350b/agilent_82350b.c

index 3f4f95b7fe34ac68b7a8676f1faade74b36d2b2d..0ba592dc984900961c2e4fe1803df7274050fcd3 100644 (file)
@@ -66,10 +66,7 @@ int agilent_82350b_accel_read(gpib_board_t *board, uint8_t *buffer, size_t lengt
                int j;
                int count;
 
-               if (num_fifo_bytes - i < agilent_82350b_fifo_size)
-                       block_size = num_fifo_bytes - i;
-               else
-                       block_size = agilent_82350b_fifo_size;
+               block_size = min(num_fifo_bytes - i, agilent_82350b_fifo_size);
                set_transfer_counter(a_priv, block_size);
                writeb(ENABLE_TI_TO_SRAM | DIRECTION_GPIB_TO_HOST,
                       a_priv->gpib_base + SRAM_ACCESS_CONTROL_REG);
@@ -200,10 +197,7 @@ int agilent_82350b_accel_write(gpib_board_t *board, uint8_t *buffer, size_t leng
        for (i = 1; i < fifotransferlength;) {
                clear_bit(WRITE_READY_BN, &tms_priv->state);
 
-               if (fifotransferlength - i < agilent_82350b_fifo_size)
-                       block_size = fifotransferlength - i;
-               else
-                       block_size = agilent_82350b_fifo_size;
+               block_size = min(fifotransferlength - i, agilent_82350b_fifo_size);
                set_transfer_counter(a_priv, block_size);
                for (j = 0; j < block_size; ++j, ++i) {
                        // load data into board's sram