devlink: check flash_update parameter support in net core
When implementing .flash_update, drivers which do not support per-component update are manually checking the component parameter to verify that it is NULL. Without this check, the driver might accept an update request with a component specified even though it will not honor such a request. Instead of having each driver check this, move the logic into net/core/devlink.c, and use a new `supported_flash_update_params` field in the devlink_ops. Drivers which will support per-component update must now specify this by setting DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT in the supported_flash_update_params in their devlink_ops. This helps ensure that drivers do not forget to check for a NULL component if they do not support per-component update. This also enables a slightly better error message by enabling the core stack to set the netlink bad attribute message to indicate precisely the unsupported attribute in the message. Going forward, any new additional parameter to flash update will require a bit in the supported_flash_update_params bitfield. Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Cc: Jiri Pirko <jiri@mellanox.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Michael Chan <michael.chan@broadcom.com> Cc: Bin Luo <luobin9@huawei.com> Cc: Saeed Mahameed <saeedm@mellanox.com> Cc: Leon Romanovsky <leon@kernel.org> Cc: Ido Schimmel <idosch@mellanox.com> Cc: Danielle Ratson <danieller@mellanox.com> Cc: Shannon Nelson <snelson@pensando.io> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
6fba737a93
commit
22ec3d232f
@@ -3148,18 +3148,29 @@ static int devlink_nl_cmd_flash_update(struct sk_buff *skb,
|
||||
struct genl_info *info)
|
||||
{
|
||||
struct devlink *devlink = info->user_ptr[0];
|
||||
const char *file_name, *component;
|
||||
const char *file_name, *component = NULL;
|
||||
struct nlattr *nla_component;
|
||||
u32 supported_params;
|
||||
|
||||
if (!devlink->ops->flash_update)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (!info->attrs[DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME])
|
||||
return -EINVAL;
|
||||
|
||||
supported_params = devlink->ops->supported_flash_update_params;
|
||||
|
||||
file_name = nla_data(info->attrs[DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME]);
|
||||
|
||||
nla_component = info->attrs[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT];
|
||||
component = nla_component ? nla_data(nla_component) : NULL;
|
||||
if (nla_component) {
|
||||
if (!(supported_params & DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT)) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, nla_component,
|
||||
"component update is not supported by this device");
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
component = nla_data(nla_component);
|
||||
}
|
||||
|
||||
return devlink->ops->flash_update(devlink, file_name, component,
|
||||
info->extack);
|
||||
|
||||
Reference in New Issue
Block a user