Commit 212c10c3 authored by Jeremy Kerr's avatar Jeremy Kerr Committed by David S. Miller

mctp: Return new key from mctp_alloc_local_tag

In a future change, we will want the key available for future use after
allocating a new tag. This change returns the key from
mctp_alloc_local_tag, rather than just key->tag.
Signed-off-by: default avatarJeremy Kerr <jk@codeconstruct.com.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e311eb91
...@@ -532,14 +532,14 @@ static void mctp_reserve_tag(struct net *net, struct mctp_sk_key *key, ...@@ -532,14 +532,14 @@ static void mctp_reserve_tag(struct net *net, struct mctp_sk_key *key,
/* Allocate a locally-owned tag value for (saddr, daddr), and reserve /* Allocate a locally-owned tag value for (saddr, daddr), and reserve
* it for the socket msk * it for the socket msk
*/ */
static int mctp_alloc_local_tag(struct mctp_sock *msk, static struct mctp_sk_key *mctp_alloc_local_tag(struct mctp_sock *msk,
mctp_eid_t saddr, mctp_eid_t daddr, u8 *tagp) mctp_eid_t saddr,
mctp_eid_t daddr, u8 *tagp)
{ {
struct net *net = sock_net(&msk->sk); struct net *net = sock_net(&msk->sk);
struct netns_mctp *mns = &net->mctp; struct netns_mctp *mns = &net->mctp;
struct mctp_sk_key *key, *tmp; struct mctp_sk_key *key, *tmp;
unsigned long flags; unsigned long flags;
int rc = -EAGAIN;
u8 tagbits; u8 tagbits;
/* for NULL destination EIDs, we may get a response from any peer */ /* for NULL destination EIDs, we may get a response from any peer */
...@@ -549,7 +549,7 @@ static int mctp_alloc_local_tag(struct mctp_sock *msk, ...@@ -549,7 +549,7 @@ static int mctp_alloc_local_tag(struct mctp_sock *msk,
/* be optimistic, alloc now */ /* be optimistic, alloc now */
key = mctp_key_alloc(msk, saddr, daddr, 0, GFP_KERNEL); key = mctp_key_alloc(msk, saddr, daddr, 0, GFP_KERNEL);
if (!key) if (!key)
return -ENOMEM; return ERR_PTR(-ENOMEM);
/* 8 possible tag values */ /* 8 possible tag values */
tagbits = 0xff; tagbits = 0xff;
...@@ -591,18 +591,16 @@ static int mctp_alloc_local_tag(struct mctp_sock *msk, ...@@ -591,18 +591,16 @@ static int mctp_alloc_local_tag(struct mctp_sock *msk,
trace_mctp_key_acquire(key); trace_mctp_key_acquire(key);
*tagp = key->tag; *tagp = key->tag;
/* done with the key in this scope */
mctp_key_unref(key);
key = NULL;
rc = 0;
} }
spin_unlock_irqrestore(&mns->keys_lock, flags); spin_unlock_irqrestore(&mns->keys_lock, flags);
if (!tagbits) if (!tagbits) {
kfree(key); kfree(key);
return ERR_PTR(-EBUSY);
}
return rc; return key;
} }
/* routing lookups */ /* routing lookups */
...@@ -740,6 +738,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt, ...@@ -740,6 +738,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
struct mctp_sock *msk = container_of(sk, struct mctp_sock, sk); struct mctp_sock *msk = container_of(sk, struct mctp_sock, sk);
struct mctp_skb_cb *cb = mctp_cb(skb); struct mctp_skb_cb *cb = mctp_cb(skb);
struct mctp_route tmp_rt; struct mctp_route tmp_rt;
struct mctp_sk_key *key;
struct net_device *dev; struct net_device *dev;
struct mctp_hdr *hdr; struct mctp_hdr *hdr;
unsigned long flags; unsigned long flags;
...@@ -799,11 +798,16 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt, ...@@ -799,11 +798,16 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
goto out_release; goto out_release;
if (req_tag & MCTP_HDR_FLAG_TO) { if (req_tag & MCTP_HDR_FLAG_TO) {
rc = mctp_alloc_local_tag(msk, saddr, daddr, &tag); key = mctp_alloc_local_tag(msk, saddr, daddr, &tag);
if (rc) if (IS_ERR(key)) {
rc = PTR_ERR(key);
goto out_release; goto out_release;
}
/* done with the key in this scope */
mctp_key_unref(key);
tag |= MCTP_HDR_FLAG_TO; tag |= MCTP_HDR_FLAG_TO;
} else { } else {
key = NULL;
tag = req_tag; tag = req_tag;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment