From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Shravan Kumar Ramani <shravankr@nvidia.com>
Cc: Vadim Pasternak <vadimp@nvidia.com>,
David Thompson <davthompson@nvidia.com>,
platform-driver-x86@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
David Thompson <davthomspson@nvidia.com>
Subject: Re: [PATCH v3 1/2] platform/mellanox: mlxbf-pmc: Remove newline char from event name input
Date: Mon, 30 Jun 2025 16:44:37 +0300 (EEST) [thread overview]
Message-ID: <2b88f7a6-0b4b-9b0b-74c9-21af22f56898@linux.intel.com> (raw)
In-Reply-To: <cd2607b381630c0ae5ef7c86a4ab7e75c86d276c.1751286845.git.shravankr@nvidia.com>
On Mon, 30 Jun 2025, Shravan Kumar Ramani wrote:
> 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);
These shouldn't need any newline removal, right?
> 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);
You should cleanup the newline here, not inside mlxbf_pmc_get_event_num()
so that you can keep the argument type const.
As the input parameter is const char *, I suggest using
kstrdup_and_replace() so you can modify it.
In general, casting constness away is bad practice.
> if (evt_num < 0)
> return -EINVAL;
> } else {
>
--
i.
next prev parent reply other threads:[~2025-06-30 13:45 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 ` [PATCH v3 1/2] platform/mellanox: mlxbf-pmc: Remove newline char from event name input Shravan Kumar Ramani
2025-06-30 13:44 ` Ilpo Järvinen [this message]
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=2b88f7a6-0b4b-9b0b-74c9-21af22f56898@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=davthompson@nvidia.com \
--cc=davthomspson@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=shravankr@nvidia.com \
--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®