public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Russell King <rmk+kernel@armlinux•org.uk>
To: Andrew Lunn <andrew@lunn•ch>, Florian Fainelli <f.fainelli@gmail•com>
Cc: netdev@vger•kernel.org
Subject: [PATCH net-next A 1/5] sfp: use precision to print non-null terminated strings
Date: Fri, 29 Dec 2017 12:15:12 +0000	[thread overview]
Message-ID: <E1eUtZA-0001uW-K8@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <20171229121451.GY10595@n2100.armlinux.org.uk>

Rather than memcpy()'ing the strings and null terminate them, printf
allows non-NULL terminated strings provided the precision is not more
than the size of the buffer.  Use this form to print the basic module
information rather than copying and terminating the strings.

Signed-off-by: Russell King <rmk+kernel@armlinux•org.uk>
---
 drivers/net/phy/sfp.c | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index ee6b2e041171..6c7d9289078d 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -466,11 +466,6 @@ static int sfp_sm_mod_probe(struct sfp *sfp)
 {
 	/* SFP module inserted - read I2C data */
 	struct sfp_eeprom_id id;
-	char vendor[17];
-	char part[17];
-	char sn[17];
-	char date[9];
-	char rev[5];
 	u8 check;
 	int err;
 
@@ -506,19 +501,12 @@ static int sfp_sm_mod_probe(struct sfp *sfp)
 
 	sfp->id = id;
 
-	memcpy(vendor, sfp->id.base.vendor_name, 16);
-	vendor[16] = '\0';
-	memcpy(part, sfp->id.base.vendor_pn, 16);
-	part[16] = '\0';
-	memcpy(rev, sfp->id.base.vendor_rev, 4);
-	rev[4] = '\0';
-	memcpy(sn, sfp->id.ext.vendor_sn, 16);
-	sn[16] = '\0';
-	memcpy(date, sfp->id.ext.datecode, 8);
-	date[8] = '\0';
-
-	dev_info(sfp->dev, "module %s %s rev %s sn %s dc %s\n",
-		 vendor, part, rev, sn, date);
+	dev_info(sfp->dev, "module %.*s %.*s rev %.*s sn %.*s dc %.*s\n",
+		 (int)sizeof(id.base.vendor_name), id.base.vendor_name,
+		 (int)sizeof(id.base.vendor_pn), id.base.vendor_pn,
+		 (int)sizeof(id.base.vendor_rev), id.base.vendor_rev,
+		 (int)sizeof(id.ext.vendor_sn), id.ext.vendor_sn,
+		 (int)sizeof(id.ext.datecode), id.ext.datecode);
 
 	/* Check whether we support this module */
 	if (!sfp->type->module_supported(&sfp->id)) {
-- 
2.7.4

  reply	other threads:[~2017-12-29 12:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-29 12:14 [PATCH net-next A 0/5] further sfp/phylink updates Russell King - ARM Linux
2017-12-29 12:15 ` Russell King [this message]
2017-12-29 12:15 ` [PATCH net-next A 2/5] sfp: don't guess support from connector type Russell King
2017-12-29 12:15 ` [PATCH net-next A 3/5] sfp: add support for 1000Base-PX and 1000Base-BX10 Russell King
2017-12-29 12:15 ` [PATCH net-next A 4/5] sfp: improve support for direct-attach copper cables Russell King
2017-12-29 12:15 ` [PATCH net-next A 5/5] phylink: remove 'mode' variable from phylink_sfp_module_insert() Russell King
2018-01-03  2:45 ` [PATCH net-next A 0/5] further sfp/phylink updates 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=E1eUtZA-0001uW-K8@rmk-PC.armlinux.org.uk \
    --to=rmk+kernel@armlinux$(echo .)org.uk \
    --cc=andrew@lunn$(echo .)ch \
    --cc=f.fainelli@gmail$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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