Skip to content

Commit ccc3e6b

Browse files
lunndavem330
authored andcommitted
net: dsa: Add helper to convert from devlink to ds
Given a devlink instance, return the dsa switch it is associated to. Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d4602a9 commit ccc3e6b

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

‎include/net/dsa.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,13 @@ struct dsa_devlink_priv {
664664
struct dsa_switch *ds;
665665
};
666666

667+
static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl)
668+
{
669+
struct dsa_devlink_priv *dl_priv = devlink_priv(dl);
670+
671+
return dl_priv->ds;
672+
}
673+
667674
struct dsa_switch_driver {
668675
struct list_head list;
669676
const struct dsa_switch_ops *ops;

‎net/dsa/dsa.c‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,7 @@ EXPORT_SYMBOL_GPL(call_dsa_notifiers);
330330
int dsa_devlink_param_get(struct devlink *dl, u32 id,
331331
struct devlink_param_gset_ctx *ctx)
332332
{
333-
struct dsa_devlink_priv *dl_priv;
334-
struct dsa_switch *ds;
335-
336-
dl_priv = devlink_priv(dl);
337-
ds = dl_priv->ds;
333+
struct dsa_switch *ds = dsa_devlink_to_ds(dl);
338334

339335
if (!ds->ops->devlink_param_get)
340336
return -EOPNOTSUPP;
@@ -346,11 +342,7 @@ EXPORT_SYMBOL_GPL(dsa_devlink_param_get);
346342
int dsa_devlink_param_set(struct devlink *dl, u32 id,
347343
struct devlink_param_gset_ctx *ctx)
348344
{
349-
struct dsa_devlink_priv *dl_priv;
350-
struct dsa_switch *ds;
351-
352-
dl_priv = devlink_priv(dl);
353-
ds = dl_priv->ds;
345+
struct dsa_switch *ds = dsa_devlink_to_ds(dl);
354346

355347
if (!ds->ops->devlink_param_set)
356348
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)