netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Niklas Cassel <niklas.cassel@axis.com>
To: peppe.cavallaro@st.com, alexandre.torgue@st.com,
	jpinto@synopsys.com, joabreu@synopsys.com
Cc: netdev@vger.kernel.org
Subject: stmmac smatch error rx_queue_routing
Date: Mon, 22 Jan 2018 17:43:04 +0100	[thread overview]
Message-ID: <20180122164304.GC23171@axis.com> (raw)

Hello stmmac peeps,

I found this smatch error:

drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c:132 dwmac4_tx_queue_routing() error:
  buffer overflow 'route_possibilities' 5 <= 254
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c:133 dwmac4_tx_queue_routing() error:
  buffer overflow 'route_possibilities' 5 <= 254

Looking at the code raises some questions:


static void dwmac4_tx_queue_routing(struct mac_device_info *hw,
                                    u8 packet, u32 queue)
{
        ...
        static const struct stmmac_rx_routing route_possibilities[] = {
                { GMAC_RXQCTRL_AVCPQ_MASK, GMAC_RXQCTRL_AVCPQ_SHIFT },
                { GMAC_RXQCTRL_PTPQ_MASK, GMAC_RXQCTRL_PTPQ_SHIFT },
                { GMAC_RXQCTRL_DCBCPQ_MASK, GMAC_RXQCTRL_DCBCPQ_SHIFT },
                { GMAC_RXQCTRL_UPQ_MASK, GMAC_RXQCTRL_UPQ_SHIFT },
                { GMAC_RXQCTRL_MCBCQ_MASK, GMAC_RXQCTRL_MCBCQ_SHIFT },
        };

        value = readl(ioaddr + GMAC_RXQ_CTRL1);

        /* routing configuration */
        value &= ~route_possibilities[packet - 1].reg_mask;
        value |= (queue << route_possibilities[packet-1].reg_shift) &
                 route_possibilities[packet - 1].reg_mask;


Calling the function with e.g. packet == 0 will lead to interesting stuff,
so the smatch warning is absolutely warranted.



Looking where this function is used:

static const struct stmmac_ops dwmac4_ops = {
        ...
        .rx_queue_routing = dwmac4_tx_queue_routing,

Mixing rx and tx.. is this really correct?



Looking where the rx_queue_routing function is used:
git grep rx_queue_routing
stmmac_main.c:  if (rx_queues_count > 1 && priv->hw->mac->rx_queue_routing)

it is just referenced in a single place, and we only check if function is
non-NULL, we never even call the function, so right now it is just unused
code.


Regards,
Niklas

             reply	other threads:[~2018-01-22 16:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-22 16:43 Niklas Cassel [this message]
2018-01-22 16:55 ` stmmac smatch error rx_queue_routing Jose Abreu
2018-01-22 17:31   ` Niklas Cassel

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=20180122164304.GC23171@axis.com \
    --to=niklas.cassel@axis.com \
    --cc=alexandre.torgue@st.com \
    --cc=joabreu@synopsys.com \
    --cc=jpinto@synopsys.com \
    --cc=netdev@vger.kernel.org \
    --cc=peppe.cavallaro@st.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).