u-boot/arch/arm
Grygorii Strashko 218ac107c5 arm: bitops: fix find_next_zero_bit() for case size < 32
find_next_zero_bit() incorrectly handles cases when:
- total bitmap size < 32
- rest of bits to process

static inline int find_next_zero_bit(void *addr, int size, int offset)
{
	unsigned long *p = ((unsigned long *)addr) + (offset >> 5);
	unsigned long result = offset & ~31UL;
	unsigned long tmp;

	if (offset >= size)
		return size;
	size -= result;
	offset &= 31UL;
	if (offset) {
		tmp = *(p++);
		tmp |= ~0UL >> (32-offset);
		if (size < 32)
[1]
			goto found_first;
		if (~tmp)
			goto found_middle;
		size -= 32;
		result += 32;
	}
	while (size & ~31UL) {
		tmp = *(p++);
		if (~tmp)
			goto found_middle;
		result += 32;
		size -= 32;
	}
[2]
	if (!size)
		return result;
	tmp = *p;

found_first:
[3]  tmp |= ~0UL >> size;

^^^ algo can reach above line from from points:
 [1] offset > 0 and size < 32, tmp[offset-1..0] bits set to 1
 [2] size < 32 - rest of bits to process
 in both cases bits to search are tmp[size-1..0], but line [3] will simply
 set all tmp[31-size..0] bits to 1 and ffz(tmp) below will fail.

example: bitmap size = 16, offset = 0, bitmap is empty.
 code will go through the point [2], tmp = 0x0
 after line [3] => tmp = 0xFFFF and ffz(tmp) will return 16.

found_middle:
	return result + ffz(tmp);
}

Fix it by correctly seting tmp[31..size] bits to 1 in the above case [3].

Fixes: 81e9fe5a29 ("arm: implement find_next_zero_bit function")
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
2018-05-08 18:50:23 -04:00
..
cpu arm: v7R: Add support for enabling caches 2018-05-07 15:53:29 -04:00
dts db410c: set clk node to be probed before relocation 2018-05-08 18:50:22 -04:00
include arm: bitops: fix find_next_zero_bit() for case size < 32 2018-05-08 18:50:23 -04:00
lib arm: v7R: Add support for enabling caches 2018-05-07 15:53:29 -04:00
mach-aspeed regmap: change regmap_init_mem() to take ofnode instead udevice 2018-05-07 15:49:51 -04:00
mach-at91 gpio: atmel_pio4: give a full configuration when muxing pins 2018-05-08 09:07:36 -04:00
mach-bcm283x arm: v7: Kconfig: Rename CPU_V7 as CPU_V7A 2018-05-07 15:53:24 -04:00
mach-davinci SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
mach-exynos arm: v7: Kconfig: Rename CPU_V7 as CPU_V7A 2018-05-07 15:53:24 -04:00
mach-highbank SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
mach-imx imx7: psci: save context id in cpu_on command 2018-05-07 11:52:55 -04:00
mach-integrator env: Convert CONFIG_ENV_IS_IN... to a choice 2017-08-15 20:50:01 -04:00
mach-keystone SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
mach-kirkwood SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
mach-meson ARM: meson: rename GXBB to GX 2018-05-08 09:07:34 -04:00
mach-mvebu arm: v7: Kconfig: Rename CPU_V7 as CPU_V7A 2018-05-07 15:53:24 -04:00
mach-omap2 arm: dra76: fastboot: extend cpu type for getvar command 2018-05-08 09:07:37 -04:00
mach-orion5x SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
mach-qemu arm: v7: Kconfig: Rename CPU_V7 as CPU_V7A 2018-05-07 15:53:24 -04:00
mach-rmobile arm: v7: Kconfig: Rename CPU_V7 as CPU_V7A 2018-05-07 15:53:24 -04:00
mach-rockchip arm: v7: Kconfig: Rename CPU_V7 as CPU_V7A 2018-05-07 15:53:24 -04:00
mach-s5pc1xx SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
mach-snapdragon SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
mach-socfpga SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
mach-sti board: Add STMicroelectronics STiH410-B2260 support 2017-03-14 20:40:21 -04:00
mach-stm32 arm: v7R: Add support for MPU 2018-05-07 15:53:29 -04:00
mach-stm32mp stm32mp: regulator: add SoC pwr regulator support 2018-05-08 09:07:38 -04:00
mach-sunxi arm: v7: Kconfig: Rename CPU_V7 as CPU_V7A 2018-05-07 15:53:24 -04:00
mach-tegra arm: v7: Kconfig: Rename CPU_V7 as CPU_V7A 2018-05-07 15:53:24 -04:00
mach-uniphier arm: v7: Kconfig: Rename CPU_V7 as CPU_V7A 2018-05-07 15:53:24 -04:00
mach-versatile SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
mach-zynq SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
thumb1/include/asm/proc-armv arm: support Thumb-1 with CONFIG_SYS_THUMB_BUILD 2015-11-10 15:03:48 +01:00
config.mk SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
Kconfig arm: v7R: Add support for MPU 2018-05-07 15:53:29 -04:00
Kconfig.debug
Makefile arm: v7R: Add initial support 2018-05-07 15:53:28 -04:00