From 571c3496e3c20444d5a2a5d4c00e608f26339505 Mon Sep 17 00:00:00 2001 From: Sinthu Raja Date: Mon, 20 Sep 2021 18:01:52 +0530 Subject: [PATCH 1/3] dt-bindings: hwlock: omap: Remove redundant binding example The example includes a board-specific compatible property, this is wrong as the example should be board agnostic and should represent the particular binding. Also, the file includes two similar examples but with a different compatible. So, drop the entire second example Suggested-by: Bjorn Andersson Signed-off-by: Sinthu Raja Reviewed-by: Rob Herring Acked-by: Suman Anna Signed-off-by: Bjorn Andersson Link: https://lore.kernel.org/r/20210920123152.32751-1-sinthu.raja@ti.com --- .../bindings/hwlock/ti,omap-hwspinlock.yaml | 33 +------------------ 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/Documentation/devicetree/bindings/hwlock/ti,omap-hwspinlock.yaml b/Documentation/devicetree/bindings/hwlock/ti,omap-hwspinlock.yaml index ae1b37dbee75..0a955c7b9706 100644 --- a/Documentation/devicetree/bindings/hwlock/ti,omap-hwspinlock.yaml +++ b/Documentation/devicetree/bindings/hwlock/ti,omap-hwspinlock.yaml @@ -39,39 +39,8 @@ additionalProperties: false examples: - | - /* OMAP4 SoCs */ - hwspinlock: spinlock@4a0f6000 { + spinlock@4a0f6000 { compatible = "ti,omap4-hwspinlock"; reg = <0x4a0f6000 0x1000>; #hwlock-cells = <1>; }; - - - | - / { - /* K3 AM65x SoCs */ - model = "Texas Instruments K3 AM654 SoC"; - compatible = "ti,am654-evm", "ti,am654"; - #address-cells = <2>; - #size-cells = <2>; - - bus@100000 { - compatible = "simple-bus"; - #address-cells = <2>; - #size-cells = <2>; - ranges = <0x00 0x00100000 0x00 0x00100000 0x00 0x00020000>, /* ctrl mmr */ - <0x00 0x30800000 0x00 0x30800000 0x00 0x0bc00000>; /* Main NavSS */ - - bus@30800000 { - compatible = "simple-mfd"; - #address-cells = <2>; - #size-cells = <2>; - ranges = <0x00 0x30800000 0x00 0x30800000 0x00 0x0bc00000>; - - spinlock@30e00000 { - compatible = "ti,am654-hwspinlock"; - reg = <0x00 0x30e00000 0x00 0x1000>; - #hwlock-cells = <1>; - }; - }; - }; - }; From 3e5f1ff7e4f297b928fb579fa1e8ec65a400162e Mon Sep 17 00:00:00 2001 From: "Gustavo A. R. Silva" Date: Mon, 24 Jan 2022 20:13:53 -0600 Subject: [PATCH 2/3] hwspinlock: stm32: Use struct_size() helper in devm_kzalloc() Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Also, address the following sparse warnings: drivers/hwspinlock/stm32_hwspinlock.c:84:32: warning: using sizeof on a flexible structure Link: https://github.com/KSPP/linux/issues/174 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Baolin Wang Signed-off-by: Bjorn Andersson Link: https://lore.kernel.org/r/20220125021353.GA29777@embeddedor --- drivers/hwspinlock/stm32_hwspinlock.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/hwspinlock/stm32_hwspinlock.c b/drivers/hwspinlock/stm32_hwspinlock.c index 5bd11a7fab65..bb5c7e5f7a80 100644 --- a/drivers/hwspinlock/stm32_hwspinlock.c +++ b/drivers/hwspinlock/stm32_hwspinlock.c @@ -73,15 +73,13 @@ static int stm32_hwspinlock_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct stm32_hwspinlock *hw; void __iomem *io_base; - size_t array_size; int i, ret; io_base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(io_base)) return PTR_ERR(io_base); - array_size = STM32_MUTEX_NUM_LOCKS * sizeof(struct hwspinlock); - hw = devm_kzalloc(dev, sizeof(*hw) + array_size, GFP_KERNEL); + hw = devm_kzalloc(dev, struct_size(hw, bank.lock, STM32_MUTEX_NUM_LOCKS), GFP_KERNEL); if (!hw) return -ENOMEM; From 9a41358972eb35e6e45327035a67adfa4a223ed2 Mon Sep 17 00:00:00 2001 From: "Gustavo A. R. Silva" Date: Tue, 25 Jan 2022 16:57:23 -0600 Subject: [PATCH 3/3] hwspinlock: sprd: Use struct_size() helper in devm_kzalloc() Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Also, address the following sparse warnings: drivers/hwspinlock/sprd_hwspinlock.c:96:36: warning: using sizeof on a flexible structure Link: https://github.com/KSPP/linux/issues/174 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Baolin Wang Signed-off-by: Bjorn Andersson Link: https://lore.kernel.org/r/20220125225723.GA78256@embeddedor --- drivers/hwspinlock/sprd_hwspinlock.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/hwspinlock/sprd_hwspinlock.c b/drivers/hwspinlock/sprd_hwspinlock.c index d221fc9d756d..22e2ffb91743 100644 --- a/drivers/hwspinlock/sprd_hwspinlock.c +++ b/drivers/hwspinlock/sprd_hwspinlock.c @@ -93,8 +93,7 @@ static int sprd_hwspinlock_probe(struct platform_device *pdev) return -ENODEV; sprd_hwlock = devm_kzalloc(&pdev->dev, - sizeof(struct sprd_hwspinlock_dev) + - SPRD_HWLOCKS_NUM * sizeof(*lock), + struct_size(sprd_hwlock, bank.lock, SPRD_HWLOCKS_NUM), GFP_KERNEL); if (!sprd_hwlock) return -ENOMEM;