lkml.org 
[lkml]   [2020]   [May]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] stmmac: fix pointer check after utilization in stmmac_interrupt
The paranoidal pointer check in IRQ handler looks very strange - it
really protects us only against bogus drivers which request IRQ line
with null pointer dev_id. However, the code fragment is incorrect
because the dev pointer is used before the actual check. That leads
to undefined behavior thus compilers are free to remove the pointer
check at all.

Signed-off-by: Maxim Petrov <mmrmaximuzz@gmail.com>
---
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 20 +++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 565da6498c84..ca08699f5565 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4070,24 +4070,28 @@ static int stmmac_set_features(struct net_device *netdev,
*/
static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
{
- struct net_device *dev = (struct net_device *)dev_id;
- struct stmmac_priv *priv = netdev_priv(dev);
- u32 rx_cnt = priv->plat->rx_queues_to_use;
- u32 tx_cnt = priv->plat->tx_queues_to_use;
+ u32 rx_cnt;
+ u32 tx_cnt;
u32 queues_count;
u32 queue;
bool xmac;
+ struct stmmac_priv *priv;
+ struct net_device *dev = (struct net_device *)dev_id;

+ if (unlikely(!dev)) {
+ netdev_err(NULL, "%s: invalid dev pointer\n", __func__);
+ return IRQ_NONE;
+ }
+
+ priv = netdev_priv(dev);
+ rx_cnt = priv->plat->rx_queues_to_use;
+ tx_cnt = priv->plat->tx_queues_to_use;
xmac = priv->plat->has_gmac4 || priv->plat->has_xgmac;
queues_count = (rx_cnt > tx_cnt) ? rx_cnt : tx_cnt;

if (priv->irq_wake)
pm_wakeup_event(priv->device, 0);

- if (unlikely(!dev)) {
- netdev_err(priv->dev, "%s: invalid dev pointer\n", __func__);
- return IRQ_NONE;
- }

/* Check if adapter is up */
if (test_bit(STMMAC_DOWN, &priv->state))
base-commit: 6a8b55ed4056ea5559ebe4f6a4b247f627870d4c
--
2.17.1

\
 
 \ /
  Last update: 2020-05-02 11:29    [W:0.040 / U:0.884 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site