summaryrefslogtreecommitdiff
path: root/drivers/net/ethernet/microchip/vcap/vcap_api.c
diff options
context:
space:
mode:
authorSteen Hegelund <steen.hegelund@microchip.com>2023-01-17 09:55:42 +0100
committerDavid S. Miller <davem@davemloft.net>2023-01-18 14:31:43 +0000
commit9579e2c271b4f2e6d24f61ff17abda2e9ce8cc85 (patch)
tree0bf45d3ce3f29743021000778df0fa333f1e84e2 /drivers/net/ethernet/microchip/vcap/vcap_api.c
parent975d86acaec78306a88b4575a2c6357b97c2c4db (diff)
downloadlinux-9579e2c271b4f2e6d24f61ff17abda2e9ce8cc85.tar.gz
linux-9579e2c271b4f2e6d24f61ff17abda2e9ce8cc85.tar.bz2
linux-9579e2c271b4f2e6d24f61ff17abda2e9ce8cc85.zip
net: microchip: sparx5: Add VCAP admin locking in debugFS
This ensures that the admin lock is taken before the debugFS functions starts iterating the VCAP rules. It also adds a separate function to decode a rule, which expects the lock to have been taken before it is called. Signed-off-by: Steen Hegelund <steen.hegelund@microchip.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/microchip/vcap/vcap_api.c')
-rw-r--r--drivers/net/ethernet/microchip/vcap/vcap_api.c60
1 files changed, 33 insertions, 27 deletions
diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c
index f1dc4fd6bb96..198c36627ba1 100644
--- a/drivers/net/ethernet/microchip/vcap/vcap_api.c
+++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c
@@ -2170,47 +2170,53 @@ void vcap_free_rule(struct vcap_rule *rule)
}
EXPORT_SYMBOL_GPL(vcap_free_rule);
-struct vcap_rule *vcap_get_rule(struct vcap_control *vctrl, u32 id)
+/* Decode a rule from the VCAP cache and return a copy */
+struct vcap_rule *vcap_decode_rule(struct vcap_rule_internal *elem)
{
- struct vcap_rule_internal *elem;
struct vcap_rule_internal *ri;
int err;
- ri = NULL;
-
- err = vcap_api_check(vctrl);
- if (err)
- return ERR_PTR(err);
- elem = vcap_lookup_rule(vctrl, id);
- if (!elem)
- return NULL;
- mutex_lock(&elem->admin->lock);
ri = vcap_dup_rule(elem, elem->state == VCAP_RS_DISABLED);
if (IS_ERR(ri))
- goto unlock;
+ return ERR_PTR(PTR_ERR(ri));
if (ri->state == VCAP_RS_DISABLED)
- goto unlock;
+ goto out;
err = vcap_read_rule(ri);
- if (err) {
- ri = ERR_PTR(err);
- goto unlock;
- }
+ if (err)
+ return ERR_PTR(err);
+
err = vcap_decode_keyset(ri);
- if (err) {
- ri = ERR_PTR(err);
- goto unlock;
- }
+ if (err)
+ return ERR_PTR(err);
+
err = vcap_decode_actionset(ri);
- if (err) {
- ri = ERR_PTR(err);
- goto unlock;
- }
+ if (err)
+ return ERR_PTR(err);
-unlock:
+out:
+ return &ri->data;
+}
+
+struct vcap_rule *vcap_get_rule(struct vcap_control *vctrl, u32 id)
+{
+ struct vcap_rule_internal *elem;
+ struct vcap_rule *rule;
+ int err;
+
+ err = vcap_api_check(vctrl);
+ if (err)
+ return ERR_PTR(err);
+
+ elem = vcap_lookup_rule(vctrl, id);
+ if (!elem)
+ return NULL;
+
+ mutex_lock(&elem->admin->lock);
+ rule = vcap_decode_rule(elem);
mutex_unlock(&elem->admin->lock);
- return (struct vcap_rule *)ri;
+ return rule;
}
EXPORT_SYMBOL_GPL(vcap_get_rule);