Thread (37 messages) 37 messages, 4 authors, 2022-01-20

Re: [PATCH v3 7/9] brcmfmac: of: Use devm_kstrdup for board_type & check for errors

From: Andy Shevchenko <hidden>
Date: 2022-01-20 10:54:03
Also in: linux-acpi, linux-devicetree, linux-wireless, lkml

On Mon, Jan 17, 2022 at 4:31 PM Hector Martin [off-list ref] wrote:
This was missing a NULL check, and we can collapse the strlen/alloc/copy
into a devm_kstrdup().
Nice patch. After dropping the message,
Reviewed-by: Andy Shevchenko <redacted>
                /* 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) {
+                       brcmf_err("out of memory allocating board_type\n");
+                       of_node_put(root);
+                       return;
+               }
                for (i = 0; i < board_type[i]; i++) {
                        if (board_type[i] == '/')
                                board_type[i] = '-';
Next step is to replace this with NIH strreplace()

And
  of_property_read_string_index(root, "compatible", 0, &tmp);
with
  of_property_read_string(root, "compatible", &tmp);

And might add an error check, but I believe if there is no compatible
property present, this can't be called.

-- 
With Best Regards,
Andy Shevchenko
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help