linux-xiaomi-chiron/drivers/net/wireless/broadcom/brcm80211/brcmfmac
Jason A. Donenfeld 81895a65ec treewide: use prandom_u32_max() when possible, part 1
Rather than incurring a division or requesting too many random bytes for
the given range, use the prandom_u32_max() function, which only takes
the minimum required bytes from the RNG and avoids divisions. This was
done mechanically with this coccinelle script:

@basic@
expression E;
type T;
identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
typedef u64;
@@
(
- ((T)get_random_u32() % (E))
+ prandom_u32_max(E)
|
- ((T)get_random_u32() & ((E) - 1))
+ prandom_u32_max(E * XXX_MAKE_SURE_E_IS_POW2)
|
- ((u64)(E) * get_random_u32() >> 32)
+ prandom_u32_max(E)
|
- ((T)get_random_u32() & ~PAGE_MASK)
+ prandom_u32_max(PAGE_SIZE)
)

@multi_line@
identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
identifier RAND;
expression E;
@@

-       RAND = get_random_u32();
        ... when != RAND
-       RAND %= (E);
+       RAND = prandom_u32_max(E);

// Find a potential literal
@literal_mask@
expression LITERAL;
type T;
identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
position p;
@@

        ((T)get_random_u32()@p & (LITERAL))

// Add one to the literal.
@script:python add_one@
literal << literal_mask.LITERAL;
RESULT;
@@

value = None
if literal.startswith('0x'):
        value = int(literal, 16)
elif literal[0] in '123456789':
        value = int(literal, 10)
if value is None:
        print("I don't know how to handle %s" % (literal))
        cocci.include_match(False)
elif value == 2**32 - 1 or value == 2**31 - 1 or value == 2**24 - 1 or value == 2**16 - 1 or value == 2**8 - 1:
        print("Skipping 0x%x for cleanup elsewhere" % (value))
        cocci.include_match(False)
elif value & (value + 1) != 0:
        print("Skipping 0x%x because it's not a power of two minus one" % (value))
        cocci.include_match(False)
elif literal.startswith('0x'):
        coccinelle.RESULT = cocci.make_expr("0x%x" % (value + 1))
else:
        coccinelle.RESULT = cocci.make_expr("%d" % (value + 1))

// Replace the literal mask with the calculated result.
@plus_one@
expression literal_mask.LITERAL;
position literal_mask.p;
expression add_one.RESULT;
identifier FUNC;
@@

-       (FUNC()@p & (LITERAL))
+       prandom_u32_max(RESULT)

@collapse_ret@
type T;
identifier VAR;
expression E;
@@

 {
-       T VAR;
-       VAR = (E);
-       return VAR;
+       return E;
 }

@drop_var@
type T;
identifier VAR;
@@

 {
-       T VAR;
        ... when != VAR
 }

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Yury Norov <yury.norov@gmail.com>
Reviewed-by: KP Singh <kpsingh@kernel.org>
Reviewed-by: Jan Kara <jack@suse.cz> # for ext4 and sbitmap
Reviewed-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com> # for drbd
Acked-by: Jakub Kicinski <kuba@kernel.org>
Acked-by: Heiko Carstens <hca@linux.ibm.com> # for s390
Acked-by: Ulf Hansson <ulf.hansson@linaro.org> # for mmc
Acked-by: Darrick J. Wong <djwong@kernel.org> # for xfs
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2022-10-11 17:42:55 -06:00
..
bcdc.c brcmfmac: increase dcmd maximum buffer size 2022-09-27 09:09:07 +03:00
bcdc.h
bcmsdh.c wifi: brcmfmac: add 43439 SDIO ids and initialization 2022-09-07 11:01:15 +03:00
btcoex.c
btcoex.h
bus.h wifi: brcmfmac: pcie/sdio/usb: Get CLM blob via standard firmware mechanism 2022-09-19 12:59:33 +03:00
cfg80211.c brcmfmac: Remove the call to "dtim_assoc" IOVAR 2022-09-27 09:09:07 +03:00
cfg80211.h brcmfmac: add support for CQM RSSI notifications 2021-02-09 09:57:02 +02:00
chip.c brcmfmac: Support 89459 pcie 2022-09-27 09:09:06 +03:00
chip.h brcmfmac: support chipsets with different core enumeration space 2021-08-21 18:49:05 +03:00
common.c wifi: brcmfmac: pcie/sdio/usb: Get CLM blob via standard firmware mechanism 2022-09-19 12:59:33 +03:00
common.h wifi: brcmfmac: of: Fetch Apple properties 2022-09-19 12:59:34 +03:00
commonring.c
commonring.h
core.c wifi: brcmfmac: fix use-after-free bug in brcmf_netdev_start_xmit() 2022-09-07 10:57:10 +03:00
core.h wireless: brcmfmac: Use netif_rx(). 2022-03-06 11:05:31 +00:00
debug.c
debug.h brcmfmac: Silence error messages about unsupported firmware features 2021-06-23 20:44:25 +03:00
dmi.c wifi: brcmfmac: Add DMI nvram filename quirk for Chuwi Hi8 Pro tablet 2022-09-07 10:58:46 +03:00
feature.c wifi: brcmfmac: add 43439 SDIO ids and initialization 2022-09-07 11:01:15 +03:00
feature.h
firmware.c wifi: brcmfmac: firmware: Allow platform to override macaddr 2022-09-19 12:59:34 +03:00
firmware.h wifi: brcmfmac: firmware: Support passing in multiple board_types 2022-09-19 12:59:33 +03:00
flowring.c wifi: brcmfmac: fix scheduling while atomic issue when deleting flowring 2022-08-10 08:47:22 +03:00
flowring.h
fweh.c brcmfmac: fweh: Add missing description for 'gfp' 2020-11-07 18:04:07 +02:00
fweh.h net: brcmfmac: Convey allocation mode as argument 2020-09-29 14:02:55 -07:00
fwil.c brcmfmac: fwil: Constify iovar name arguments 2022-02-01 14:27:07 +02:00
fwil.h brcmfmac: fwil: Constify iovar name arguments 2022-02-01 14:27:07 +02:00
fwil_types.h brcmfmac: increase default max WOWL patterns to 16 2022-09-27 09:09:06 +03:00
fwsignal.c wifi: move from strlcpy with unused retval to strscpy 2022-09-02 11:47:22 +03:00
fwsignal.h wifi: brcmfmac: Fix to add skb free for TIM update info when tx is completed 2022-08-10 08:47:22 +03:00
Kconfig
Makefile brcmfmac: add xtlv support to firmware interface layer 2021-08-21 18:49:04 +03:00
msgbuf.c wifi: brcmfmac: fix scheduling while atomic issue when deleting flowring 2022-08-10 08:47:22 +03:00
msgbuf.h wifi: brcmfmac: msgbuf: Increase RX ring sizes to 1024 2022-09-19 12:59:34 +03:00
of.c wifi: brcmfmac: of: Fetch Apple properties 2022-09-19 12:59:34 +03:00
of.h
p2p.c treewide: use prandom_u32_max() when possible, part 1 2022-10-11 17:42:55 -06:00
p2p.h
pcie.c brcmfmac: Support 89459 pcie 2022-09-27 09:09:06 +03:00
pcie.h brcmfmac: properly check for bus register errors 2021-05-13 18:58:42 +02:00
pno.c wifi: brcmfmac: fix invalid address access when enabling SCAN log level 2022-08-10 08:47:22 +03:00
pno.h
proto.c
proto.h wireless: brcmfmac: Use netif_rx(). 2022-03-06 11:05:31 +00:00
sdio.c wifi: brcmfmac: firmware: Support passing in multiple board_types 2022-09-19 12:59:33 +03:00
sdio.h wifi: brcmfmac: pcie/sdio/usb: Get CLM blob via standard firmware mechanism 2022-09-19 12:59:33 +03:00
tracepoint.c
tracepoint.h tracing/brcm: Use the new __vstring() helper 2022-07-15 17:44:40 -04:00
usb.c wifi: brcmfmac: pcie/sdio/usb: Get CLM blob via standard firmware mechanism 2022-09-19 12:59:33 +03:00
usb.h brcmfmac: A typo fix 2021-04-18 09:28:21 +03:00
vendor.c
vendor.h
xtlv.c include/linux/unaligned: replace kernel.h with the necessary inclusions 2022-01-20 08:52:53 +02:00
xtlv.h brcmfmac: Replace zero-length arrays with flexible-array members 2022-02-21 10:59:35 +02:00