From: Shannon Nelson <shannon.nelson@amd.com>
To: <andrew+netdev@lunn.ch>, <brett.creeley@amd.com>,
<davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<pabeni@redhat.com>, <michal.swiatkowski@linux.intel.com>,
<horms@kernel.org>, <linux-kernel@vger.kernel.org>,
<netdev@vger.kernel.org>
Cc: Shannon Nelson <shannon.nelson@amd.com>
Subject: [PATCH v2 net 3/5] pds_core: handle unsupported PDS_CORE_CMD_FW_CONTROL result
Date: Thu, 10 Apr 2025 17:32:07 -0700 [thread overview]
Message-ID: <20250411003209.44053-4-shannon.nelson@amd.com> (raw)
In-Reply-To: <20250411003209.44053-1-shannon.nelson@amd.com>
From: Brett Creeley <brett.creeley@amd.com>
If the FW doesn't support the PDS_CORE_CMD_FW_CONTROL command
the driver might at the least print garbage and at the worst
crash when the user runs the "devlink dev info" devlink command.
This happens because the stack variable fw_list is not 0
initialized which results in fw_list.num_fw_slots being a
garbage value from the stack. Then the driver tries to access
fw_list.fw_names[i] with i >= ARRAY_SIZE and runs off the end
of the array.
Fix this by initializing the fw_list and by not failing
completely if the devcmd fails because other useful information
is printed via devlink dev info even if the devcmd fails.
Fixes: 45d76f492938 ("pds_core: set up device and adminq")
Signed-off-by: Brett Creeley <brett.creeley@amd.com>
Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
---
drivers/net/ethernet/amd/pds_core/devlink.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/amd/pds_core/devlink.c b/drivers/net/ethernet/amd/pds_core/devlink.c
index c5c787df61a4..d8dc39da4161 100644
--- a/drivers/net/ethernet/amd/pds_core/devlink.c
+++ b/drivers/net/ethernet/amd/pds_core/devlink.c
@@ -105,7 +105,7 @@ int pdsc_dl_info_get(struct devlink *dl, struct devlink_info_req *req,
.fw_control.opcode = PDS_CORE_CMD_FW_CONTROL,
.fw_control.oper = PDS_CORE_FW_GET_LIST,
};
- struct pds_core_fw_list_info fw_list;
+ struct pds_core_fw_list_info fw_list = {};
struct pdsc *pdsc = devlink_priv(dl);
union pds_core_dev_comp comp;
char buf[32];
@@ -118,8 +118,6 @@ int pdsc_dl_info_get(struct devlink *dl, struct devlink_info_req *req,
if (!err)
memcpy_fromio(&fw_list, pdsc->cmd_regs->data, sizeof(fw_list));
mutex_unlock(&pdsc->devcmd_lock);
- if (err && err != -EIO)
- return err;
listlen = min(fw_list.num_fw_slots, ARRAY_SIZE(fw_list.fw_names));
for (i = 0; i < listlen; i++) {
--
2.17.1
next prev parent reply other threads:[~2025-04-11 0:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-11 0:32 [PATCH v2 net 0/5] pds_core: updates and fixes Shannon Nelson
2025-04-11 0:32 ` [PATCH v2 net 1/5] pds_core: Prevent possible adminq overflow/stuck condition Shannon Nelson
2025-04-11 18:59 ` Simon Horman
2025-04-11 0:32 ` [PATCH v2 net 2/5] pds_core: remove extra name description Shannon Nelson
2025-04-15 0:36 ` Jakub Kicinski
2025-04-15 23:15 ` Nelson, Shannon
2025-04-11 0:32 ` Shannon Nelson [this message]
2025-04-11 19:00 ` [PATCH v2 net 3/5] pds_core: handle unsupported PDS_CORE_CMD_FW_CONTROL result Simon Horman
2025-04-11 0:32 ` [PATCH v2 net 4/5] pds_core: Remove unnecessary check in pds_client_adminq_cmd() Shannon Nelson
2025-04-11 0:32 ` [PATCH v2 net 5/5] pds_core: make wait_context part of q_info Shannon Nelson
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=20250411003209.44053-4-shannon.nelson@amd.com \
--to=shannon.nelson@amd.com \
--cc=andrew+netdev@lunn.ch \
--cc=brett.creeley@amd.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.swiatkowski@linux.intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@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 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).