From: Dafna Hirschfeld Date: Wed, 16 Mar 2022 17:45:24 +0000 (+0200) Subject: habanalabs: enforce alignment upon registers access through debugfs X-Git-Tag: v5.19-rc1~45^2~32 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=9248aa90d2fa0a03955f0813d17accde9e1f0751;p=linux-block.git habanalabs: enforce alignment upon registers access through debugfs 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 Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay Signed-off-by: Greg Kroah-Hartman --- 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);