Skip to content

Commit 5c632cc

Browse files
Jiri PirkoSaeed Mahameed
authored andcommitted
net/mlx5: Relax mlx5_devlink_eswitch_get() return value checking
If called from port ops, it is not needed to perform the checks in mlx5_devlink_eswitch_get(). The reason is devlink port would not be registered if the checks are not true. Introduce relaxed version mlx5_devlink_eswitch_nocheck_get() and use it in port ops. Signed-off-by: Jiri Pirko <jiri@nvidia.com> Reviewed-by: Shay Drory <shayd@nvidia.com> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
1 parent c0ae009 commit 5c632cc

File tree

3 files changed

+29
-37
lines changed

3 files changed

+29
-37
lines changed

drivers/net/ethernet/mellanox/mlx5/core/eswitch.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,31 @@ static int mlx5_eswitch_check(const struct mlx5_core_dev *dev)
7777
return 0;
7878
}
7979

80-
struct mlx5_eswitch *mlx5_devlink_eswitch_get(struct devlink *devlink)
80+
static struct mlx5_eswitch *__mlx5_devlink_eswitch_get(struct devlink *devlink, bool check)
8181
{
8282
struct mlx5_core_dev *dev = devlink_priv(devlink);
8383
int err;
8484

85-
err = mlx5_eswitch_check(dev);
86-
if (err)
87-
return ERR_PTR(err);
85+
if (check) {
86+
err = mlx5_eswitch_check(dev);
87+
if (err)
88+
return ERR_PTR(err);
89+
}
8890

8991
return dev->priv.eswitch;
9092
}
9193

94+
struct mlx5_eswitch *__must_check
95+
mlx5_devlink_eswitch_get(struct devlink *devlink)
96+
{
97+
return __mlx5_devlink_eswitch_get(devlink, true);
98+
}
99+
100+
struct mlx5_eswitch *mlx5_devlink_eswitch_nocheck_get(struct devlink *devlink)
101+
{
102+
return __mlx5_devlink_eswitch_get(devlink, false);
103+
}
104+
92105
struct mlx5_vport *__must_check
93106
mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num)
94107
{

drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,11 @@ void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw);
679679
MLX5_CAP_GEN_2((esw->dev), ec_vf_vport_base) +\
680680
(last) - 1)
681681

682-
struct mlx5_eswitch *mlx5_devlink_eswitch_get(struct devlink *devlink);
682+
struct mlx5_eswitch *__must_check
683+
mlx5_devlink_eswitch_get(struct devlink *devlink);
684+
685+
struct mlx5_eswitch *mlx5_devlink_eswitch_nocheck_get(struct devlink *devlink);
686+
683687
struct mlx5_vport *__must_check
684688
mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num);
685689

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3634,7 +3634,7 @@ static bool esw_offloads_devlink_ns_eq_netdev_ns(struct devlink *devlink)
36343634
struct net *devl_net, *netdev_net;
36353635
struct mlx5_eswitch *esw;
36363636

3637-
esw = mlx5_devlink_eswitch_get(devlink);
3637+
esw = mlx5_devlink_eswitch_nocheck_get(devlink);
36383638
netdev_net = dev_net(esw->dev->mlx5e_res.uplink_netdev);
36393639
devl_net = devlink_net(devlink);
36403640

@@ -4222,13 +4222,10 @@ int mlx5_devlink_port_fn_hw_addr_get(struct devlink_port *port,
42224222
u8 *hw_addr, int *hw_addr_len,
42234223
struct netlink_ext_ack *extack)
42244224
{
4225-
struct mlx5_eswitch *esw;
4225+
struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
42264226
struct mlx5_vport *vport;
42274227
u16 vport_num;
42284228

4229-
esw = mlx5_devlink_eswitch_get(port->devlink);
4230-
if (IS_ERR(esw))
4231-
return PTR_ERR(esw);
42324229

42334230
vport_num = mlx5_esw_devlink_port_index_to_vport_num(port->index);
42344231

@@ -4249,15 +4246,9 @@ int mlx5_devlink_port_fn_hw_addr_set(struct devlink_port *port,
42494246
const u8 *hw_addr, int hw_addr_len,
42504247
struct netlink_ext_ack *extack)
42514248
{
4252-
struct mlx5_eswitch *esw;
4249+
struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
42534250
u16 vport_num;
42544251

4255-
esw = mlx5_devlink_eswitch_get(port->devlink);
4256-
if (IS_ERR(esw)) {
4257-
NL_SET_ERR_MSG_MOD(extack, "Eswitch doesn't support set hw_addr");
4258-
return PTR_ERR(esw);
4259-
}
4260-
42614252
vport_num = mlx5_esw_devlink_port_index_to_vport_num(port->index);
42624253
return mlx5_eswitch_set_vport_mac(esw, vport_num, hw_addr);
42634254
}
@@ -4277,13 +4268,9 @@ mlx5_devlink_port_fn_get_vport(struct devlink_port *port, struct mlx5_eswitch *e
42774268
int mlx5_devlink_port_fn_migratable_get(struct devlink_port *port, bool *is_enabled,
42784269
struct netlink_ext_ack *extack)
42794270
{
4280-
struct mlx5_eswitch *esw;
4271+
struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
42814272
struct mlx5_vport *vport;
42824273

4283-
esw = mlx5_devlink_eswitch_get(port->devlink);
4284-
if (IS_ERR(esw))
4285-
return PTR_ERR(esw);
4286-
42874274
if (!MLX5_CAP_GEN(esw->dev, migration)) {
42884275
NL_SET_ERR_MSG_MOD(extack, "Device doesn't support migration");
42894276
return -EOPNOTSUPP;
@@ -4304,17 +4291,13 @@ int mlx5_devlink_port_fn_migratable_get(struct devlink_port *port, bool *is_enab
43044291
int mlx5_devlink_port_fn_migratable_set(struct devlink_port *port, bool enable,
43054292
struct netlink_ext_ack *extack)
43064293
{
4294+
struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
43074295
int query_out_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out);
4308-
struct mlx5_eswitch *esw;
43094296
struct mlx5_vport *vport;
43104297
void *query_ctx;
43114298
void *hca_caps;
43124299
int err;
43134300

4314-
esw = mlx5_devlink_eswitch_get(port->devlink);
4315-
if (IS_ERR(esw))
4316-
return PTR_ERR(esw);
4317-
43184301
if (!MLX5_CAP_GEN(esw->dev, migration)) {
43194302
NL_SET_ERR_MSG_MOD(extack, "Device doesn't support migration");
43204303
return -EOPNOTSUPP;
@@ -4368,13 +4351,9 @@ int mlx5_devlink_port_fn_migratable_set(struct devlink_port *port, bool enable,
43684351
int mlx5_devlink_port_fn_roce_get(struct devlink_port *port, bool *is_enabled,
43694352
struct netlink_ext_ack *extack)
43704353
{
4371-
struct mlx5_eswitch *esw;
4354+
struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
43724355
struct mlx5_vport *vport;
43734356

4374-
esw = mlx5_devlink_eswitch_get(port->devlink);
4375-
if (IS_ERR(esw))
4376-
return PTR_ERR(esw);
4377-
43784357
vport = mlx5_devlink_port_fn_get_vport(port, esw);
43794358
if (IS_ERR(vport)) {
43804359
NL_SET_ERR_MSG_MOD(extack, "Invalid port");
@@ -4390,18 +4369,14 @@ int mlx5_devlink_port_fn_roce_get(struct devlink_port *port, bool *is_enabled,
43904369
int mlx5_devlink_port_fn_roce_set(struct devlink_port *port, bool enable,
43914370
struct netlink_ext_ack *extack)
43924371
{
4372+
struct mlx5_eswitch *esw = mlx5_devlink_eswitch_nocheck_get(port->devlink);
43934373
int query_out_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out);
4394-
struct mlx5_eswitch *esw;
43954374
struct mlx5_vport *vport;
43964375
void *query_ctx;
43974376
void *hca_caps;
43984377
u16 vport_num;
43994378
int err;
44004379

4401-
esw = mlx5_devlink_eswitch_get(port->devlink);
4402-
if (IS_ERR(esw))
4403-
return PTR_ERR(esw);
4404-
44054380
vport = mlx5_devlink_port_fn_get_vport(port, esw);
44064381
if (IS_ERR(vport)) {
44074382
NL_SET_ERR_MSG_MOD(extack, "Invalid port");

0 commit comments

Comments
 (0)