From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751905AbbDIHlt (ORCPT ); Thu, 9 Apr 2015 03:41:49 -0400 Received: from helcar.hengli.com.au ([209.40.204.226]:50068 "EHLO helcar.hengli.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751560AbbDIHlr (ORCPT ); Thu, 9 Apr 2015 03:41:47 -0400 Date: Thu, 9 Apr 2015 15:41:41 +0800 From: Herbert Xu To: Stephan Mueller Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] crypto: remove instance when test failed Message-ID: <20150409074141.GA4394@gondor.apana.org.au> References: <1461449.htSjBpksos@tachyon.chronox.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1461449.htSjBpksos@tachyon.chronox.de> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 09, 2015 at 09:36:03AM +0200, Stephan Mueller wrote: > > diff --git a/crypto/algapi.c b/crypto/algapi.c > index f1d0307..cfca1de 100644 > --- a/crypto/algapi.c > +++ b/crypto/algapi.c > @@ -533,6 +533,13 @@ int crypto_register_instance(struct crypto_template *tmpl, > if (IS_ERR(larval)) > goto unlock; > > + err = -EAGAIN; > + if (unlikely(!crypto_mod_get(&inst->alg))) { > + up_write(&crypto_alg_sem); > + crypto_unregister_instance(inst); > + goto err; > + } Just grab the reference count as soon as you enter the function and then you can unconditionally drop the reference count at the end. If you fail to grab it then just return an error and the caller will free it for you. Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt