Re: [RFC PATCH net-next 9/9] ethtool: Add ability to flash transceiver modules' firmware

From: Jakub Kicinski
Date: Wed Jan 24 2024 - 12:09:05 EST


On Wed, 24 Jan 2024 15:46:55 +0000 Danielle Ratson wrote:
> > > The file_name parameter is not really needed inside the work. Once we
> > > called request_firmware_direct(), we have all that we need in
> > > module_fw->fw. Do we still need to avoid that situation? If so, can
> > > you please suggest how?
> >
> > I'd pass it to module_flash_fw_schedule() as a separate argument, if it doesn't
> > have to be saved.
>
> It doesn’t make the module_fw->file_name attribute redundant?

This is what I mean:

diff --git a/net/ethtool/module.c b/net/ethtool/module.c
index 69cedb3ede6d..ea048a7089d9 100644
--- a/net/ethtool/module.c
+++ b/net/ethtool/module.c
@@ -229,7 +229,7 @@ static int module_flash_fw_work_init(struct ethtool_module_fw_flash *module_fw,
}

static int
-module_flash_fw_schedule(struct net_device *dev,
+module_flash_fw_schedule(struct net_device *dev, const char *file_name,
struct ethtool_module_fw_flash_params *params,
struct netlink_ext_ack *extack)
{
@@ -254,8 +254,7 @@ module_flash_fw_schedule(struct net_device *dev,
return -ENOMEM;

module_fw->params = *params;
- err = request_firmware(&module_fw->fw, module_fw->params.file_name,
- &dev->dev);
+ err = request_firmware(&module_fw->fw, file_name, &dev->dev);
if (err) {
NL_SET_ERR_MSG(extack,
"Failed to request module firmware image");
@@ -288,6 +287,7 @@ static int module_flash_fw(struct net_device *dev, struct nlattr **tb,
struct netlink_ext_ack *extack)
{
struct ethtool_module_fw_flash_params params = {};
+ const char *file_name;
struct nlattr *attr;

if (!tb[ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME]) {
@@ -297,8 +297,7 @@ static int module_flash_fw(struct net_device *dev, struct nlattr **tb,
return -EINVAL;
}

- params.file_name =
- nla_data(tb[ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME]);
+ file_name = nla_data(tb[ETHTOOL_A_MODULE_FW_FLASH_FILE_NAME]);

attr = tb[ETHTOOL_A_MODULE_FW_FLASH_PASSWORD];
if (attr) {
@@ -306,7 +305,7 @@ static int module_flash_fw(struct net_device *dev, struct nlattr **tb,
params.password_valid = true;
}

- return module_flash_fw_schedule(dev, &params, extack);
+ return module_flash_fw_schedule(dev, file_name, &params, extack);
}

int ethnl_act_module_fw_flash(struct sk_buff *skb, struct genl_info *info)
diff --git a/net/ethtool/module_fw.h b/net/ethtool/module_fw.h
index 969de116f995..888f082f8daf 100644
--- a/net/ethtool/module_fw.h
+++ b/net/ethtool/module_fw.h
@@ -13,12 +13,10 @@ void ethtool_cmis_fw_update(struct work_struct *work);

/**
* struct ethtool_module_fw_flash_params - module firmware flashing parameters
- * @file_name: Firmware image file name.
* @password: Module password. Only valid when @pass_valid is set.
* @password_valid: Whether the module password is valid or not.
*/
struct ethtool_module_fw_flash_params {
- const char *file_name;
u32 password;
u8 password_valid:1;
};