linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Toshi Kani <toshi.kani@hpe.com>
To: mchehab@osg.samsung.com, bp@alien8.de, dougthompson@xmission.com
Cc: linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org,
	elliott@hpe.com, tony.luck@intel.com,
	Toshi Kani <toshi.kani@hpe.com>
Subject: [PATCH v2 1/2] EDAC: Fix sysfs dimm_label show operation
Date: Tue, 22 Sep 2015 08:58:02 -0600	[thread overview]
Message-ID: <1442933883-21587-2-git-send-email-toshi.kani@hpe.com> (raw)
In-Reply-To: <1442933883-21587-1-git-send-email-toshi.kani@hpe.com>

After 'commit 7d375bffa524 ("sb_edac: Fix support for systems with
two home agents per socket")', sysfs "dimm_label" and "chX_dimm_label"
show their label string without a newline "\n" at the end.

 [root@orange ~]# cat /sys/bus/mc0/devices/dimm0/dimm_label
 CPU_SrcID#0_Ha#0_Chan#0_DIMM#0[root@orange ~]#

 [root@orange ~]# cat /sys/devices/system/edac/mc/mc0/csrow0/ch0_dimm_label
 CPU_SrcID#0_Ha#0_Chan#0_DIMM#0[root@orange ~]#

The label strings now have 31 characters, which are the same as
EDAC_MC_LABEL_LEN.  Since the snprintf()s in channel_dimm_label_show()
and dimmdev_label_show() limit the whole length by EDAC_MC_LABEL_LEN,
the newline in the format "%s\n" is ignored.

 [root@orange ~]# od -bc /sys/bus/mc0/devices/dimm0/dimm_label
 0000000 103 120 125 137 123 162 143 111 104 043 060 137 110 141 043 060
           C   P   U   _   S   r   c   I   D   #   0   _   H   a   #   0
 0000020 137 103 150 141 156 043 060 137 104 111 115 115 043 060 000
           _   C   h   a   n   #   0   _   D   I   M   M   #   0  \0
 0000037

Fix it by using 'sizeof(dimm->label) + 1' as the whole length in
the snprintf()s in channel_dimm_label_show() and dimmdev_label_show().

Reported-by: Robert Elliott <elliott@hpe.com>
Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Acked-by: Tony Luck <tony.luck@intel.com>
Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Doug Thompson <dougthompson@xmission.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Robert Elliott <elliott@hpe.com>
---
 drivers/edac/edac_mc_sysfs.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index 33df7d9..8983755 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -229,7 +229,7 @@ static ssize_t channel_dimm_label_show(struct device *dev,
 	if (!rank->dimm->label[0])
 		return 0;
 
-	return snprintf(data, EDAC_MC_LABEL_LEN, "%s\n",
+	return snprintf(data, sizeof(rank->dimm->label) + 1, "%s\n",
 			rank->dimm->label);
 }
 
@@ -485,7 +485,7 @@ static ssize_t dimmdev_label_show(struct device *dev,
 	if (!dimm->label[0])
 		return 0;
 
-	return snprintf(data, EDAC_MC_LABEL_LEN, "%s\n", dimm->label);
+	return snprintf(data, sizeof(dimm->label) + 1, "%s\n", dimm->label);
 }
 
 static ssize_t dimmdev_label_store(struct device *dev,

  reply	other threads:[~2015-09-22 15:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-22 14:58 [PATCH v2 0/2] EDAC: Fix sysfs dimm_label show & store operations Toshi Kani
2015-09-22 14:58 ` Toshi Kani [this message]
2015-09-22 14:58 ` [PATCH v2 2/2] EDAC: Fix sysfs dimm_label store operation Toshi Kani
2015-09-24 16:48   ` Borislav Petkov
2015-09-24 19:06     ` Toshi Kani
2015-09-24 19:15       ` Borislav Petkov
2015-09-24 19:59         ` Toshi Kani
2015-09-25 17:49           ` Borislav Petkov

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=1442933883-21587-2-git-send-email-toshi.kani@hpe.com \
    --to=toshi.kani@hpe.com \
    --cc=bp@alien8.de \
    --cc=dougthompson@xmission.com \
    --cc=elliott@hpe.com \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@osg.samsung.com \
    --cc=tony.luck@intel.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).