linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] brcmfmac: Transform compatible string for FW loading
@ 2020-06-29 11:01 matthias.bgg
  2020-06-29 11:35 ` Hans de Goede
  0 siblings, 1 reply; 2+ messages in thread
From: matthias.bgg @ 2020-06-29 11:01 UTC (permalink / raw)
  To: arend.vanspriel, kvalo, davem, kuba
  Cc: brcm80211-dev-list.pdl, mbrugger, netdev, chi-hsien.lin,
	linux-wireless, hante.meuleman, linux-kernel, hdegoede,
	wright.feng, matthias.bgg, brcm80211-dev-list, franky.lin

From: Matthias Brugger <mbrugger@suse.com>

The driver relies on the compatible string from DT to determine which
FW configuration file it should load. The DTS spec allows for '/' as
part of the compatible string. We change this to '-' so that we will
still be able to load the config file, even when the compatible has a
'/'. This fixes explicitly the firmware loading for
"solidrun,cubox-i/q".

Signed-off-by: Matthias Brugger <mbrugger@suse.com>

---

Changes in v2:
- use strscpy instead of strncpy (Hans de Goede)
- use strlen(tmp) + 1 for allocation (Hans de Goede, kernel test robot)

 .../wireless/broadcom/brcm80211/brcmfmac/of.c  | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
index b886b56a5e5a..5f0ebaf4d64e 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
@@ -17,7 +17,6 @@ void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
 {
 	struct brcmfmac_sdio_pd *sdio = &settings->bus.sdio;
 	struct device_node *root, *np = dev->of_node;
-	struct property *prop;
 	int irq;
 	u32 irqf;
 	u32 val;
@@ -25,8 +24,21 @@ 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) {
-		prop = of_find_property(root, "compatible", NULL);
-		settings->board_type = of_prop_next_string(prop, NULL);
+		int i;
+		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 */
+		board_type = devm_kzalloc(dev, strlen(tmp) + 1, GFP_KERNEL);
+		strscpy(board_type, tmp, sizeof(board_type));
+		for (i = 0; i < strlen(board_type); i++) {
+			if (board_type[i] == '/')
+				board_type[i] = '-';
+		}
+		settings->board_type = board_type;
+
 		of_node_put(root);
 	}
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] brcmfmac: Transform compatible string for FW loading
  2020-06-29 11:01 [PATCH v2] brcmfmac: Transform compatible string for FW loading matthias.bgg
@ 2020-06-29 11:35 ` Hans de Goede
  0 siblings, 0 replies; 2+ messages in thread
From: Hans de Goede @ 2020-06-29 11:35 UTC (permalink / raw)
  To: matthias.bgg, arend.vanspriel, kvalo, davem, kuba
  Cc: brcm80211-dev-list.pdl, mbrugger, netdev, chi-hsien.lin,
	linux-wireless, hante.meuleman, linux-kernel, wright.feng,
	brcm80211-dev-list, franky.lin

Hi,

On 6/29/20 1:01 PM, matthias.bgg@kernel.org wrote:
> From: Matthias Brugger <mbrugger@suse.com>
> 
> The driver relies on the compatible string from DT to determine which
> FW configuration file it should load. The DTS spec allows for '/' as
> part of the compatible string. We change this to '-' so that we will
> still be able to load the config file, even when the compatible has a
> '/'. This fixes explicitly the firmware loading for
> "solidrun,cubox-i/q".
> 
> Signed-off-by: Matthias Brugger <mbrugger@suse.com>
> 
> ---
> 
> Changes in v2:
> - use strscpy instead of strncpy (Hans de Goede)
> - use strlen(tmp) + 1 for allocation (Hans de Goede, kernel test robot)
> 
>   .../wireless/broadcom/brcm80211/brcmfmac/of.c  | 18 +++++++++++++++---
>   1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> index b886b56a5e5a..5f0ebaf4d64e 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> @@ -17,7 +17,6 @@ void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
>   {
>   	struct brcmfmac_sdio_pd *sdio = &settings->bus.sdio;
>   	struct device_node *root, *np = dev->of_node;
> -	struct property *prop;
>   	int irq;
>   	u32 irqf;
>   	u32 val;
> @@ -25,8 +24,21 @@ 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) {
> -		prop = of_find_property(root, "compatible", NULL);
> -		settings->board_type = of_prop_next_string(prop, NULL);
> +		int i;
> +		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 */
> +		board_type = devm_kzalloc(dev, strlen(tmp) + 1, GFP_KERNEL);
> +		strscpy(board_type, tmp, sizeof(board_type));

sizeof(board_type) == sizeof(char *) == 4 or 8 bytes, which is not what you
want. Maybe store strlen() + 1 in an int len to avoid having to call it 2 times?

> +		for (i = 0; i < strlen(board_type); i++) {

And here you probably want to use:

		for (i = 0; board_type[i]; i++) {

Rather then calling strlen many times again (in theory each step
through the loop).

Regards,

Hans



> +			if (board_type[i] == '/')
> +				board_type[i] = '-';
> +		}
> +		settings->board_type = board_type;
> +
>   		of_node_put(root);
>   	}
>   
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-29 21:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29 11:01 [PATCH v2] brcmfmac: Transform compatible string for FW loading matthias.bgg
2020-06-29 11:35 ` Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).