brcmfmac: fix "board_type" in brcmf_of_probe()
PATCH v2 1/1 brcmfmac: fix "board_type" in brcmf_of_probe()
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.
---
v2: Basically a completely different patch. :)
.../net/wireless/broadcom/brcm80211/brcmfmac/of.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +4 -8
@@ -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);
Signature · 1 line
2.30.2
Hi,
Quoted 36 lines · Dan Carpenter
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()andstrreplace()functions.Fixes 29e354ebeeec ("brcmfmac: Transform compatible string for FW loading")Suggested-by Johannes Berg <[email protected]>Suggested-by Christophe JAILLET <[email protected]>Signed-off-by Dan Carpenter <[email protected]>---
v2: Basically a completely different patch. :).../net/wireless/broadcom/brcm80211/brcmfmac/of.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +0
-1@@ -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 */
drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type, · line 35
Quoted 10 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +3
-7- 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 ;
The error handling here seems to be lacking, specifically this error-exit path needs a of_node_put(root); call (or a "goto put;" or some such)
Regards,
Hans
Quoted 5 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +1
-0+strreplace (board_type,'/' ,'-' ); settings->board_type = board_type;of_node_put (root);
Quoted 38 lines · Hans de Goede
Hi,
Quoted 35 lines · Dan Carpenter
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()andstrreplace()functions.Fixes 29e354ebeeec ("brcmfmac: Transform compatible string for FW loading")Suggested-by Johannes Berg <[email protected]>Suggested-by Christophe JAILLET <[email protected]>Signed-off-by Dan Carpenter <[email protected]>---
v2: Basically a completely different patch. :).../net/wireless/broadcom/brcm80211/brcmfmac/of.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +0
-1@@ -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);
Quoted 15 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type, · line 35
Quoted 11 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +3
-7/* 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 ;The error handling here seems to be lacking, specifically this error-exit path needs a
of_node_put(root); call (or a "goto put;" or some such)
Good catch. I will add a call to of_node_put().
regards,
dan carpenter
Hi,
Quoted 11 lines · Dan Carpenter
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()andstrreplace()functions.
Quoted 5 lines
Fixes 29e354ebeeec ("brcmfmac: Transform compatible string for FW loading")Suggested-by Johannes Berg <[email protected]>Suggested-by Christophe JAILLET <[email protected]>Reported-by Hans deGoede <[email protected]>Signed-off-by Dan Carpenter <[email protected]>
Thanks, patch looks good to me:
Regards,
Hans
Quoted 38 lines
---
v2: Basically a completely different patch. :)
v3: Add missingof_node_put()caught by Hans de Goede.../net/wireless/broadcom/brcm80211/brcmfmac/of.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +5
-7@@ -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);
Quoted 11 lines · Dan Carpenter
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()andstrreplace()functions.
Quoted 5 lines
Fixes 29e354ebeeec ("brcmfmac: Transform compatible string for FW loading")Suggested-by Johannes Berg <[email protected]>Suggested-by Christophe JAILLET <[email protected]>Reported-by Hans deGoede <[email protected]>Signed-off-by Dan Carpenter <[email protected]>
Thanks for taking care of this.
Quoted 38 lines
---
v2: Basically a completely different patch. :)
v3: Add missingof_node_put()caught by Hans de Goede.../net/wireless/broadcom/brcm80211/brcmfmac/of.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +5
-7@@ -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);
This patch is still needed.
regards,
dan carpenter
Quoted 55 lines · Dan Carpenter
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()andstrreplace()functions.Fixes 29e354ebeeec ("brcmfmac: Transform compatible string for FW loading")Suggested-by Johannes Berg <[email protected]>Suggested-by Christophe JAILLET <[email protected]>Reported-by Hans deGoede <[email protected]>Signed-off-by Dan Carpenter <[email protected]>---
v2: Basically a completely different patch. :)
v3: Add missingof_node_put()caught by Hans de Goede.../net/wireless/broadcom/brcm80211/brcmfmac/of.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +5
-7@@ -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);Signature · 1 line
2.30.2
Quoted 1 line · Dan Carpenter
This patch is still needed.
I don't see v3 in patchwork[1], but I do see v2. I don't know what happened, but please resend the patch as v4.
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches