Patch "spi: Fix erroneous sgs value with min_t()" has been added to the 5.16-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    spi: Fix erroneous sgs value with min_t()

to the 5.16-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     spi-fix-erroneous-sgs-value-with-min_t.patch
and it can be found in the queue-5.16 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit ab97f2e6a340df4aa2f64d5c8586cf84490c886b
Author: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
Date:   Wed Mar 16 17:53:17 2022 +0000

    spi: Fix erroneous sgs value with min_t()
    
    [ Upstream commit ebc4cb43ea5ada3db46c80156fca58a54b9bbca8 ]
    
    While computing sgs in spi_map_buf(), the data type
    used in min_t() for max_seg_size is 'unsigned int' where
    as that of ctlr->max_dma_len is 'size_t'.
    
    min_t(unsigned int,x,y) gives wrong results if one of x/y is
    'size_t'
    
    Consider the below examples on a 64-bit machine (ie size_t is
    64-bits, and unsigned int is 32-bit).
        case 1) min_t(unsigned int, 5, 0x100000001);
        case 2) min_t(size_t, 5, 0x100000001);
    
    Case 1 returns '1', where as case 2 returns '5'. As you can see
    the result from case 1 is wrong.
    
    This patch fixes the above issue by using the data type of the
    parameters that are used in min_t with maximum data length.
    
    Fixes: commit 1a4e53d2fc4f68aa ("spi: Fix invalid sgs value")
    Reported-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
    Suggested-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
    Signed-off-by: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
    Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20220316175317.465-1-biju.das.jz@xxxxxxxxxxxxxx
    Signed-off-by: Mark Brown <broonie@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ed4e6983eda0..4e459516b74c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1021,10 +1021,10 @@ int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
 	int i, ret;
 
 	if (vmalloced_buf || kmap_buf) {
-		desc_len = min_t(unsigned int, max_seg_size, PAGE_SIZE);
+		desc_len = min_t(unsigned long, max_seg_size, PAGE_SIZE);
 		sgs = DIV_ROUND_UP(len + offset_in_page(buf), desc_len);
 	} else if (virt_addr_valid(buf)) {
-		desc_len = min_t(unsigned int, max_seg_size, ctlr->max_dma_len);
+		desc_len = min_t(size_t, max_seg_size, ctlr->max_dma_len);
 		sgs = DIV_ROUND_UP(len, desc_len);
 	} else {
 		return -EINVAL;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux