@@ -133,21 +133,15 @@ EXPORT_SYMBOL_GPL(af_alg_release);
133133void af_alg_release_parent (struct sock * sk )
134134{
135135 struct alg_sock * ask = alg_sk (sk );
136- unsigned int nokey = ask -> nokey_refcnt ;
137- bool last = nokey && !ask -> refcnt ;
136+ unsigned int nokey = atomic_read (& ask -> nokey_refcnt );
138137
139138 sk = ask -> parent ;
140139 ask = alg_sk (sk );
141140
142- local_bh_disable ();
143- bh_lock_sock (sk );
144- ask -> nokey_refcnt -= nokey ;
145- if (!last )
146- last = !-- ask -> refcnt ;
147- bh_unlock_sock (sk );
148- local_bh_enable ();
141+ if (nokey )
142+ atomic_dec (& ask -> nokey_refcnt );
149143
150- if (last )
144+ if (atomic_dec_and_test ( & ask -> refcnt ) )
151145 sock_put (sk );
152146}
153147EXPORT_SYMBOL_GPL (af_alg_release_parent );
@@ -192,7 +186,7 @@ static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
192186
193187 err = - EBUSY ;
194188 lock_sock (sk );
195- if (ask -> refcnt | ask -> nokey_refcnt )
189+ if (atomic_read ( & ask -> refcnt ) )
196190 goto unlock ;
197191
198192 swap (ask -> type , type );
@@ -241,7 +235,7 @@ static int alg_setsockopt(struct socket *sock, int level, int optname,
241235 int err = - EBUSY ;
242236
243237 lock_sock (sk );
244- if (ask -> refcnt )
238+ if (atomic_read ( & ask -> refcnt ) != atomic_read ( & ask -> nokey_refcnt ) )
245239 goto unlock ;
246240
247241 type = ask -> type ;
@@ -308,12 +302,14 @@ int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern)
308302
309303 sk2 -> sk_family = PF_ALG ;
310304
311- if (nokey || ! ask -> refcnt ++ )
305+ if (atomic_inc_return_relaxed ( & ask -> refcnt ) == 1 )
312306 sock_hold (sk );
313- ask -> nokey_refcnt += nokey ;
307+ if (nokey ) {
308+ atomic_inc (& ask -> nokey_refcnt );
309+ atomic_set (& alg_sk (sk2 )-> nokey_refcnt , 1 );
310+ }
314311 alg_sk (sk2 )-> parent = sk ;
315312 alg_sk (sk2 )-> type = type ;
316- alg_sk (sk2 )-> nokey_refcnt = nokey ;
317313
318314 newsock -> ops = type -> ops ;
319315 newsock -> state = SS_CONNECTED ;
0 commit comments