Skip to contentSkip to conversation

firmware: Allocate firmware id dynamically

PATCH In review Samuel Ortiz 8 participants 12 messages May 26, 2009 – May 27, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firmware: Allocate firmware id dynamically

Hi Andrew,

Since the firmware loader is not maintained by anyone, I'm sending this one to you, for the next merge window:

From: Samuel Ortiz <[email protected]>

The firmware loader has a statically allocated 30 bytes long string for the firmware id (a.k.a. the firmware file name). There is no reason why we couldnt allocate dynamically, and avoid having restrictions on the firmware names lengths.
Please note that we have to keep the FIRMWARE_NAME_MAX definition around as some drivers rely on it.

---

 drivers/base/firmware_class.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
drivers/base/firmware_class.c +13 -3
index d3a59c6..1f0daf9 100644
@@ -40,7 +40,7 @@ static int loading_timeout = 60;	/* In seconds */
 static DEFINE_MUTEX(fw_lock);
 
 struct firmware_priv {
-	char fw_id[FIRMWARE_NAME_MAX];
+	char *fw_id;
 	struct completion completion;
 	struct bin_attribute attr_data;
 	struct firmware *fw;
@@ -278,6 +278,7 @@ static void fw_dev_release(struct device *dev)
 {
 	struct firmware_priv *fw_priv = dev_get_drvdata(dev);
 
+	kfree(fw_priv->fw_id);
 	kfree(fw_priv);
 	kfree(dev);
 
@@ -309,7 +310,13 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
 
 	init_completion(&fw_priv->completion);
 	fw_priv->attr_data = firmware_attr_data_tmpl;
-	strlcpy(fw_priv->fw_id, fw_name, FIRMWARE_NAME_MAX);
+	fw_priv->fw_id = kstrdup(fw_name, GFP_KERNEL);
+	if (!fw_priv->fw_id) {
+		dev_err(device, "%s: Firmware name allocation failed\n",
+			__func__);
+		retval = -ENOMEM;
+		goto error_kfree;
+	}
 
 	fw_priv->timeout.function = firmware_class_timeout;
 	fw_priv->timeout.data = (u_long) fw_priv;
@@ -323,11 +330,14 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
 	retval = device_register(f_dev);
 	if (retval) {
 		dev_err(device, "%s: device_register failed\n", __func__);
-		goto error_kfree;
+		goto error_kfree_fw_id;
 	}
 	*dev_p = f_dev;
 	return 0;
 
+error_kfree_fw_id:
+	kfree(fw_priv->fw_id);
+
 error_kfree:
 	kfree(fw_priv);
 	kfree(f_dev);
Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
#1 lore raw
Quoted 2 lines · Samuel Ortiz

Since the firmware loader is not maintained by anyone, I'm sending this one to you, for the next merge window:

It's part of the driver-core directory, and handled by Greg.

Quoted 4 lines

The firmware loader has a statically allocated 30 bytes long string for the firmware id (a.k.a. the firmware file name). There is no reason why we couldnt allocate dynamically, and avoid having restrictions on the firmware names lengths.

Looks good.

Quoted 2 lines

Please note that we have to keep the FIRMWARE_NAME_MAX definition around as some drivers rely on it.

I think the 6 files should be converted, and FIRMWARE_NAME_MAX removed, otherwise people will keep copying that crap around.

drivers/pcmcia/ds.c
drivers/usb/atm/ueagle-atm.c
drivers/net/wireless/libertas/if_usb.c
drivers/net/wireless/libertas/if_spi.c
drivers/media/dvb/dvb-usb/dvb-usb.h
drivers/media/common/tuners/tuner-xc2028.c

Thanks,
Kay

#2 lore raw
Quoted 6 lines · On Tue, 26 May 2009 16:11:35 +0200 Kay Sievers <[email protected]> wrote:
Quoted 2 lines · Samuel Ortiz

Since the firmware loader is not maintained by anyone, I'm sending this one to you, for the next merge window:

It's part of the driver-core directory, and handled by Greg.

To which it doesn't apply. It needed more fixes than I felt like making.

Quoted 13 lines
Quoted 4 lines

The firmware loader has a statically allocated 30 bytes long string for the firmware id (a.k.a. the firmware file name). There is no reason why we couldnt allocate dynamically, and avoid having restrictions on the firmware names lengths.

Looks good.

Quoted 2 lines

Please note that we have to keep the FIRMWARE_NAME_MAX definition around as some drivers rely on it.

I think the 6 files should be converted, and FIRMWARE_NAME_MAX removed, otherwise people will keep copying that crap around.

Quoted 6 lines

drivers/pcmcia/ds.c
drivers/usb/atm/ueagle-atm.c
drivers/net/wireless/libertas/if_usb.c
drivers/net/wireless/libertas/if_spi.c
drivers/media/dvb/dvb-usb/dvb-usb.h
drivers/media/common/tuners/tuner-xc2028.c

Yep.

#3 lore raw

Hi all,

Quoted 7 lines · On Tue, 26 May 2009 13:23:51 -0700 Andrew Morton <[email protected]>…
Quoted 7 lines
Quoted 3 lines

Please note that we have to keep the FIRMWARE_NAME_MAX definition around as some drivers rely on it.

I think the 6 files should be converted, and FIRMWARE_NAME_MAX removed, otherwise people will keep copying that crap around.

Quoted 8 lines
Quoted 6 lines

drivers/pcmcia/ds.c
drivers/usb/atm/ueagle-atm.c
drivers/net/wireless/libertas/if_usb.c
drivers/net/wireless/libertas/if_spi.c
drivers/media/dvb/dvb-usb/dvb-usb.h
drivers/media/common/tuners/tuner-xc2028.c

Yep.

$ git grep -l -w FIRMWARE_NAME_MAX next-20090526 
next-20090526:drivers/base/firmware_class.c
next-20090526:drivers/media/common/tuners/tuner-xc2028.c
next-20090526:drivers/media/dvb/dvb-usb/dvb-usb.h
next-20090526:drivers/net/wireless/libertas/if_spi.c
next-20090526:drivers/net/wireless/libertas/if_usb.c
next-20090526:drivers/net/wireless/p54/p54usb.c
next-20090526:drivers/pcmcia/ds.c
next-20090526:drivers/usb/atm/ueagle-atm.c
next-20090526:include/linux/firmware.h
next-20090526:samples/firmware_class/firmware_sample_firmware_class.c

Its already started ...

/me looks forward to more breakage in -next :-(

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#4 lore raw

Hi Stephen,

Quoted 19 lines · Stephen Rothwell

Hi all,

Quoted 7 lines · On Tue, 26 May 2009 13:23:51 -0700 Andrew Morton <[email protected]>…
Quoted 7 lines
Quoted 3 lines

Please note that we have to keep the FIRMWARE_NAME_MAX definition around as some drivers rely on it.

I think the 6 files should be converted, and FIRMWARE_NAME_MAX removed, otherwise people will keep copying that crap around.

Quoted 8 lines
Quoted 6 lines

drivers/pcmcia/ds.c
drivers/usb/atm/ueagle-atm.c
drivers/net/wireless/libertas/if_usb.c
drivers/net/wireless/libertas/if_spi.c
drivers/media/dvb/dvb-usb/dvb-usb.h
drivers/media/common/tuners/tuner-xc2028.c

Yep.

Quoted 10 lines
$ git grep -l -w FIRMWARE_NAME_MAX next-20090526 
next-20090526:drivers/base/firmware_class.c
next-20090526:drivers/media/common/tuners/tuner-xc2028.c
next-20090526:drivers/media/dvb/dvb-usb/dvb-usb.h
next-20090526:drivers/net/wireless/libertas/if_spi.c
next-20090526:drivers/net/wireless/libertas/if_usb.c
next-20090526:drivers/net/wireless/p54/p54usb.c
next-20090526:drivers/pcmcia/ds.c
next-20090526:drivers/usb/atm/ueagle-atm.c
next-20090526:include/linux/firmware.h

All of those have been taken care of by my last patch set, see:
http://lkml.org/lkml/2009/5/26/518

The p54usb one has been sent to John and linux-wireless as it's coming from wireless-testing.

Quoted 1 line

next-20090526:samples/firmware_class/firmware_sample_firmware_class.c

Do I really need to fix this one too ?

Cheers,
Samuel.

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
#5 lore raw
Quoted 2 lines · Samuel Ortiz
Quoted 1 line

next-20090526:samples/firmware_class/firmware_sample_firmware_class.c

Do I really need to fix this one too ?

I does not compile since ages, it is totally outdated and uses the long removed struct class_device. And we really don't need an example for firmware loading, I think. This file should just be deleted.

Thanks,
Kay

#6 lore raw
Quoted 8 lines · Kay Sievers
Quoted 2 lines · Samuel Ortiz
Quoted 1 line

next-20090526:samples/firmware_class/firmware_sample_firmware_class.c

Do I really need to fix this one too ?

I does not compile since ages, it is totally outdated and uses the long removed struct class_device. And we really don't need an example for firmware loading, I think. This file should just be deleted.

Yeah, I had plans to write it "properly", but it's at the end of my long TODO list :(

I'll just go delete the thing instead.

thanks,

greg k-h

#7 lore raw
In reply to Samuel Ortiz
Quoted 7 lines · Samuel Ortiz
Quoted 1 line

next-20090526:drivers/net/wireless/p54/p54usb.c

All of those have been taken care of by my last patch set, see:
http://lkml.org/lkml/2009/5/26/518

The p54usb one has been sent to John and linux-wireless as it's coming from wireless-testing.

Is that patch dependent on other p54 bits in wireless-next-2.6?

John

Signature · 2 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.
#8 lore raw
Quoted 11 lines · John W. Linville
Quoted 7 lines · Samuel Ortiz
Quoted 1 line

next-20090526:drivers/net/wireless/p54/p54usb.c

All of those have been taken care of by my last patch set, see:
http://lkml.org/lkml/2009/5/26/518

The p54usb one has been sent to John and linux-wireless as it's coming from wireless-testing.

Is that patch dependent on other p54 bits in wireless-next-2.6?

The p54usb.c FIRMWARE_NAME_MAX reference was introduce with commit 1ca5f2e94c40b04d5dec437cd41fd5ba12aaac31 from your wireless-next-2.6 tree.

Cheers,
Samuel.

Quoted 4 lines

John

Signature · 2 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.
Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
#9 lore raw
In reply to Kay Sievers

Hi Samuel,

Quoted 11 lines
Quoted 2 lines

Since the firmware loader is not maintained by anyone, I'm sending this one to you, for the next merge window:

It's part of the driver-core directory, and handled by Greg.

Quoted 4 lines

The firmware loader has a statically allocated 30 bytes long string for the firmware id (a.k.a. the firmware file name). There is no reason why we couldnt allocate dynamically, and avoid having restrictions on the firmware names lengths.

Looks good.

Quoted 6 lines
Quoted 2 lines

Please note that we have to keep the FIRMWARE_NAME_MAX definition around as some drivers rely on it.

I think the 6 files should be converted, and FIRMWARE_NAME_MAX removed, otherwise people will keep copying that crap around.

Quoted 6 lines

drivers/pcmcia/ds.c
drivers/usb/atm/ueagle-atm.c
drivers/net/wireless/libertas/if_usb.c
drivers/net/wireless/libertas/if_spi.c
drivers/media/dvb/dvb-usb/dvb-usb.h
drivers/media/common/tuners/tuner-xc2028.c

I do agree with Kay here that we should just go ahead and fix these.

Regards

Marcel

#10 lore raw

PATCH 1/1 libertas: adapt for dynamic firmware id allocation

In reply to Samuel Ortiz
---
 drivers/net/wireless/libertas/if_spi.c |    8 ++++----
 drivers/net/wireless/libertas/if_spi.h |    3 +++
 drivers/net/wireless/libertas/if_usb.c |    8 ++------
 3 files changed, 9 insertions(+), 10 deletions(-)
drivers/net/wireless/libertas/if_spi.c +4 -4
index 5fa55fe..b3dc609 100644
@@ -44,8 +44,8 @@ struct if_spi_card {
 	struct lbs_private		*priv;
 	struct libertas_spi_platform_data *pdata;
 
-	char				helper_fw_name[FIRMWARE_NAME_MAX];
-	char				main_fw_name[FIRMWARE_NAME_MAX];
+	char				helper_fw_name[IF_SPI_FW_NAME_MAX];
+	char				main_fw_name[IF_SPI_FW_NAME_MAX];
 
 	/* The card ID and card revision, as reported by the hardware. */
 	u16				card_id;
@@ -1013,9 +1013,9 @@ static int if_spi_calculate_fw_names(u16 card_id,
 		lbs_pr_err("Unsupported chip_id: 0x%02x\n", card_id);
 		return -EAFNOSUPPORT;
 	}
-	snprintf(helper_fw, FIRMWARE_NAME_MAX, "libertas/gspi%d_hlp.bin",
+	snprintf(helper_fw, IF_SPI_FW_NAME_MAX, "libertas/gspi%d_hlp.bin",
 		 chip_id_to_device_name[i].name);
-	snprintf(main_fw, FIRMWARE_NAME_MAX, "libertas/gspi%d.bin",
+	snprintf(main_fw, IF_SPI_FW_NAME_MAX, "libertas/gspi%d.bin",
 		 chip_id_to_device_name[i].name);
 	return 0;
 }
drivers/net/wireless/libertas/if_spi.h +3 -0
index 2103869..f87eec4 100644
@@ -22,6 +22,9 @@
 #define IF_SPI_CMD_BUF_SIZE 2400
 
 /***************** Firmware *****************/
+
+#define IF_SPI_FW_NAME_MAX 30
+
 struct chip_ident {
 	u16 chip_id;
 	u16 name;
drivers/net/wireless/libertas/if_usb.c +2 -6
index ea3dc03..713c830 100644
@@ -61,11 +61,9 @@ static ssize_t if_usb_firmware_set(struct device *dev,
 {
 	struct lbs_private *priv = to_net_dev(dev)->ml_priv;
 	struct if_usb_card *cardp = priv->card;
-	char fwname[FIRMWARE_NAME_MAX];
 	int ret;
 
-	sscanf(buf, "%29s", fwname); /* FIRMWARE_NAME_MAX - 1 = 29 */
-	ret = if_usb_prog_firmware(cardp, fwname, BOOT_CMD_UPDATE_FW);
+	ret = if_usb_prog_firmware(cardp, buf, BOOT_CMD_UPDATE_FW);
 	if (ret == 0)
 		return count;
 
@@ -88,11 +86,9 @@ static ssize_t if_usb_boot2_set(struct device *dev,
 {
 	struct lbs_private *priv = to_net_dev(dev)->ml_priv;
 	struct if_usb_card *cardp = priv->card;
-	char fwname[FIRMWARE_NAME_MAX];
 	int ret;
 
-	sscanf(buf, "%29s", fwname); /* FIRMWARE_NAME_MAX - 1 = 29 */
-	ret = if_usb_prog_firmware(cardp, fwname, BOOT_CMD_UPDATE_BOOT2);
+	ret = if_usb_prog_firmware(cardp, buf, BOOT_CMD_UPDATE_BOOT2);
 	if (ret == 0)
 		return count;
 
Signature · 1 line
1.6.0.6
Acked-by on v1 1/1
#11 lore raw

Re: [PATCH] libertas: adapt for dynamic firmware id allocation

Quoted 1 line · John W. Linville
Quoted 77 lines
---
 drivers/net/wireless/libertas/if_spi.c |    8 ++++----
 drivers/net/wireless/libertas/if_spi.h |    3 +++
 drivers/net/wireless/libertas/if_usb.c |    8 ++------
 3 files changed, 9 insertions(+), 10 deletions(-)
drivers/net/wireless/libertas/if_spi.c +4 -4
index 5fa55fe..b3dc609 100644
@@ -44,8 +44,8 @@ struct if_spi_card {
 	struct lbs_private		*priv;
 	struct libertas_spi_platform_data *pdata;
 
-	char				helper_fw_name[FIRMWARE_NAME_MAX];
-	char				main_fw_name[FIRMWARE_NAME_MAX];
+	char				helper_fw_name[IF_SPI_FW_NAME_MAX];
+	char				main_fw_name[IF_SPI_FW_NAME_MAX];
 
 	/* The card ID and card revision, as reported by the hardware. */
 	u16				card_id;
@@ -1013,9 +1013,9 @@ static int if_spi_calculate_fw_names(u16 card_id,
 		lbs_pr_err("Unsupported chip_id: 0x%02x\n", card_id);
 		return -EAFNOSUPPORT;
 	}
-	snprintf(helper_fw, FIRMWARE_NAME_MAX, "libertas/gspi%d_hlp.bin",
+	snprintf(helper_fw, IF_SPI_FW_NAME_MAX, "libertas/gspi%d_hlp.bin",
 		 chip_id_to_device_name[i].name);
-	snprintf(main_fw, FIRMWARE_NAME_MAX, "libertas/gspi%d.bin",
+	snprintf(main_fw, IF_SPI_FW_NAME_MAX, "libertas/gspi%d.bin",
 		 chip_id_to_device_name[i].name);
 	return 0;
 }
drivers/net/wireless/libertas/if_spi.h +3 -0
index 2103869..f87eec4 100644
@@ -22,6 +22,9 @@
 #define IF_SPI_CMD_BUF_SIZE 2400
 
 /***************** Firmware *****************/
+
+#define IF_SPI_FW_NAME_MAX 30
+
 struct chip_ident {
 	u16 chip_id;
 	u16 name;
drivers/net/wireless/libertas/if_usb.c +2 -6
index ea3dc03..713c830 100644
@@ -61,11 +61,9 @@ static ssize_t if_usb_firmware_set(struct device *dev,
 {
 	struct lbs_private *priv = to_net_dev(dev)->ml_priv;
 	struct if_usb_card *cardp = priv->card;
-	char fwname[FIRMWARE_NAME_MAX];
 	int ret;
 
-	sscanf(buf, "%29s", fwname); /* FIRMWARE_NAME_MAX - 1 = 29 */
-	ret = if_usb_prog_firmware(cardp, fwname, BOOT_CMD_UPDATE_FW);
+	ret = if_usb_prog_firmware(cardp, buf, BOOT_CMD_UPDATE_FW);
 	if (ret == 0)
 		return count;
 
@@ -88,11 +86,9 @@ static ssize_t if_usb_boot2_set(struct device *dev,
 {
 	struct lbs_private *priv = to_net_dev(dev)->ml_priv;
 	struct if_usb_card *cardp = priv->card;
-	char fwname[FIRMWARE_NAME_MAX];
 	int ret;
 
-	sscanf(buf, "%29s", fwname); /* FIRMWARE_NAME_MAX - 1 = 29 */
-	ret = if_usb_prog_firmware(cardp, fwname, BOOT_CMD_UPDATE_BOOT2);
+	ret = if_usb_prog_firmware(cardp, buf, BOOT_CMD_UPDATE_BOOT2);
 	if (ret == 0)
 		return count;