mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shravan Kumar Ramani <shravankr@nvidia.com>
To: Ilpo Jarvinen <ilpo.jarvinen@linux.intel.com>,
	Vadim Pasternak <vadimp@nvidia.com>,
	David Thompson <davthompson@nvidia.com>
Cc: Shravan Kumar Ramani <shravankr@nvidia.com>,
	<platform-driver-x86@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	"David Thompson" <davthomspson@nvidia.com>
Subject: [PATCH v3 1/2] platform/mellanox: mlxbf-pmc: Remove newline char from event name input
Date: Mon, 30 Jun 2025 09:26:56 -0400	[thread overview]
Message-ID: <cd2607b381630c0ae5ef7c86a4ab7e75c86d276c.1751286845.git.shravankr@nvidia.com> (raw)
In-Reply-To: <cover.1751286845.git.shravankr@nvidia.com>

Since the input string passed via the command line appends a newline char,
it needs to be removed before comparison with the event_list.

Fixes: 1a218d312e65 ("platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver")
Signed-off-by: Shravan Kumar Ramani <shravankr@nvidia.com>
Reviewed-by: David Thompson <davthomspson@nvidia.com>
---
 drivers/platform/mellanox/mlxbf-pmc.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/mellanox/mlxbf-pmc.c b/drivers/platform/mellanox/mlxbf-pmc.c
index 900069eb186e..16cc909aecab 100644
--- a/drivers/platform/mellanox/mlxbf-pmc.c
+++ b/drivers/platform/mellanox/mlxbf-pmc.c
@@ -1204,9 +1204,10 @@ static bool mlxbf_pmc_event_supported(const char *blk)
 }
 
 /* Get the event number given the name */
-static int mlxbf_pmc_get_event_num(const char *blk, const char *evt)
+static int mlxbf_pmc_get_event_num(const char *blk, char *evt)
 {
 	const struct mlxbf_pmc_events *events;
+	int len = strlen(evt);
 	unsigned int i;
 	size_t size;
 
@@ -1214,6 +1215,10 @@ static int mlxbf_pmc_get_event_num(const char *blk, const char *evt)
 	if (!events)
 		return -EINVAL;
 
+	/* Remove the trailing newline character if present */
+	if (evt[len - 1] == '\n')
+		evt[len - 1] = '\0';
+
 	for (i = 0; i < size; ++i) {
 		if (!strcmp(evt, events[i].evt_name))
 			return events[i].evt_num;
@@ -1681,7 +1686,7 @@ static ssize_t mlxbf_pmc_counter_show(struct device *dev,
 			return -EINVAL;
 	} else if (pmc->block[blk_num].type == MLXBF_PMC_TYPE_REGISTER) {
 		offset = mlxbf_pmc_get_event_num(pmc->block_name[blk_num],
-						 attr->attr.name);
+						 (char *)attr->attr.name);
 		if (offset < 0)
 			return -EINVAL;
 		if (mlxbf_pmc_read_reg(blk_num, offset, &value))
@@ -1730,7 +1735,7 @@ static ssize_t mlxbf_pmc_counter_store(struct device *dev,
 			return err;
 	} else if (pmc->block[blk_num].type == MLXBF_PMC_TYPE_REGISTER) {
 		offset = mlxbf_pmc_get_event_num(pmc->block_name[blk_num],
-						 attr->attr.name);
+						 (char *)attr->attr.name);
 		if (offset < 0)
 			return -EINVAL;
 		err = mlxbf_pmc_write_reg(blk_num, offset, data);
@@ -1792,7 +1797,7 @@ static ssize_t mlxbf_pmc_event_store(struct device *dev,
 
 	if (isalpha(buf[0])) {
 		evt_num = mlxbf_pmc_get_event_num(pmc->block_name[blk_num],
-						  buf);
+						  (char *)buf);
 		if (evt_num < 0)
 			return -EINVAL;
 	} else {
-- 
2.43.2


  reply	other threads:[~2025-06-30 13:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-30 13:26 [PATCH v3 0/2] Fixes to mlxbf-pmc Shravan Kumar Ramani
2025-06-30 13:26 ` Shravan Kumar Ramani [this message]
2025-06-30 13:44   ` [PATCH v3 1/2] platform/mellanox: mlxbf-pmc: Remove newline char from event name input Ilpo Järvinen
2025-06-30 13:26 ` [PATCH v3 2/2] platform/mellanox: mlxbf-pmc: Validate event/enable input Shravan Kumar Ramani

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=cd2607b381630c0ae5ef7c86a4ab7e75c86d276c.1751286845.git.shravankr@nvidia.com \
    --to=shravankr@nvidia.com \
    --cc=davthompson@nvidia.com \
    --cc=davthomspson@nvidia.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=vadimp@nvidia.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

all inboxes | Powered by JetHome®