Netdev List
 help / color / mirror / Atom feed
From: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
To: davem@davemloft.net
Cc: Jacob Keller <jacob.e.keller@intel.com>,
	netdev@vger.kernel.org, nhorman@redhat.com, sassmann@redhat.com,
	jogreene@redhat.com, Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Subject: [net-next 06/13] fm10k: avoid possible truncation of q_vector->name
Date: Mon,  2 Oct 2017 08:42:29 -0700	[thread overview]
Message-ID: <20171002154236.84043-7-jeffrey.t.kirsher@intel.com> (raw)
In-Reply-To: <20171002154236.84043-1-jeffrey.t.kirsher@intel.com>

From: Jacob Keller <jacob.e.keller@intel.com>

New versions of GCC since version 7 began warning about possible
truncation of calls to snprintf. We can fix this and avoid false
positives. First, we should pass the full buffer size to snprintf,
because it guarantees a NULL character as part of its passed length, so
passing len-1 is simply wasting a byte of possible storage.

Second, if we make the ri and ti variables unsigned, the compiler is
able to correctly reason that the value never gets larger than 256, so
it doesn't need to warn about the full space required to print a signed
integer.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Krishneil Singh <krishneil.k.singh@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---
 drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_pci.c b/drivers/net/ethernet/intel/fm10k/fm10k_pci.c
index 63784576ae8b..9212b3fa3b62 100644
--- a/drivers/net/ethernet/intel/fm10k/fm10k_pci.c
+++ b/drivers/net/ethernet/intel/fm10k/fm10k_pci.c
@@ -1544,7 +1544,7 @@ int fm10k_qv_request_irq(struct fm10k_intfc *interface)
 	struct net_device *dev = interface->netdev;
 	struct fm10k_hw *hw = &interface->hw;
 	struct msix_entry *entry;
-	int ri = 0, ti = 0;
+	unsigned int ri = 0, ti = 0;
 	int vector, err;
 
 	entry = &interface->msix_entries[NON_Q_VECTORS(hw)];
@@ -1554,15 +1554,15 @@ int fm10k_qv_request_irq(struct fm10k_intfc *interface)
 
 		/* name the vector */
 		if (q_vector->tx.count && q_vector->rx.count) {
-			snprintf(q_vector->name, sizeof(q_vector->name) - 1,
-				 "%s-TxRx-%d", dev->name, ri++);
+			snprintf(q_vector->name, sizeof(q_vector->name),
+				 "%s-TxRx-%u", dev->name, ri++);
 			ti++;
 		} else if (q_vector->rx.count) {
-			snprintf(q_vector->name, sizeof(q_vector->name) - 1,
-				 "%s-rx-%d", dev->name, ri++);
+			snprintf(q_vector->name, sizeof(q_vector->name),
+				 "%s-rx-%u", dev->name, ri++);
 		} else if (q_vector->tx.count) {
-			snprintf(q_vector->name, sizeof(q_vector->name) - 1,
-				 "%s-tx-%d", dev->name, ti++);
+			snprintf(q_vector->name, sizeof(q_vector->name),
+				 "%s-tx-%u", dev->name, ti++);
 		} else {
 			/* skip this unused q_vector */
 			continue;
-- 
2.14.2

  parent reply	other threads:[~2017-10-02 15:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-02 15:42 [net-next 00/13][pull request] 100GbE Intel Wired LAN Driver Updates 2017-10-02 Jeff Kirsher
2017-10-02 15:42 ` [net-next 01/13] fm10k: ensure we process SM mbx when processing VF mbx Jeff Kirsher
2017-10-02 15:42 ` [net-next 02/13] fm10k: reschedule service event if we stall the PF<->SM mailbox Jeff Kirsher
2017-10-02 15:42 ` [net-next 03/13] fm10k: Use seq_putc() in fm10k_dbg_desc_break() Jeff Kirsher
2017-10-02 15:42 ` [net-next 04/13] fm10k: stop spurious link down messages when Tx FIFO is full Jeff Kirsher
2017-10-02 15:42 ` [net-next 05/13] fm10k: fix typos on fall through comments Jeff Kirsher
2017-10-02 15:42 ` Jeff Kirsher [this message]
2017-10-02 15:42 ` [net-next 07/13] fm10k: add missing fall through comment Jeff Kirsher
2017-10-02 15:42 ` [net-next 08/13] fm10k: avoid needless delay when loading driver Jeff Kirsher
2017-10-02 15:42 ` [net-next 09/13] fm10k: simplify reading PFVFLRE register Jeff Kirsher
2017-10-02 15:42 ` [net-next 10/13] fm10k: don't loop while resetting VFs due to VFLR event Jeff Kirsher
2017-10-02 15:42 ` [net-next 11/13] fm10k: avoid divide by zero in rare cases when device is resetting Jeff Kirsher
2017-10-02 15:42 ` [net-next 12/13] fm10k: move fm10k_prepare_for_reset and fm10k_handle_reset Jeff Kirsher
2017-10-02 15:42 ` [net-next 13/13] fm10k: prevent race condition of __FM10K_SERVICE_SCHED Jeff Kirsher
2017-10-02 18:59 ` [net-next 00/13][pull request] 100GbE Intel Wired LAN Driver Updates 2017-10-02 David Miller

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=20171002154236.84043-7-jeffrey.t.kirsher@intel.com \
    --to=jeffrey.t.kirsher@intel.com \
    --cc=davem@davemloft.net \
    --cc=jacob.e.keller@intel.com \
    --cc=jogreene@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@redhat.com \
    --cc=sassmann@redhat.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