From: Oded Gabbay <ogabbay@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Dafna Hirschfeld <dhirschfeld@habana.ai>
Subject: [PATCH 3/7] habanalabs: enforce alignment upon registers access through debugfs
Date: Fri, 1 Apr 2022 15:20:13 +0300 [thread overview]
Message-ID: <20220401122017.116205-3-ogabbay@kernel.org> (raw)
In-Reply-To: <20220401122017.116205-1-ogabbay@kernel.org>
From: Dafna Hirschfeld <dhirschfeld@habana.ai>
When accessing the configuration registers through debugfs,
it is only allowed to access aligned address.
Fail if address is not aligned.
Signed-off-by: Dafna Hirschfeld <dhirschfeld@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
---
drivers/misc/habanalabs/common/device.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/misc/habanalabs/common/device.c b/drivers/misc/habanalabs/common/device.c
index bd76a68d44be..9a71737fc804 100644
--- a/drivers/misc/habanalabs/common/device.c
+++ b/drivers/misc/habanalabs/common/device.c
@@ -94,6 +94,11 @@ int hl_access_cfg_region(struct hl_device *hdev, u64 addr, u64 *val,
struct pci_mem_region *cfg_region = &hdev->pci_mem_region[PCI_REGION_CFG];
u32 val_h, val_l;
+ if (!IS_ALIGNED(addr, sizeof(u32))) {
+ dev_err(hdev->dev, "address %#llx not a multiple of %zu\n", addr, sizeof(u32));
+ return -EINVAL;
+ }
+
switch (acc_type) {
case DEBUGFS_READ32:
*val = RREG32(addr - cfg_region->region_base);
--
2.25.1
next prev parent reply other threads:[~2022-04-01 12:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-01 12:20 [PATCH 1/7] habanalabs: add callback and field to be used for debugfs refactor Oded Gabbay
2022-04-01 12:20 ` [PATCH 2/7] habanalabs: unify code for memory access from debugfs Oded Gabbay
2022-04-01 12:20 ` Oded Gabbay [this message]
2022-04-01 12:20 ` [PATCH 4/7] habanalabs: remove debugfs read/write callbacks Oded Gabbay
2022-04-01 12:20 ` [PATCH 5/7] habanalabs: wrong handle removal in memory manager Oded Gabbay
2022-04-01 12:20 ` [PATCH 6/7] habanalabs: remove redundant info print Oded Gabbay
2022-04-01 12:20 ` [PATCH 7/7] habanalabs: change a reset print to debug level Oded Gabbay
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=20220401122017.116205-3-ogabbay@kernel.org \
--to=ogabbay@kernel.org \
--cc=dhirschfeld@habana.ai \
--cc=linux-kernel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.