From: Dan Carpenter <dan.carpenter@oracle.com> To: Arend van Spriel <aspriel@gmail.com>, Matthias Brugger <mbrugger@suse.com>, Christophe JAILLET <christophe.jaillet@wanadoo.fr> Cc: Franky Lin <franky.lin@broadcom.com>, Hante Meuleman <hante.meuleman@broadcom.com>, Chi-hsien Lin <chi-hsien.lin@infineon.com>, Wright Feng <wright.feng@infineon.com>, Chung-hsien Hsu <chung-hsien.hsu@infineon.com>, Kalle Valo <kvalo@codeaurora.org>, Hans deGoede <hdegoede@redhat.com>, linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com, SHA-cyfmac-dev-list@infineon.com, kernel-janitors@vger.kernel.org Subject: [PATCH v2] brcmfmac: fix "board_type" in brcmf_of_probe() Date: Mon, 21 Jun 2021 15:33:20 +0300 [thread overview] Message-ID: <YNCHELb14+eNV94n@mwanda> (raw) 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 <christophe.jaillet@wanadoo.fr> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> --- 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
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com> To: Arend van Spriel <aspriel@gmail.com>, Matthias Brugger <mbrugger@suse.com>, Christophe JAILLET <christophe.jaillet@wanadoo.fr> Cc: Franky Lin <franky.lin@broadcom.com>, Hante Meuleman <hante.meuleman@broadcom.com>, Chi-hsien Lin <chi-hsien.lin@infineon.com>, Wright Feng <wright.feng@infineon.com>, Chung-hsien Hsu <chung-hsien.hsu@infineon.com>, Kalle Valo <kvalo@codeaurora.org>, Hans deGoede <hdegoede@redhat.com>, linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com, SHA-cyfmac-dev-list@infineon.com, kernel-janitors@vger.kernel.org Subject: [PATCH v3] brcmfmac: fix "board_type" in brcmf_of_probe() Date: Tue, 22 Jun 2021 13:46:55 +0300 [thread overview] Message-ID: <YNCHELb14+eNV94n@mwanda> (raw) Message-ID: <20210622104655.OEWfv9gepGOtFiyWFxUHr_AgsKNkl4vMbJ6tB1_SWzs@z> (raw) 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 <christophe.jaillet@wanadoo.fr> Reported-by: Hans deGoede <hdegoede@redhat.com> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> --- v2: Basically a completely different patch. :) v3: Add missing of_node_put() caught by Hans de Goede .../net/wireless/broadcom/brcm80211/brcmfmac/of.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c index a7554265f95f..dee3d968e49b 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c @@ -24,20 +24,18 @@ 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) { + of_node_put(root); + return; } + strreplace(board_type, '/', '-'); settings->board_type = board_type; of_node_put(root); -- 2.30.2
next reply other threads:[~2021-06-21 12:33 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-21 12:33 Dan Carpenter [this message] 2021-06-22 10:46 ` [PATCH v3] brcmfmac: fix "board_type" in brcmf_of_probe() Dan Carpenter 2021-06-21 12:41 ` [PATCH v2] " Hans de Goede 2021-06-21 12:47 ` Dan Carpenter 2021-06-22 10:48 ` [PATCH v3] " Hans de Goede 2021-06-22 10:56 ` Matthias Brugger 2021-09-08 13:12 ` Dan Carpenter 2021-09-09 9:42 ` Kalle Valo
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=YNCHELb14+eNV94n@mwanda \ --to=dan.carpenter@oracle.com \ --cc=SHA-cyfmac-dev-list@infineon.com \ --cc=aspriel@gmail.com \ --cc=brcm80211-dev-list.pdl@broadcom.com \ --cc=chi-hsien.lin@infineon.com \ --cc=christophe.jaillet@wanadoo.fr \ --cc=chung-hsien.hsu@infineon.com \ --cc=franky.lin@broadcom.com \ --cc=hante.meuleman@broadcom.com \ --cc=hdegoede@redhat.com \ --cc=kernel-janitors@vger.kernel.org \ --cc=kvalo@codeaurora.org \ --cc=linux-wireless@vger.kernel.org \ --cc=mbrugger@suse.com \ --cc=wright.feng@infineon.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.