All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
To: davem@davemloft.net
Cc: Tony Nguyen <anthony.l.nguyen@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 07/15] ixgbe: Resolve truncation warning for q_vector->name
Date: Wed, 31 May 2017 14:19:28 -0700	[thread overview]
Message-ID: <20170531211936.63417-8-jeffrey.t.kirsher@intel.com> (raw)
In-Reply-To: <20170531211936.63417-1-jeffrey.t.kirsher@intel.com>

From: Tony Nguyen <anthony.l.nguyen@intel.com>

The following warning is now shown as a result of new checks added for
gcc 7:

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c: In function ‘ixgbe_open’:
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c:3118:13: warning: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size between 3 and 18 [-Wformat-truncation=]
      "%s-%s-%d", netdev->name, "TxRx", ri++);
             ^~
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c:3118:6: note: directive argument in the range [0, 2147483647]
      "%s-%s-%d", netdev->name, "TxRx", ri++);
      ^~~~~~~~~~
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c:3117:4: note: ‘snprintf’ output between 8 and 32 bytes into a destination of size 24
    snprintf(q_vector->name, sizeof(q_vector->name) - 1,
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      "%s-%s-%d", netdev->name, "TxRx", ri++);
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Resolve this warning by making a couple of changes.
 - Don't reserve space for the null terminator.  Since snprintf adds the
   null terminator automatically, there is no need for us to reserve a byte
   for it.

 - Change a couple variables that can never be negative from int to
   unsigned int.

While we're making changes to the format string, move the constant strings
into the format string instead of providing them as specifiers.

Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 5c671b7401cd..0d2c54693cf3 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -3105,23 +3105,23 @@ int ixgbe_poll(struct napi_struct *napi, int budget)
 static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
 {
 	struct net_device *netdev = adapter->netdev;
+	unsigned int ri = 0, ti = 0;
 	int vector, err;
-	int ri = 0, ti = 0;
 
 	for (vector = 0; vector < adapter->num_q_vectors; vector++) {
 		struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
 		struct msix_entry *entry = &adapter->msix_entries[vector];
 
 		if (q_vector->tx.ring && q_vector->rx.ring) {
-			snprintf(q_vector->name, sizeof(q_vector->name) - 1,
-				 "%s-%s-%d", netdev->name, "TxRx", ri++);
+			snprintf(q_vector->name, sizeof(q_vector->name),
+				 "%s-TxRx-%u", netdev->name, ri++);
 			ti++;
 		} else if (q_vector->rx.ring) {
-			snprintf(q_vector->name, sizeof(q_vector->name) - 1,
-				 "%s-%s-%d", netdev->name, "rx", ri++);
+			snprintf(q_vector->name, sizeof(q_vector->name),
+				 "%s-rx-%u", netdev->name, ri++);
 		} else if (q_vector->tx.ring) {
-			snprintf(q_vector->name, sizeof(q_vector->name) - 1,
-				 "%s-%s-%d", netdev->name, "tx", ti++);
+			snprintf(q_vector->name, sizeof(q_vector->name),
+				 "%s-tx-%u", netdev->name, ti++);
 		} else {
 			/* skip this unused q_vector */
 			continue;
-- 
2.12.2

  parent reply	other threads:[~2017-05-31 21:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-31 21:19 [net-next 00/15][pull request] 10GbE Intel Wired LAN Driver Updates 2017-05-31 Jeff Kirsher
2017-05-31 21:19 ` [net-next 01/15] ixgbe/ixgbevf: Enables TSO for MPLS encapsulated packets Jeff Kirsher
2017-05-31 21:19 ` [net-next 02/15] ixgbe: initialize u64_stats_sync structures early at ixgbe_probe Jeff Kirsher
2017-05-31 21:19 ` [net-next 03/15] ixgbe: Remove MAC X550EM_X 1Gbase-t led_[on|off] support Jeff Kirsher
2017-05-31 21:19 ` [net-next 04/15] ixgbe: enable L3/L4 filtering for Tx switched packets Jeff Kirsher
2017-05-31 21:19 ` [net-next 05/15] ixgbe: Correct thermal sensor event check Jeff Kirsher
2017-05-31 21:19 ` [net-next 06/15] ixgbe: Add error checking to setting VF MAC Jeff Kirsher
2017-05-31 21:19 ` Jeff Kirsher [this message]
2017-05-31 21:19 ` [net-next 08/15] ixgbe: Resolve warnings for -Wimplicit-fallthrough Jeff Kirsher
2017-05-31 21:19 ` [net-next 09/15] ixgbevf: Resolve truncation warning for q_vector->name Jeff Kirsher
2017-06-01  9:30   ` Sergei Shtylyov
2017-05-31 21:19 ` [net-next 10/15] ixgbevf: Resolve warnings for -Wimplicit-fallthrough Jeff Kirsher
2017-05-31 21:19 ` [net-next 11/15] ixgbe: correct CS4223/7 PHY identification Jeff Kirsher
2017-05-31 21:19 ` [net-next 12/15] ixgbe: add write flush when configuring CS4223/7 Jeff Kirsher
2017-05-31 21:19 ` [net-next 13/15] ixgbe: always call setup_mac_link for multispeed fiber Jeff Kirsher
2017-05-31 21:19 ` [net-next 14/15] ixgbe: add missing configuration for rate select 1 Jeff Kirsher
2017-05-31 21:19 ` [net-next 15/15] ixgbe: fix incorrect status check Jeff Kirsher
2017-05-31 21:55 ` [net-next 00/15][pull request] 10GbE Intel Wired LAN Driver Updates 2017-05-31 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=20170531211936.63417-8-jeffrey.t.kirsher@intel.com \
    --to=jeffrey.t.kirsher@intel.com \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.