brcmfmac: of: Use devm_kstrdup for board_type & check for errors
authorHector Martin <marcan@marcan.st>
Mon, 31 Jan 2022 16:07:11 +0000 (01:07 +0900)
committerKalle Valo <kvalo@kernel.org>
Tue, 1 Feb 2022 12:27:07 +0000 (14:27 +0200)
This was missing a NULL check, and we can collapse the strlen/alloc/copy
into a devm_kstrdup().

Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20220131160713.245637-8-marcan@marcan.st
drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c

index 513c7e6..5708de1 100644 (file)
@@ -79,8 +79,11 @@ void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
 
                /* 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);
+               board_type = devm_kstrdup(dev, tmp, GFP_KERNEL);
+               if (!board_type) {
+                       of_node_put(root);
+                       return;
+               }
                for (i = 0; i < board_type[i]; i++) {
                        if (board_type[i] == '/')
                                board_type[i] = '-';