From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Nathan Chancellor <natechancellor@gmail.com>
Cc: Rob Herring <robh+dt@kernel.org>,
"David S . Miller" <davem@davemloft.net>,
Matthias Brugger <matthias.bgg@gmail.com>,
John Crispin <john@phrozen.org>,
Sean Wang <sean.wang@mediatek.com>,
Mark Lee <Mark-MC.Lee@mediatek.com>,
Jakub Kicinski <kuba@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
Fabien Parent <fparent@baylibre.com>,
Heiner Kallweit <hkallweit1@gmail.com>,
Edwin Peer <edwin.peer@broadcom.com>,
devicetree <devicetree@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
netdev <netdev@vger.kernel.org>,
Linux ARM <linux-arm-kernel@lists.infradead.org>,
"moderated list:ARM/Mediatek SoC..."
<linux-mediatek@lists.infradead.org>,
Stephane Le Provost <stephane.leprovost@mediatek.com>,
Pedro Tsai <pedro.tsai@mediatek.com>,
Andrew Perepech <andrew.perepech@mediatek.com>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
clang-built-linux@googlegroups.com
Subject: Re: [PATCH v5 06/11] net: ethernet: mtk-star-emac: new driver
Date: Wed, 27 May 2020 10:46:08 +0200 [thread overview]
Message-ID: <CAMRc=MevVsYZFDQif+8Zyv41sSkbS8XqWbKGdCvHooneXz88hg@mail.gmail.com> (raw)
In-Reply-To: <20200527073150.GA3384158@ubuntu-s3-xlarge-x86>
śr., 27 maj 2020 o 09:31 Nathan Chancellor <natechancellor@gmail.com>
napisał(a):
>
> On Fri, May 22, 2020 at 02:06:55PM +0200, Bartosz Golaszewski wrote:
>
> <snip>
>
> > diff --git a/drivers/net/ethernet/mediatek/mtk_star_emac.c b/drivers/net/ethernet/mediatek/mtk_star_emac.c
> > new file mode 100644
> > index 000000000000..789c77af501f
> > --- /dev/null
> > +++ b/drivers/net/ethernet/mediatek/mtk_star_emac.c
> > @@ -0,0 +1,1678 @@
>
> <snip>
>
> I've searched netdev and I cannot find any reports from others but this
> function introduces a clang warning:
>
> drivers/net/ethernet/mediatek/mtk_star_emac.c:1296:6: warning: variable 'new_dma_addr' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
> if (!new_skb) {
> ^~~~~~~~
> drivers/net/ethernet/mediatek/mtk_star_emac.c:1321:23: note: uninitialized use occurs here
> desc_data.dma_addr = new_dma_addr;
> ^~~~~~~~~~~~
> drivers/net/ethernet/mediatek/mtk_star_emac.c:1296:2: note: remove the 'if' if its condition is always false
> if (!new_skb) {
> ^~~~~~~~~~~~~~~
> drivers/net/ethernet/mediatek/mtk_star_emac.c:1285:6: warning: variable 'new_dma_addr' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
> if ((desc_data.flags & MTK_STAR_DESC_BIT_RX_CRCE) ||
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/net/ethernet/mediatek/mtk_star_emac.c:1321:23: note: uninitialized use occurs here
> desc_data.dma_addr = new_dma_addr;
> ^~~~~~~~~~~~
> drivers/net/ethernet/mediatek/mtk_star_emac.c:1285:2: note: remove the 'if' if its condition is always false
> if ((desc_data.flags & MTK_STAR_DESC_BIT_RX_CRCE) ||
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/net/ethernet/mediatek/mtk_star_emac.c:1285:6: warning: variable 'new_dma_addr' is used uninitialized whenever '||' condition is true [-Wsometimes-uninitialized]
> if ((desc_data.flags & MTK_STAR_DESC_BIT_RX_CRCE) ||
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/net/ethernet/mediatek/mtk_star_emac.c:1321:23: note: uninitialized use occurs here
> desc_data.dma_addr = new_dma_addr;
> ^~~~~~~~~~~~
> drivers/net/ethernet/mediatek/mtk_star_emac.c:1285:6: note: remove the '||' if its condition is always false
> if ((desc_data.flags & MTK_STAR_DESC_BIT_RX_CRCE) ||
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/net/ethernet/mediatek/mtk_star_emac.c:1274:25: note: initialize the variable 'new_dma_addr' to silence this warning
> dma_addr_t new_dma_addr;
> ^
> = 0
> 3 warnings generated.
>
> > +static int mtk_star_receive_packet(struct mtk_star_priv *priv)
> > +{
> > + struct mtk_star_ring *ring = &priv->rx_ring;
> > + struct device *dev = mtk_star_get_dev(priv);
> > + struct mtk_star_ring_desc_data desc_data;
> > + struct net_device *ndev = priv->ndev;
> > + struct sk_buff *curr_skb, *new_skb;
> > + dma_addr_t new_dma_addr;
>
> Uninitialized here
>
> > + int ret;
> > +
> > + spin_lock(&priv->lock);
> > + ret = mtk_star_ring_pop_tail(ring, &desc_data);
> > + spin_unlock(&priv->lock);
> > + if (ret)
> > + return -1;
> > +
> > + curr_skb = desc_data.skb;
> > +
> > + if ((desc_data.flags & MTK_STAR_DESC_BIT_RX_CRCE) ||
> > + (desc_data.flags & MTK_STAR_DESC_BIT_RX_OSIZE)) {
> > + /* Error packet -> drop and reuse skb. */
> > + new_skb = curr_skb;
> > + goto push_new_skb;
>
> this goto
>
> > + }
> > +
> > + /* Prepare new skb before receiving the current one. Reuse the current
> > + * skb if we fail at any point.
> > + */
> > + new_skb = mtk_star_alloc_skb(ndev);
> > + if (!new_skb) {
> > + ndev->stats.rx_dropped++;
> > + new_skb = curr_skb;
> > + goto push_new_skb;
>
> and this goto
>
> > + }
> > +
> > + new_dma_addr = mtk_star_dma_map_rx(priv, new_skb);
> > + if (dma_mapping_error(dev, new_dma_addr)) {
> > + ndev->stats.rx_dropped++;
> > + dev_kfree_skb(new_skb);
> > + new_skb = curr_skb;
> > + netdev_err(ndev, "DMA mapping error of RX descriptor\n");
> > + goto push_new_skb;
> > + }
> > +
> > + /* We can't fail anymore at this point: it's safe to unmap the skb. */
> > + mtk_star_dma_unmap_rx(priv, &desc_data);
> > +
> > + skb_put(desc_data.skb, desc_data.len);
> > + desc_data.skb->ip_summed = CHECKSUM_NONE;
> > + desc_data.skb->protocol = eth_type_trans(desc_data.skb, ndev);
> > + desc_data.skb->dev = ndev;
> > + netif_receive_skb(desc_data.skb);
> > +
> > +push_new_skb:
> > + desc_data.dma_addr = new_dma_addr;
>
> assign it uninitialized here.
>
> > + desc_data.len = skb_tailroom(new_skb);
> > + desc_data.skb = new_skb;
> > +
> > + spin_lock(&priv->lock);
> > + mtk_star_ring_push_head_rx(ring, &desc_data);
> > + spin_unlock(&priv->lock);
> > +
> > + return 0;
> > +}
>
> I don't know if there should be a new label that excludes that
> assignment for those particular gotos or if new_dma_addr should
> be initialized to something at the top. Please take a look at
> addressing this when you get a chance.
>
> Cheers,
> Nathan
Hi Nathan,
Thanks for reporting this! I have a fix ready and will send it shortly.
Bartosz
next prev parent reply other threads:[~2020-05-27 8:46 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-22 12:06 [PATCH v5 00/11] mediatek: add support for MediaTek Ethernet MAC Bartosz Golaszewski
2020-05-22 12:06 ` [PATCH v5 01/11] dt-bindings: convert the binding document for mediatek PERICFG to yaml Bartosz Golaszewski
2020-05-22 12:06 ` [PATCH v5 02/11] dt-bindings: add new compatible to mediatek,pericfg Bartosz Golaszewski
2020-05-22 12:06 ` [PATCH v5 03/11] dt-bindings: net: add a binding document for MediaTek STAR Ethernet MAC Bartosz Golaszewski
2020-05-22 12:06 ` [PATCH v5 04/11] net: ethernet: mediatek: rename Kconfig prompt Bartosz Golaszewski
2020-05-22 12:06 ` [PATCH v5 05/11] net: ethernet: mediatek: remove unnecessary spaces from Makefile Bartosz Golaszewski
2020-05-22 12:06 ` [PATCH v5 06/11] net: ethernet: mtk-star-emac: new driver Bartosz Golaszewski
2020-05-22 15:06 ` Matthias Brugger
2020-05-22 15:26 ` Bartosz Golaszewski
2020-05-22 15:35 ` Bartosz Golaszewski
2020-05-22 23:36 ` Andrew Lunn
2020-05-27 7:31 ` Nathan Chancellor
2020-05-27 8:46 ` Bartosz Golaszewski [this message]
2020-05-27 11:33 ` Arnd Bergmann
2020-05-27 11:48 ` Bartosz Golaszewski
2020-05-27 12:28 ` Arnd Bergmann
2020-05-22 12:06 ` [PATCH v5 07/11] ARM64: dts: mediatek: add pericfg syscon to mt8516.dtsi Bartosz Golaszewski
2020-05-22 12:06 ` [PATCH v5 08/11] ARM64: dts: mediatek: add the ethernet node " Bartosz Golaszewski
2020-05-22 12:06 ` [PATCH v5 09/11] ARM64: dts: mediatek: add an alias for ethernet0 for pumpkin boards Bartosz Golaszewski
2020-05-22 12:06 ` [PATCH v5 10/11] ARM64: dts: mediatek: add ethernet pins " Bartosz Golaszewski
2020-05-22 12:07 ` [PATCH v5 11/11] ARM64: dts: mediatek: enable ethernet on " Bartosz Golaszewski
2020-05-22 21:20 ` [PATCH v5 00/11] mediatek: add support for MediaTek Ethernet MAC David Miller
2020-05-22 21:31 ` Matthias Brugger
2020-05-22 21:36 ` David Miller
2020-05-23 13:14 ` Matthias Brugger
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='CAMRc=MevVsYZFDQif+8Zyv41sSkbS8XqWbKGdCvHooneXz88hg@mail.gmail.com' \
--to=brgl@bgdev.pl \
--cc=Mark-MC.Lee@mediatek.com \
--cc=andrew.perepech@mediatek.com \
--cc=arnd@arndb.de \
--cc=bgolaszewski@baylibre.com \
--cc=clang-built-linux@googlegroups.com \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edwin.peer@broadcom.com \
--cc=fparent@baylibre.com \
--cc=hkallweit1@gmail.com \
--cc=john@phrozen.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=natechancellor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pedro.tsai@mediatek.com \
--cc=robh+dt@kernel.org \
--cc=sean.wang@mediatek.com \
--cc=stephane.leprovost@mediatek.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).