2020-12-14 00:12:11

by Syed Nayyar Waris

[permalink] [raw]
Subject: [PATCH v2 0/2] Modify bitmap_set_value() to suppress compiler warning

Hi All,

The purpose of this patchset is to suppress the compiler warning (-Wtype-limits).

In function bitmap_set_value(), add explicit check to see if the value being
written into the bitmap does not fall outside the bitmap.
The situation that it is falling outside is never possible in the code
because the boundaries are required to be correct before the function is
called. The responsibility is on the caller for ensuring the boundaries
are correct.
The code change is simply to silence the GCC warning messages
because GCC is not aware that the boundaries have already been checked.
As such, we're better off using __builtin_unreachable() here because we
can avoid the latency of the conditional check entirely.

Michal,
What do you think of [PATCH 2/2]? Is the conditional check needed, and also does
returning -EINVAL look good?

Changes in v2:
- [Patch 1/2]: Squashed earlier three patches into one.

Syed Nayyar Waris (2):
bitmap: Modify bitmap_set_value() to check bitmap length
gpio: xilinx: Add extra check if sum of widths exceed 64

drivers/gpio/gpio-xilinx.c | 18 ++++++++++++------
include/linux/bitmap.h | 35 +++++++++++++++++++++--------------
lib/test_bitmap.c | 4 ++--
3 files changed, 35 insertions(+), 22 deletions(-)


base-commit: b640c4e12bbe1f0b6383c3ef788a89e5427c763f
--
2.29.0


2020-12-14 00:12:21

by Syed Nayyar Waris

[permalink] [raw]
Subject: [PATCH v2 2/2] gpio: xilinx: Add extra check if sum of widths exceed 64

Add extra check to see if sum of widths does not exceed 64. If it
exceeds then return -EINVAL alongwith appropriate error message.

Cc: Michal Simek <[email protected]>
Signed-off-by: Syed Nayyar Waris <[email protected]>
---
drivers/gpio/gpio-xilinx.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
index 05dae086c4d0..a2e92a1cf50b 100644
--- a/drivers/gpio/gpio-xilinx.c
+++ b/drivers/gpio/gpio-xilinx.c
@@ -340,6 +340,12 @@ static int xgpio_probe(struct platform_device *pdev)

chip->gc.base = -1;
chip->gc.ngpio = chip->gpio_width[0] + chip->gpio_width[1];
+
+ if (chip->gc.ngpio > 64) {
+ dev_err(&pdev->dev, "invalid configuration: number of GPIO is greater than 64");
+ return -EINVAL;
+ }
+
chip->gc.parent = &pdev->dev;
chip->gc.direction_input = xgpio_dir_in;
chip->gc.direction_output = xgpio_dir_out;
--
2.29.0