Thread (7 messages) 7 messages, 4 authors, 2021-09-09
STALE1742d

[PATCH v2] brcmfmac: fix "board_type" in brcmf_of_probe()

From: Dan Carpenter <hidden>
Date: 2021-06-21 12:33:46
Also in: kernel-janitors
Subsystem: broadcom brcm80211 ieee802.11 wireless drivers, the rest · Maintainers: Arend van Spriel, Linus Torvalds

There are two bugs here:
1) devm_kzalloc() needs to be checked for allocation errors.
2) The loop was intended to be:

 Bad:	for (i = 0; i < board_type[i]; i++) {
Good:	for (i = 0; i < len; i++) {

Neither of these bugs are likely to cause an issue in practice but
they're worth fixing.  Also the code could be made simpler by using the
devm_kstrdup() and strreplace() functions.

Fixes: 29e354ebeeec ("brcmfmac: Transform compatible string for FW loading")
Suggested-by: Johannes Berg <johannes@sipsolutions.net>
Suggested-by: Christophe JAILLET <redacted>
Signed-off-by: Dan Carpenter <redacted>
---
v2: Basically a completely different patch.  :)

 .../net/wireless/broadcom/brcm80211/brcmfmac/of.c    | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
index a7554265f95f..8ca62cd0e8ac 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
@@ -24,20 +24,16 @@ void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
 	/* Set board-type to the first string of the machine compatible prop */
 	root = of_find_node_by_path("/");
 	if (root) {
-		int i, len;
 		char *board_type;
 		const char *tmp;
 
 		of_property_read_string_index(root, "compatible", 0, &tmp);
 
 		/* get rid of '/' in the compatible string to be able to find the FW */
-		len = strlen(tmp) + 1;
-		board_type = devm_kzalloc(dev, len, GFP_KERNEL);
-		strscpy(board_type, tmp, len);
-		for (i = 0; i < board_type[i]; i++) {
-			if (board_type[i] == '/')
-				board_type[i] = '-';
-		}
+		board_type = devm_kstrdup(dev, tmp, GFP_KERNEL);
+		if (!board_type)
+			return;
+		strreplace(board_type, '/', '-');
 		settings->board_type = board_type;
 
 		of_node_put(root);
-- 
2.30.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help