Re: [PATCH v3 7/9] brcmfmac: of: Use devm_kstrdup for board_type & check for errors
From: Andy Shevchenko
Date: Thu Jan 20 2022 - 05:54:04 EST
On Mon, Jan 17, 2022 at 4:31 PM Hector Martin <marcan@xxxxxxxxx> 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 <andy.shevchenko@xxxxxxxxx>
> /* 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