diff mbox series

[v4,2/5] lib: logic_pio: Avoid possible overlap for unregistering regions

Message ID 1564493396-92195-3-git-send-email-john.garry@huawei.com
State Accepted
Commit 0a27142bd1ee259e24a0be2b0133e5ca5df8da91
Headers show
Series Fixes for HiSilicon LPC driver and logical PIO code | expand

Commit Message

John Garry July 30, 2019, 1:29 p.m. UTC
The code was originally written to not support unregistering logical PIO
regions.

To accommodate supporting unregistering logical PIO regions, subtly modify
LOGIC_PIO_CPU_MMIO region registration code, such that the "end" of the
registered regions is the "end" of the last region, and not the sum of
the sizes of all the registered regions.

Cc: stable@vger.kernel.org
Signed-off-by: John Garry <john.garry@huawei.com>

---
 lib/logic_pio.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

-- 
2.17.1

Comments

John Garry Aug. 1, 2019, 1:42 p.m. UTC | #1
On 01/08/2019 14:31, Sasha Levin wrote:
> Hi,

>

> [This is an automated email]

>

> This commit has been processed because it contains a -stable tag.

> The stable tag indicates that it's relevant for the following trees: all

>

> The bot has tested the following trees: v5.2.4, v5.1.21, v4.19.62, v4.14.134, v4.9.186, v4.4.186.

>

> v5.2.4: Build OK!

> v5.1.21: Build OK!

> v4.19.62: Build OK!

> v4.14.134: Failed to apply! Possible dependencies:

>     031e3601869c ("lib: Add generic PIO mapping method")

>

> v4.9.186: Failed to apply! Possible dependencies:

>     031e3601869c ("lib: Add generic PIO mapping method")

>

> v4.4.186: Failed to apply! Possible dependencies:

>     031e3601869c ("lib: Add generic PIO mapping method")

>

>

> NOTE: The patch will not be queued to stable trees until it is upstream.

>

> How should we proceed with this patch?

>


Please only consider for v4.19.x, v5.1.x, and v5.2.x stable trees, same 
for all patches in the patchset.

Thanks,
John

> --

> Thanks,

> Sasha

>

> .

>
diff mbox series

Patch

diff --git a/lib/logic_pio.c b/lib/logic_pio.c
index 761296376fbc..d0165c88f705 100644
--- a/lib/logic_pio.c
+++ b/lib/logic_pio.c
@@ -35,7 +35,7 @@  int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
 	struct logic_pio_hwaddr *range;
 	resource_size_t start;
 	resource_size_t end;
-	resource_size_t mmio_sz = 0;
+	resource_size_t mmio_end = 0;
 	resource_size_t iio_sz = MMIO_UPPER_LIMIT;
 	int ret = 0;
 
@@ -56,7 +56,7 @@  int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
 			/* for MMIO ranges we need to check for overlap */
 			if (start >= range->hw_start + range->size ||
 			    end < range->hw_start) {
-				mmio_sz += range->size;
+				mmio_end = range->io_start + range->size;
 			} else {
 				ret = -EFAULT;
 				goto end_register;
@@ -69,16 +69,16 @@  int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
 
 	/* range not registered yet, check for available space */
 	if (new_range->flags == LOGIC_PIO_CPU_MMIO) {
-		if (mmio_sz + new_range->size - 1 > MMIO_UPPER_LIMIT) {
+		if (mmio_end + new_range->size - 1 > MMIO_UPPER_LIMIT) {
 			/* if it's too big check if 64K space can be reserved */
-			if (mmio_sz + SZ_64K - 1 > MMIO_UPPER_LIMIT) {
+			if (mmio_end + SZ_64K - 1 > MMIO_UPPER_LIMIT) {
 				ret = -E2BIG;
 				goto end_register;
 			}
 			new_range->size = SZ_64K;
 			pr_warn("Requested IO range too big, new size set to 64K\n");
 		}
-		new_range->io_start = mmio_sz;
+		new_range->io_start = mmio_end;
 	} else if (new_range->flags == LOGIC_PIO_INDIRECT) {
 		if (iio_sz + new_range->size - 1 > IO_SPACE_LIMIT) {
 			ret = -E2BIG;