From nobody Thu Dec 18 19:04:26 2025 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 973EF235C01 for ; Thu, 11 Dec 2025 10:16:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765448188; cv=none; b=BDOneUPk7SOfeFBBnossnDTCTSzAYr6I+NAJQTEZVI3Do1Z0kt4vzcEbfKvsYP5HTkGanF2m5wQT7aZJtQTM83kJ+30mCEX8hAzmpGXC7W4iz6WbERDnHJs9BbgvsmO85zOcK3l/EyHXFitzzEaSoWRgwopiyhgk7IYhtp1+F7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765448188; c=relaxed/simple; bh=lieRE9PA+dpJ6RIsXJqjPjVzqfQJAKvnPAI211ulA7I=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=nDt3618Q1QO09PNgHNS6rdMnxjeTgWYD0joOy4lAdvXcr/7D3T9gwH7g/RnmNHs9XPclre8Sd7aLd91AmerOOXXxIvF2X0fdL8SO1uOAedEr2fiNluqfMzoxcvEym8efrvCPQoQfhLzRQ6Jw0a1D9my7cuA0pWLMQB5CUg+PUN8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=IAGDXYN+; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="IAGDXYN+" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1765448172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=0Nasadk8k5y+YUBWDSlZruWHH/AR3DkJCbP/5WhuApk=; b=IAGDXYN+sdIpHGsW28HbOHAxw6TZI5NB9H9oF/BffVYW+hkVR+yvB0M/lPNVHFr2SqMhsw 8i619fEtyuEGxJ+vy2p3BHWrpf/mi/XnRvMDcQbWQywlAu8CiNApTDspga46Put4TmxD0t wW0lbxuQ1MTHZLhaN5gj3ouywu92Nrc= From: Thorsten Blum To: Herbert Xu , "David S. Miller" Cc: Thorsten Blum , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] crypto: algapi - Use crypto_unregister_algs in crypto_register_algs Date: Thu, 11 Dec 2025 11:15:55 +0100 Message-ID: <20251211101555.802559-1-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Replace the for loop with a call to crypto_unregister_algs(). Return 'ret' immediately and remove the goto statement to simplify the error handling code. In crypto_unregister_algs(), unregister the algorithms in reverse order. Signed-off-by: Thorsten Blum --- crypto/algapi.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/crypto/algapi.c b/crypto/algapi.c index e604d0d8b7b4..ac4fc790687e 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -511,17 +511,13 @@ int crypto_register_algs(struct crypto_alg *algs, int= count) =20 for (i =3D 0; i < count; i++) { ret =3D crypto_register_alg(&algs[i]); - if (ret) - goto err; + if (ret) { + crypto_unregister_algs(algs, i); + return ret; + } } =20 return 0; - -err: - for (--i; i >=3D 0; --i) - crypto_unregister_alg(&algs[i]); - - return ret; } EXPORT_SYMBOL_GPL(crypto_register_algs); =20 @@ -529,7 +525,7 @@ void crypto_unregister_algs(struct crypto_alg *algs, in= t count) { int i; =20 - for (i =3D 0; i < count; i++) + for (i =3D count - 1; i >=3D 0; --i) crypto_unregister_alg(&algs[i]); } EXPORT_SYMBOL_GPL(crypto_unregister_algs); --=20 Thorsten Blum GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4