Patch "net: ocelot: fix wrong time_after usage" has been added to the 5.18-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

    net: ocelot: fix wrong time_after usage

to the 5.18-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:
     net-ocelot-fix-wrong-time_after-usage.patch
and it can be found in the queue-5.18 subdirectory.

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



commit e2088345538f91f3113c6428cef37022942633b7
Author: Pavel Skripkin <paskripkin@xxxxxxxxx>
Date:   Wed Jul 6 16:28:45 2022 +0300

    net: ocelot: fix wrong time_after usage
    
    [ Upstream commit f46fd3d7c3bd5d7bd5bb664135cf32ca9e97190b ]
    
    Accidentally noticed, that this driver is the only user of
    while (time_after(jiffies...)).
    
    It looks like typo, because likely this while loop will finish after 1st
    iteration, because time_after() returns true when 1st argument _is after_
    2nd one.
    
    There is one possible problem with this poll loop: the scheduler could put
    the thread to sleep, and it does not get woken up for
    OCELOT_FDMA_CH_SAFE_TIMEOUT_US. During that time, the hardware has done
    its thing, but you exit the while loop and return -ETIMEDOUT.
    
    Fix it by using sane poll API that avoids all problems described above
    
    Fixes: 753a026cfec1 ("net: ocelot: add FDMA support")
    Suggested-by: Andrew Lunn <andrew@xxxxxxx>
    Signed-off-by: Pavel Skripkin <paskripkin@xxxxxxxxx>
    Reviewed-by: Vladimir Oltean <vladimir.oltean@xxxxxxx>
    Link: https://lore.kernel.org/r/20220706132845.27968-1-paskripkin@xxxxxxxxx
    Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/net/ethernet/mscc/ocelot_fdma.c b/drivers/net/ethernet/mscc/ocelot_fdma.c
index dffa597bffe6..6a8f84f325a3 100644
--- a/drivers/net/ethernet/mscc/ocelot_fdma.c
+++ b/drivers/net/ethernet/mscc/ocelot_fdma.c
@@ -94,19 +94,18 @@ static void ocelot_fdma_activate_chan(struct ocelot *ocelot, dma_addr_t dma,
 	ocelot_fdma_writel(ocelot, MSCC_FDMA_CH_ACTIVATE, BIT(chan));
 }
 
+static u32 ocelot_fdma_read_ch_safe(struct ocelot *ocelot)
+{
+	return ocelot_fdma_readl(ocelot, MSCC_FDMA_CH_SAFE);
+}
+
 static int ocelot_fdma_wait_chan_safe(struct ocelot *ocelot, int chan)
 {
-	unsigned long timeout;
 	u32 safe;
 
-	timeout = jiffies + usecs_to_jiffies(OCELOT_FDMA_CH_SAFE_TIMEOUT_US);
-	do {
-		safe = ocelot_fdma_readl(ocelot, MSCC_FDMA_CH_SAFE);
-		if (safe & BIT(chan))
-			return 0;
-	} while (time_after(jiffies, timeout));
-
-	return -ETIMEDOUT;
+	return readx_poll_timeout_atomic(ocelot_fdma_read_ch_safe, ocelot, safe,
+					 safe & BIT(chan), 0,
+					 OCELOT_FDMA_CH_SAFE_TIMEOUT_US);
 }
 
 static void ocelot_fdma_dcb_set_data(struct ocelot_fdma_dcb *dcb,



[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