From: Wolfram Sang <wsa@the-dreams.de>
To: netdev@vger.kernel.org
Cc: Wolfram Sang <wsa@the-dreams.de>,
Simon Horman <horms@verge.net.au>,
Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>,
linux-renesas-soc@vger.kernel.org
Subject: [PATCH] net: sh_eth: avoid NULL pointer dereference in ring setup
Date: Wed, 2 Mar 2016 16:26:06 +0100 [thread overview]
Message-ID: <1456932370-4143-1-git-send-email-wsa@the-dreams.de> (raw)
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
When allocating an skb fails, rxdesc is still NULL (or the previous ring
index on further iterations of the loop). However, this pointer is
dereferenced after the loop. So, make sure rxdesc is updated immediately
at the beginning of the loop.
Reported-by: coverity (CID 1056464)
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/net/ethernet/renesas/sh_eth.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index a2767336b7c545..d5f13d54099734 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -1120,6 +1120,7 @@ static void sh_eth_ring_format(struct net_device *ndev)
/* build Rx ring buffer */
for (i = 0; i < mdp->num_rx_ring; i++) {
+ rxdesc = &mdp->rx_ring[i];
/* skb */
mdp->rx_skbuff[i] = NULL;
skb = netdev_alloc_skb(ndev, skbuff_size);
@@ -1128,7 +1129,6 @@ static void sh_eth_ring_format(struct net_device *ndev)
sh_eth_set_receive_align(skb);
/* RX descriptor */
- rxdesc = &mdp->rx_ring[i];
/* The size of the buffer is a multiple of 32 bytes. */
buf_len = ALIGN(mdp->rx_buf_sz, 32);
rxdesc->len = cpu_to_le32(buf_len << 16);
--
2.7.0
next reply other threads:[~2016-03-02 15:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-02 15:26 Wolfram Sang [this message]
2016-03-02 16:47 ` [PATCH] net: sh_eth: avoid NULL pointer dereference in ring setup Sergei Shtylyov
2016-03-02 17:11 ` Wolfram Sang
2016-03-02 17:47 ` Sergei Shtylyov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1456932370-4143-1-git-send-email-wsa@the-dreams.de \
--to=wsa@the-dreams.de \
--cc=horms@verge.net.au \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sergei.shtylyov@cogentembedded.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).