diff mbox series

[v4,7/9] brcmfmac: of: Use devm_kstrdup for board_type & check for errors

Message ID 20220131160713.245637-8-marcan@marcan.st (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series misc brcmfmac fixes (M1/T2 series spin-off) | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Hector Martin Jan. 31, 2022, 4:07 p.m. UTC
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>
---
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Piotr Masłowski Jan. 31, 2022, 10:33 p.m. UTC | #1
On Mon, Jan 31, 2022 at 5:07 PM Hector Martin <marcan@marcan.st> wrote:
>
>This was missing a NULL check, and we can collapse the strlen/alloc/copy
>into a devm_kstrdup().

...
 
> 		/* 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);

Also `len` can be dropped, since it is now unused.

--
Best regards,
Piotr Masłowski
diff mbox series

Patch

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
index 513c7e6421b2..5708de1d9f26 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
@@ -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] = '-';