From nobody Sun May 24 20:33:25 2026 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8818D31ED80 for ; Fri, 22 May 2026 23:01:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490904; cv=none; b=XdKXSvGMj+V0Y38Zsczz1B9ns0+gvaJPcuixUaZ1C7FaXTkXcdTQUNLlNzuipCcd7vVErKgQucz/McFoBl8WQja7nwuFRndKDZbyJUQKCbbMflwTdfM2cnds22oOqMNbhwZxqKCY3NJobxy72S1ztbcRJST3lJ+JEj7q5yH7v0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490904; c=relaxed/simple; bh=+GkEvCmZvKvSSf0kbXSJbp3bZrMZ4EaeOXstOxgGbmM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pIO9f/G143G9t6aXfDsiLMqIjN4xPQ7xGpudSBuGXkE7IDO36yGDBWQl08zoJKozgCcjZ+oP0o4arIo1UEW1b4ohqIpULGSayLGLhR/zZko+EEkuOWrtI02hnGkSGKUbYWeEU4Ey/Wsf8OGNNWY8tbMVcof2hd2mvLTBLCDCKr8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BPDjivtM; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BPDjivtM" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-44b7e8b65faso599509f8f.1 for ; Fri, 22 May 2026 16:01:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779490901; x=1780095701; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yLhglCCko+VFtBnuII+zHndGNGz8atU/cZ6T50d3HYU=; b=BPDjivtMTNk2lNkHwUDJIWSwEndYX5f+C8cUq1k8vRR/oXcc6UalT/kbwqdzdOjSgt qsYePMNiGv6UCf97x/5tTW8XVRqeN2InAoTeUVKRbUuN1eHUuFfwBeHomBpWNWBkC84O iofNlNgxQXEEQY/esV/IPRT22COVOzuNkIJHcZqwztlqfttBE1f2OxvELpoNfmSt9k5a 1DHO8oql55sZtHvFPKuX1GGfyI+Cc/TmXFk3Epl0EC1eNeukq5PFvx89ojyuq/27yROb OD+j3uXwQ3vcadL174FegwVYnzIw4UsFhNoSnxwLhwP2/oqLp7jge2/bPkJqFdsvzN/9 nTUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779490901; x=1780095701; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yLhglCCko+VFtBnuII+zHndGNGz8atU/cZ6T50d3HYU=; b=DkT4c1hKXdU+Wvqx38Uc4rGKErtvqDn7fIj+Oj2sZq1D5GaFQy25Av3WS15/1cu9DD BYzXvLLm2x6cpB2DG0VP1mizDB4PewxQcXjYqP9ZNRsWc7ykD/OoE0VZREAx+7V1Jtsn 4FS6f0+maUmui0JQYKIbES3oYmkc3aw3pFEhzm65UDFN/WQomhWZgcEdLhk2AI3WcITC TEiNAkypNaq/zybgCUYKRQTgXFcuTPgkPCDkL0QzyjvyVegai+qUc9hC+l7FSw1zrq3g AZ0PBtY88VhVHRTpRZzflYypumvRRXKbrqc4r/UBYPp8FBr/RyHT42RU5TaCek5u9yZW h5lA== X-Forwarded-Encrypted: i=1; AFNElJ+iusD4mXe6ZPrDbmzJLoB4bbOVKwhVEJ/gM2F6RLGjqD5TVfLgfAIgtjrD6VVr4CvR2dnKfCVf0YGBK+k=@vger.kernel.org X-Gm-Message-State: AOJu0YwiSFyXKRjMUEFrSz/bwBiDOsG5XyFGY7BdaPtBTGWshyTEcNOa pTp6aDgUWjDKlWym47wuRPgCkIGnOG8X/RO0o8f8As0RzCW/XXEtNJY7 X-Gm-Gg: Acq92OGtXs+obAHgNDol0xNXIKO8YjRml4GPbl8lkLeA6Lci50zPJ72HVyeHowZmzLb GcaMAgGoEOrpm8m276ABIVY+XBJ+3XviHj7nounQ1WCCTGOP/PRLOuQFrTZrumE2GEq9FwDbDXd B5INAcJCWJqvdetPQLWG8+HJ3vbTSI0p3HF/SLowXcgTWWhDplrarOm6c1ERfAQOQsUbemTFK0F 2Itk/0bo7+nbB7qjqmDd6AjME43AU34p3NqKgZ2m9NdIUHP4qD8HUbPBzP8oOxFS100notpPjL2 MYCLoOfHY1hU2Tvj3u9pQjRjIok/KJSNr6FQbnVo1TY8oh1HNlD5XqkDUe0fRyBKefijTmlT450 GpHuzxZgzBdS5z60za8z03NYgw5H+Iow4iVfmtoXH03m4LevAnOQBNTsbUmpAlRkmqhvfSuNzES nxBf4cN16eGrcYVTZSU55VMexPNO0tASVkOKxjI1C8SLhtyPEnR9CZo9TAa5uXxQvR+LlHKnc1B g== X-Received: by 2002:a05:600c:b96:b0:490:4923:aa3e with SMTP id 5b1f17b1804b1-4904923ab35mr20036195e9.7.1779490900958; Fri, 22 May 2026 16:01:40 -0700 (PDT) Received: from menon.v.cablecom.net (84-74-0-139.dclient.hispeed.ch. [84.74.0.139]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490456274ebsm67100265e9.15.2026.05.22.16.01.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 16:01:40 -0700 (PDT) From: Lothar Rubusch To: thorsten.blum@linux.dev, herbert@gondor.apana.org.au, davem@davemloft.net, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, tudor.ambarus@linaro.org, ardb@kernel.org, linusw@kernel.org, krzk+dt@kernel.org Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, l.rubusch@gmail.com Subject: [PATCH v4 01/12] crypto: atmel-ecc - fix use after free situation Date: Fri, 22 May 2026 23:01:23 +0000 Message-Id: <20260522230134.32414-2-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260522230134.32414-1-l.rubusch@gmail.com> References: <20260522230134.32414-1-l.rubusch@gmail.com> 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 Content-Type: text/plain; charset="utf-8" Fixes a possible race condition, when having multiple of such devices attached (identified by sashiko feedback). The Scenario: Thread A (Device 1 Probe): Successfully adds i2c_priv to the global list (Line 324). The lock is released. Thread B (An active crypto request): Concurrently calls atmel_ecc_i2c_client_alloc(). It scans the global list, sees Device 1, and assigns a crypto job to it. Thread A: Moves to line 332. crypto_register_kpp() fails (e.g., out of memory or name clash). Thread A: Enters the error path. It removes Device 1 from the list and frees the i2c_priv memory. Thread B: Is still actively trying to talk to the I2C hardware using the i2c_priv pointer it grabbed in Step 2. The memory is now gone. Result: Kernel crash (Use-After-Free). Fixes: 11105693fa05 ("crypto: atmel-ecc - introduce Microchip / Atmel ECC d= river") Signed-off-by: Lothar Rubusch --- drivers/crypto/atmel-ecc.c | 10 ++++++++++ drivers/crypto/atmel-i2c.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 9660f6426a84..94360d29f9f9 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -218,6 +218,8 @@ static struct i2c_client *atmel_ecc_i2c_client_alloc(vo= id) =20 list_for_each_entry(i2c_priv, &driver_data.i2c_client_list, i2c_client_list_node) { + if (!i2c_priv->ready) + continue; tfm_cnt =3D atomic_read(&i2c_priv->tfm_count); if (tfm_cnt < min_tfm_cnt) { min_tfm_cnt =3D tfm_cnt; @@ -322,20 +324,24 @@ static int atmel_ecc_probe(struct i2c_client *client) return ret; =20 i2c_priv =3D i2c_get_clientdata(client); + i2c_priv->ready =3D false; =20 spin_lock(&driver_data.i2c_list_lock); list_add_tail(&i2c_priv->i2c_client_list_node, &driver_data.i2c_client_list); + i2c_priv->ready =3D true; spin_unlock(&driver_data.i2c_list_lock); =20 ret =3D crypto_register_kpp(&atmel_ecdh_nist_p256); if (ret) { spin_lock(&driver_data.i2c_list_lock); + i2c_priv->ready =3D false; list_del(&i2c_priv->i2c_client_list_node); spin_unlock(&driver_data.i2c_list_lock); =20 dev_err(&client->dev, "%s alg registration failed\n", atmel_ecdh_nist_p256.base.cra_driver_name); + return ret; } else { dev_info(&client->dev, "atmel ecc algorithms registered in /proc/crypto\= n"); } @@ -347,6 +353,10 @@ static void atmel_ecc_remove(struct i2c_client *client) { struct atmel_i2c_client_priv *i2c_priv =3D i2c_get_clientdata(client); =20 + spin_lock(&driver_data.i2c_list_lock); + i2c_priv->ready =3D false; + spin_unlock(&driver_data.i2c_list_lock); + /* Return EBUSY if i2c client already allocated. */ if (atomic_read(&i2c_priv->tfm_count)) { /* diff --git a/drivers/crypto/atmel-i2c.h b/drivers/crypto/atmel-i2c.h index 72f04c15682f..e3b12030f9c4 100644 --- a/drivers/crypto/atmel-i2c.h +++ b/drivers/crypto/atmel-i2c.h @@ -129,6 +129,7 @@ struct atmel_ecc_driver_data { * @wake_token_sz : size in bytes of the wake_token * @tfm_count : number of active crypto transformations on i2c c= lient * @hwrng : hold the hardware generated rng + * @ready : hw client is ready to use * * Reads and writes from/to the i2c client are sequential. The first byte * transmitted to the device is treated as the byte size. Any attempt to s= end @@ -145,6 +146,7 @@ struct atmel_i2c_client_priv { size_t wake_token_sz; atomic_t tfm_count ____cacheline_aligned; struct hwrng hwrng; + bool ready; }; =20 /** --=20 2.39.5 From nobody Sun May 24 20:33:25 2026 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0875347BA7 for ; Fri, 22 May 2026 23:01:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490905; cv=none; b=U89dWPWJzj0jaSjf3wf1D8Lzk+/I9riUoeF+kGSGOJFxPstk9cfeCUjZnrWJ1Q4jYUg4w97ZFQ6ubW8tjcRzBGInV60z3Cmanwt3CsT0BF2sJmf53cBu9BKVV9GBnhoOEdCPjxu+x3iDUDkOD1bwnv9P3hh5HpJoHPRPpugOVew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490905; c=relaxed/simple; bh=nsNvnSO+5T+Nj0B0DFFIY3h9EpY8d8S0QFcXa60qh7g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cx3n8dj8W+CxoGnZCLnhlkBVS8ydy/UdZ0R5Kt2fgb7we2UZTkSKYi7H4bsI1+KMdaDl4tHwodxeDfv3Ke5WfUsmZ9Uh4ZJGK5xC8LUcGOAOgUhcEUuEHiKVS5O9XbM734CjOFsYzJWJZPVd9aujrnmfkjCDPKgncawYZB3C5jE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Irz/Ey2S; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Irz/Ey2S" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-4462f8d2488so745422f8f.0 for ; Fri, 22 May 2026 16:01:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779490902; x=1780095702; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r1V+f8VZ/BVcHT7ioxjC934CpqH8W/zfFq5YGMNwGR4=; b=Irz/Ey2SLQ8vE/94bKmOy9hXb4VobCz4iPKfEsn+8Cr53S1WXpBfOC7rf0y6PahkvU V52/LvIuzYHkSwYqyhODNChBy6VuJhSRnFod8tPyyTfjJHmtNMGMeeQdLIGYP9GHZssm /Ren52AalmsjvYhWNEMcF23k/OcJifpIQGkPqxifmtuB+aPlpbuIX+LTulIdByt9MRqz g9Weffuk5yguZ/7Q9wUd+z+ffAFLx3xvSohPe+OqFP0EZK7D53RpiCARnJg52UA+Wv6I dpw7wkkQUszmsrOQ8Qz4Xl/rOMsM54FmI+ep41OPzunB6ZJEsAFyx2Fqrhja2aINH5nm HCpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779490902; x=1780095702; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=r1V+f8VZ/BVcHT7ioxjC934CpqH8W/zfFq5YGMNwGR4=; b=DBDdi9DgIa8mOTW5GhtiSGJrdcZG3MLwzOdoBex0nxTtQAj022FF71S7zkCIr3EUl5 U4tGBIokaCspuOKJVPjcUjsVbrPxf/uMYzDyyCBZF5Qmkg17ZCpinwr9bJNGs8pl/afb nDFXi6l1Nqjm8L9Ciq5CEdHyUMPigVyg5mnhSaCAAA/aeQsUiy5Uk326afQiJITDgJeg ggHFN9YiKNt0KVjNHgkEQ3ACfJJDxmEV3Qtdi9G42BPtq6VyOo6YxJYpTVszCLGm0xra WFzENk7ZuQXtECSJzCOl/eTLIb1NmEFVCWeHY35tM4g6+gnDRovHJVoneB5wtq90e865 u/Xg== X-Forwarded-Encrypted: i=1; AFNElJ8InRW/PptvgNavcI9aGCRyM2jcDig1ccPZXCaDqt+gQHiZ4LGC4bFdho9H7eCOc5wZFHcX7dvbj54pumc=@vger.kernel.org X-Gm-Message-State: AOJu0Ywu+FLMJIdP569oh9P9geuQ1pNYTmfYz9DDZMd4SsjwUtnIM9GQ +1bpKd2tIiu5bZyXHl1iyhhaxhtmPAsDroRFwzNO1wX8RNOKcVvb5JJ1 X-Gm-Gg: Acq92OGcxNHI4+m2hVwev/9nzAepsA1pklDNncw1Q0Bk9KcwPXW7uVPxYfDnQsIkXAa 8pfUuAgI8TCSRtdDb6IRE2yMncpBcMtOytw893gKt99RMAplOtkZMu1saqPpcrCuLlW/PBF80pX npTGECSTFmw9EtzmFLLHWJxhAhkIde0nAI+VGGhmcXge5b0bGok5H8NtID6Rjah3KO53SVzY0X4 jdT2XBsmzQ6cLAxkjLYCAFrLehlwATPOzXLuCr42YGxZSbx6/j9+uw8FlNS2fWVXdm9l6+UKKfb fsuO2xH/2ZoWJyufeC8kqH3LeVhlcLeiqWGJnKRKdz6CcmS2Oi+vkgdUxSoCmMXa/WTYRgb/Uwd aiqt5DjWw7xOVhxcXznwg5mPQprEM4nLAUBNm6j8b693al3kRBcJXmyesgxF9H2LU7TeDjWWStf BHp/mpi1vT1tzq8QSOMzO3VbzNCpC1Y6/kz63SQr1xQr99KksNb2w5FcOSNne3a20gnnkT9Z1cm g== X-Received: by 2002:a05:600c:4fc7:b0:488:abe9:86 with SMTP id 5b1f17b1804b1-49042aec1demr39859485e9.7.1779490902091; Fri, 22 May 2026 16:01:42 -0700 (PDT) Received: from menon.v.cablecom.net (84-74-0-139.dclient.hispeed.ch. [84.74.0.139]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490456274ebsm67100265e9.15.2026.05.22.16.01.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 16:01:41 -0700 (PDT) From: Lothar Rubusch To: thorsten.blum@linux.dev, herbert@gondor.apana.org.au, davem@davemloft.net, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, tudor.ambarus@linaro.org, ardb@kernel.org, linusw@kernel.org, krzk+dt@kernel.org Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, l.rubusch@gmail.com Subject: [PATCH v4 02/12] crypto: atmel-ecc - fix multi-device kpp registration Date: Fri, 22 May 2026 23:01:24 +0000 Message-Id: <20260522230134.32414-3-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260522230134.32414-1-l.rubusch@gmail.com> References: <20260522230134.32414-1-l.rubusch@gmail.com> 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 Content-Type: text/plain; charset="utf-8" When multiple atmel-ecc hardware accelerator chips are attached to the same host, registering the same static kpp_alg structure multiple times corrupts internal fields used by the crypto core's algorithm list. This leads to immediate list corruption or kernel panics. Additionally, removing an individual device via sysfs while active crypto transformations (TFMs) are running triggers a use-after-free (UAF) bug. Because the device driver core lacks unbind error-handling paths, the underlying memory allocated via devm for the i2c_priv structure is freed unconditionally, leaving active transformation context pointers dangling. Fix these problems by implementing a centralized subsystem tracking matrix: 1. Introduce a global subsystem mutex and reference counter to ensure that the static 'atmel_ecdh_nist_p256' structure is only registered by the first probing device, and unregistered exclusively when the last supporting device unbinds. 2. Maintain per-device allocation tracking with 'tfm_count'. On remove, mark the device unready to halt load-balancing assignments, and block via a completion barrier until all pending transformation contexts bound to that specific physical hardware are freed. 3. Fix a critical re-registration race where a high-velocity unbind and subsequent re-probe cycles occur while crypto core asynchronous users are still purging. Establish a global 'atmel_ecc_unreg_active' state fence to force concurrent probing threads to execute a 2-second timeout bounded wait_for_completion_timeout() rather than unsafely mutating static lists. Fixes: 11105693fa05 ("crypto: atmel-ecc - introduce Microchip / Atmel ECC d= river") Signed-off-by: Lothar Rubusch --- drivers/crypto/atmel-ecc.c | 107 ++++++++++++++++++++++++++++--------- drivers/crypto/atmel-i2c.h | 1 + 2 files changed, 82 insertions(+), 26 deletions(-) diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 94360d29f9f9..005a9a3d919c 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -23,6 +23,11 @@ #include #include "atmel-i2c.h" =20 +static DEFINE_MUTEX(atmel_ecc_kpp_lock); +static int atmel_ecc_kpp_refcnt; +DECLARE_COMPLETION(atmel_ecc_unreg_done); +static bool atmel_ecc_unreg_active; + static struct atmel_ecc_driver_data driver_data; =20 /** @@ -243,7 +248,8 @@ static void atmel_ecc_i2c_client_free(struct i2c_client= *client) { struct atmel_i2c_client_priv *i2c_priv =3D i2c_get_clientdata(client); =20 - atomic_dec(&i2c_priv->tfm_count); + if (atomic_dec_and_test(&i2c_priv->tfm_count)) + complete(&i2c_priv->remove_done); } =20 static int atmel_ecdh_init_tfm(struct crypto_kpp *tfm) @@ -278,7 +284,8 @@ static void atmel_ecdh_exit_tfm(struct crypto_kpp *tfm) struct atmel_ecdh_ctx *ctx =3D kpp_tfm_ctx(tfm); =20 kfree(ctx->public_key); - crypto_free_kpp(ctx->fallback); + if (ctx->fallback) + crypto_free_kpp(ctx->fallback); atmel_ecc_i2c_client_free(ctx->client); } =20 @@ -317,6 +324,7 @@ static struct kpp_alg atmel_ecdh_nist_p256 =3D { static int atmel_ecc_probe(struct i2c_client *client) { struct atmel_i2c_client_priv *i2c_priv; + unsigned long timeout; int ret; =20 ret =3D atmel_i2c_probe(client); @@ -332,50 +340,97 @@ static int atmel_ecc_probe(struct i2c_client *client) i2c_priv->ready =3D true; spin_unlock(&driver_data.i2c_list_lock); =20 - ret =3D crypto_register_kpp(&atmel_ecdh_nist_p256); - if (ret) { - spin_lock(&driver_data.i2c_list_lock); - i2c_priv->ready =3D false; - list_del(&i2c_priv->i2c_client_list_node); - spin_unlock(&driver_data.i2c_list_lock); + mutex_lock(&atmel_ecc_kpp_lock); + /* + * For cases where the same/last such device is still in unregistering, + * and now re-registering (refcnt is 0, but completion still exists). + * Safely capture the pointer, drop the lock and sleep until it + * terminates upon completion or retry limit reached. + */ + while (atmel_ecc_unreg_active) { + mutex_unlock(&atmel_ecc_kpp_lock); + timeout =3D wait_for_completion_timeout(&atmel_ecc_unreg_done, + msecs_to_jiffies(2000)); + mutex_lock(&atmel_ecc_kpp_lock); + + if (timeout =3D=3D 0) { + spin_lock(&driver_data.i2c_list_lock); + i2c_priv->ready =3D false; + list_del(&i2c_priv->i2c_client_list_node); + spin_unlock(&driver_data.i2c_list_lock); + mutex_unlock(&atmel_ecc_kpp_lock); + + dev_err(&client->dev, "probe timed out, former driver instance not full= y deregistered\n"); + return -ETIMEDOUT; + } + } =20 - dev_err(&client->dev, "%s alg registration failed\n", - atmel_ecdh_nist_p256.base.cra_driver_name); - return ret; - } else { - dev_info(&client->dev, "atmel ecc algorithms registered in /proc/crypto\= n"); + if (atmel_ecc_kpp_refcnt =3D=3D 0) { + ret =3D crypto_register_kpp(&atmel_ecdh_nist_p256); + if (ret) { + spin_lock(&driver_data.i2c_list_lock); + i2c_priv->ready =3D false; + list_del(&i2c_priv->i2c_client_list_node); + spin_unlock(&driver_data.i2c_list_lock); + mutex_unlock(&atmel_ecc_kpp_lock); + + dev_err(&client->dev, "%s alg registration failed\n", + atmel_ecdh_nist_p256.base.cra_driver_name); + return ret; + } } + atmel_ecc_kpp_refcnt++; + mutex_unlock(&atmel_ecc_kpp_lock); =20 + dev_info(&client->dev, "atmel ecc algorithms registered in /proc/crypto\n= "); return ret; } =20 static void atmel_ecc_remove(struct i2c_client *client) { struct atmel_i2c_client_priv *i2c_priv =3D i2c_get_clientdata(client); + bool trigger_unreg =3D false; =20 spin_lock(&driver_data.i2c_list_lock); i2c_priv->ready =3D false; spin_unlock(&driver_data.i2c_list_lock); =20 - /* Return EBUSY if i2c client already allocated. */ - if (atomic_read(&i2c_priv->tfm_count)) { - /* - * After we return here, the memory backing the device is freed. - * That happens no matter what the return value of this function - * is because in the Linux device model there is no error - * handling for unbinding a driver. - * If there is still some action pending, it probably involves - * accessing the freed memory. - */ - dev_emerg(&client->dev, "Device is busy, expect memory corruption.\n"); - return; + /* + * The Linux crypto core automatically blocks until all active + * transformations utilizing that specific algorithm structure + * are fully freed and closed. + */ + mutex_lock(&atmel_ecc_kpp_lock); + atmel_ecc_kpp_refcnt--; + + if (atmel_ecc_kpp_refcnt =3D=3D 0) { + trigger_unreg =3D true; + atmel_ecc_unreg_active =3D true; + reinit_completion(&atmel_ecc_unreg_done); } + mutex_unlock(&atmel_ecc_kpp_lock); =20 - crypto_unregister_kpp(&atmel_ecdh_nist_p256); + if (atomic_read(&i2c_priv->tfm_count)) + wait_for_completion(&i2c_priv->remove_done); =20 spin_lock(&driver_data.i2c_list_lock); list_del(&i2c_priv->i2c_client_list_node); spin_unlock(&driver_data.i2c_list_lock); + + /* + * The driver registers once an algorithm, but maintains a list of + * supporting i2c devices. Unregister the algorithm only, when the last + * supporting device deregisters. Use completions to assure no inflight + * TFMs and/or re-registering driver probe will then loose memory + * by over initializing the global statics. + */ + if (trigger_unreg) { + crypto_unregister_kpp(&atmel_ecdh_nist_p256); + mutex_lock(&atmel_ecc_kpp_lock); + atmel_ecc_unreg_active =3D false; + complete_all(&atmel_ecc_unreg_done); + mutex_unlock(&atmel_ecc_kpp_lock); + } } =20 static const struct of_device_id atmel_ecc_dt_ids[] =3D { diff --git a/drivers/crypto/atmel-i2c.h b/drivers/crypto/atmel-i2c.h index e3b12030f9c4..b320559e50eb 100644 --- a/drivers/crypto/atmel-i2c.h +++ b/drivers/crypto/atmel-i2c.h @@ -146,6 +146,7 @@ struct atmel_i2c_client_priv { size_t wake_token_sz; atomic_t tfm_count ____cacheline_aligned; struct hwrng hwrng; + struct completion remove_done; bool ready; }; =20 --=20 2.39.5 From nobody Sun May 24 20:33:25 2026 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED0C637DEBE for ; Fri, 22 May 2026 23:01:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490906; cv=none; b=ufm6pKHZr74x/YwFLlOC/iv0UY+RsTDHMdnC6yYKWf5M5LE1oxR4f/LAiQhHN74Tz4YxA27p9rIoXF++PI/N7WsOhfIT8l/rvA4hHLlomWLs+0XK0N/vp6ahG6zroQ2w4RW1GvHSJTSrQAUVwuaKj3sRiLC+kiIigqiNnveUVmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490906; c=relaxed/simple; bh=WT68BEzTx1l29XJyggZ3cUigYYl0bj5fpGSnTqow5sY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PVzVpGVBTwzli69jKoFreZCaVKz/vBqHPLnYFhBSKHWXcD8gAD+bS66L7sNLAZTbbeQtxR6oRfEjw6Cbigw/IY2c6nVtVR4fp+MhOwH3IDt7QJBWiuvZBtfJwh9uLQggX5Is6+rD8tO0+1ucM0kBfj3AfG9w71gM3YXBoPeQIas= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=s3ej08MZ; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s3ej08MZ" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-43fe5574cb9so598203f8f.3 for ; Fri, 22 May 2026 16:01:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779490903; x=1780095703; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=h4hFlokuo7P4aQz1gprT7L1r7NqG5LdGzkVv8qgvK+0=; b=s3ej08MZnmsJCHBndcquvjzw/tLVMBDZCyPG4BE+EU6+5WuPnB7y+YOuQM6xJlKTe2 caffvG0wV923GgewcB9UWvHtlb3kwuosNeOD6ZDPhyNHsL70SJfjZZ4hWK9O5xRS9Yse 32lBjH1WdlAlH4bnfb+gUqmR7qFQcn1l+FLiPLXzSnj7k0QTXYELBAHkNuewrLncgMM3 99d8wBjoYRvAzUPw8SHBetotEzghWp3WXlyAxXHXfPFAbuRkFXFNDAoCCIAcMAu639X/ 1mbY+G5MiteVyx3YSN2F0n73w+efUHySQfQmRqUW1xEEYHojj0FVl3EwYUW6NKuFuovq QxYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779490903; x=1780095703; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=h4hFlokuo7P4aQz1gprT7L1r7NqG5LdGzkVv8qgvK+0=; b=SD15rr+Sn8h2TbUXzb4yx2izEtpiIISmXZKnHHwPlVLUTrKbFu26ZCYG6P0XLUoxCy /2GO9vH4oy+oi4/CsmZBHgAflC6UBgb/nEWKUXgtroVeFL2ddWQ3xhFDiudLn3fpvreT 8/tt6ftH+trEpDY4Dxe0c9/CRnfIxWc1CStpbDNnVmrJgk/LJOJaO2FBi71MyJieXjF/ clP++d0BETC7aX1ep24Kb0uFLEJIqDxvW5BRYF0eeiV+xcsnBfE9o5W7LkULYraJe7iP 6R5fVKSbD0J4Ez+IkO1ivoTPiaa9TxnXrnXWerRrjTmWD3ugVEUP8k3S9mFyMS2VPNUg +YPg== X-Forwarded-Encrypted: i=1; AFNElJ/O2CVCBBd/KT4zAX6DWR485oR3IFv7OeglVHPDGMWt27oxDF8o7rSalR59esMbxZ0dm8S/Rs5ymrMQj3A=@vger.kernel.org X-Gm-Message-State: AOJu0Yyuu+rK7z6g5RT07mMJuWJcosKRWXGFLGFWIJJ3bAhMQspnHSnh KzRXMah425KP7jUZP1ER6zo+TeMNEbPbHxms1SKeslFyqqSl1sJyyO5P X-Gm-Gg: Acq92OFmr0Jx7AThh4oz72kFoMP4n0ov3FrErp6kacimOTdpEG07mjHura2Sbufjkwe fyxZhg/HoYZpCPQPCAbdGNhbo6j4io5s0zkBUixXNvoGBPemdXJpd5y1JCrhr9JnHz+lyYMnoSm 3ghbabAeuY4TQ76GcqLsoK6AXz7yEl01Ku5Q6lN5j12uiVLqEmb/vLxHC1SlmeI/77cwHjo0dfA M/4JZ0UrzUIBxYcbIo3WxqHhiYFcvCvI7MGgQW2Ytv38ka0E0uVxqb03+O2+uuCZ+xobD325vzJ RGOpwTUgLEZEOBYnnnSgR+oY+5imQR9Cs+aUtOlbdt0D3QkCW8HoZfyWjaxxqhk2MfrIlDMOiDB v4M2geZxpVUQxag3+VQJPpM+4xM2YO+SBTT98k/7Yqw4rZCGN+A4pjqnbzj4q/of/a1t14H5dmZ JU+9IgEyxc1c6AC7WcsFf/oTllkVnWkjPtdrroQWfUQ75zXC1khMeqageYtG+72z8= X-Received: by 2002:a05:600c:35cf:b0:488:7e7b:dbc2 with SMTP id 5b1f17b1804b1-490426bb7f1mr44203705e9.3.1779490903199; Fri, 22 May 2026 16:01:43 -0700 (PDT) Received: from menon.v.cablecom.net (84-74-0-139.dclient.hispeed.ch. [84.74.0.139]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490456274ebsm67100265e9.15.2026.05.22.16.01.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 16:01:42 -0700 (PDT) From: Lothar Rubusch To: thorsten.blum@linux.dev, herbert@gondor.apana.org.au, davem@davemloft.net, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, tudor.ambarus@linaro.org, ardb@kernel.org, linusw@kernel.org, krzk+dt@kernel.org Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, l.rubusch@gmail.com Subject: [PATCH v4 03/12] crypto: atmel-sha204a - fix heap info leak on I2C transfer failure Date: Fri, 22 May 2026 23:01:25 +0000 Message-Id: <20260522230134.32414-4-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260522230134.32414-1-l.rubusch@gmail.com> References: <20260522230134.32414-1-l.rubusch@gmail.com> 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 Content-Type: text/plain; charset="utf-8" When a non-blocking read operation is requested, the driver dynamically allocates memory to track asynchronous transfer status. If the underlying I2C transmission fails, atmel_sha204a_rng_done() logs a rate-limited warning but incorrectly proceeds to cache the pointer to this uninitialized buffer inside the rng->priv data field anyway. On subsequent execution passes, atmel_sha204a_rng_read_nonblocking() detects the stale rng->priv value, skips executing a hardware data read, and copies up to 32 bytes of uninitialized kernel heap data from this garbage memory pool straight back into the system's hwrng data stream. Fix this information disclosure vector by immediately releasing the allocated asynchronous work data buffer and explicitly clearing the tracking pointer context whenever an I2C transaction returns a non-zero error status. Additionally, duplicate the tfm counter decrement within the new error path to ensure the reference counter is properly released before executing the early return, maintaining the driver's availability for subsequent requests. Fixes: da001fb651b0 ("crypto: atmel-i2c - add support for SHA204A random nu= mber generator") Signed-off-by: Lothar Rubusch --- drivers/crypto/atmel-sha204a.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/atmel-sha204a.c b/drivers/crypto/atmel-sha204a.c index 12eb85b57380..33e5a66b843c 100644 --- a/drivers/crypto/atmel-sha204a.c +++ b/drivers/crypto/atmel-sha204a.c @@ -31,10 +31,15 @@ static void atmel_sha204a_rng_done(struct atmel_i2c_wor= k_data *work_data, struct atmel_i2c_client_priv *i2c_priv =3D work_data->ctx; struct hwrng *rng =3D areq; =20 - if (status) + if (status) { dev_warn_ratelimited(&i2c_priv->client->dev, "i2c transaction failed (%d)\n", status); + kfree(work_data); + rng->priv =3D 0; + atomic_dec(&i2c_priv->tfm_count); + return; + } =20 rng->priv =3D (unsigned long)work_data; atomic_dec(&i2c_priv->tfm_count); --=20 2.39.5 From nobody Sun May 24 20:33:25 2026 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FA4239060C for ; Fri, 22 May 2026 23:01:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490913; cv=none; b=YqO1Fqn8YvMroys669OJJtHkPZFLvcHvxJaQ9WYcnAm+x+yJM8fGCQXQpQO7PktBNBlh6/9NzQ5w6E667IbYdL8MuFxnHsQiHIVtZsE9GX1zPET65IgzdAbD5iBVJwjm70WGz0N0q8LxhcWPzB3LuoSxGBdoSFE1Z+2JsyRcE4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490913; c=relaxed/simple; bh=zLuyHNJ9QkrKL+o3IkuZN3AWnRs1fdyM8NUHUTCahUA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Pkt+3Xum8VZhXnAI+qexEt6nGfz83v1M2klUaw5ODNNemqAxWYCHlh9nmpIUNIeQvrx2MI5ONZ5z+DUsMl3XTmlh/qDyd62bGEHWgovliV/JOjeoWdoLfm1dMXnSCGGccBnHfXATM0QpBOqL5Br8jIgBbkP7h42ExK8zTjsA1nQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Re3LuG8v; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Re3LuG8v" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-44a7c719151so592673f8f.0 for ; Fri, 22 May 2026 16:01:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779490906; x=1780095706; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VdPdyRKOtuD7Jq2T1rwTu6Wes+v7LpW2HMOrPNqb248=; b=Re3LuG8vaR1NwZUdM8I7+ExQIOS3iyPIjc/gDMLLncMuR0vJJ2HNIKYuMkqrHexs1z ddb6go7qQbMN0OZc6sd53nQweNKChG2y1pkEk6QAbCkGBkACXXv3yOkbiQF3gxLX4cjM OrhwBigWLUuwFqxVUhz65dve9OizYVqH+QqNpb2gsQvDy2N4fsVyIsF6TdiyXExovGlC PxUo0aKzeGkDd0xiwGxZLeybwwydWISsIWvVSMQbwS3WO5pqqPVRwzqMXID35o0RXvf0 FQXc14WbTcMrs3fZC5pIhrnjtjtH2DRCM/SLRuvyAfeXuCaJON0mLApK9N5hV/DDFZ3t bzQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779490906; x=1780095706; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=VdPdyRKOtuD7Jq2T1rwTu6Wes+v7LpW2HMOrPNqb248=; b=A+OPCCEHzuKC40byhVjis3+t01avcCwxc5oKE3Z8tD1SrILy87TnXERb/DDsBgig6H o0gC4soJS72Okcv1ayPCcB4C5Jg5Q1X0ei5g9Gg65QjN4SeBpg2Yp1giPELGhhu4OXJm xciIC9hhx/W1NcASiebcd8eACLpKcX+ZaRKwFsdKswrA6ZN7MwJb9Uuas1iuqNAWE8wV ARz6Z601STVDpMzESOgx5pZQxEsDFWVoxyTlW6goyPUsuImKVlB4cRr6itrTufS4jy/w CyydKBGEkh3YWQ1Yo06hPuC+7St3o+wLS+cazBe87nTvVGtUMucoNLLKjOzfvYUqwaLq OUmg== X-Forwarded-Encrypted: i=1; AFNElJ9Qdr9X2EcG3vrqaqo6l2WMxscKVHy501LlPp6uYGZEl87EFspZTBBDnJ2f5cgXwkGtQ7PkCAdDGfn75QI=@vger.kernel.org X-Gm-Message-State: AOJu0YxS/IWGndAQYWwwoR9vEXyiDSWMVeD415yDch8oxgjViLSFjIGG aJMgM6ZG6SN+rD8ccvjXM8LhER/Hb+EIjwyOWfkHAvpkw0wxp19EjIJ/ X-Gm-Gg: Acq92OEc4isP8ACjbPoQdYv8wN7VqUDVMyd5wZBcpx7xGyXtIwYM4WxukvtdaN2pmTQ trM3A9uRFAZjKkAQ4YCzm/Qmf+tSCbZdaPq8bxXc6ubDYd9t489EWhvOgx2bCLFeofmBjpX7zwZ SgKEfMLZxU6eco3kZkeFRPWae2W4OVgY8kILMI57qH1KQ6GWwAIk6S0XVGAY5ms/5dd3AMcg303 zUU/Am89klmzXq4HkKSMldlhqi/rmwlQOyc7qp1zaNFtdV/8qguztfInWMn6BeBahsPVpBeJqk+ Vo2JMhehXllBqKZAkfTgDa55IdWmkHRrovb+/kGyK7l4Lfw8pWvScn6WicnDJ+iDcNpUaNEp+/H iigc6h5XRd7l5Fq/XURi5wSHzG55l7m2tqaIoYDXovPZcfS+sts1T08w6vo0jkt0jDTq17s20I+ RhwZ6Gpihdi8IayYwLGtt17/EYG3JEEdBWsDXAS9fWdZD4GiApHoq/IiZ9c5mKUIg= X-Received: by 2002:a05:600c:c4a3:b0:485:c456:5e4f with SMTP id 5b1f17b1804b1-490422529aemr38152485e9.0.1779490905632; Fri, 22 May 2026 16:01:45 -0700 (PDT) Received: from menon.v.cablecom.net (84-74-0-139.dclient.hispeed.ch. [84.74.0.139]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490456274ebsm67100265e9.15.2026.05.22.16.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 16:01:44 -0700 (PDT) From: Lothar Rubusch To: thorsten.blum@linux.dev, herbert@gondor.apana.org.au, davem@davemloft.net, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, tudor.ambarus@linaro.org, ardb@kernel.org, linusw@kernel.org, krzk+dt@kernel.org Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, l.rubusch@gmail.com Subject: [PATCH v4 04/12] crypto: atmel-ecc - rename driver_data before moving it into atmel-i2c Date: Fri, 22 May 2026 23:01:26 +0000 Message-Id: <20260522230134.32414-5-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260522230134.32414-1-l.rubusch@gmail.com> References: <20260522230134.32414-1-l.rubusch@gmail.com> 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 Content-Type: text/plain; charset="utf-8" Rename the local driver_data instance to atmel_i2c_mgmt in preparation for moving the shared I2C client management infrastructure into the atmel-i2c core driver in a subsequent change. No functional changes intended. Signed-off-by: Lothar Rubusch --- drivers/crypto/atmel-ecc.c | 39 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 005a9a3d919c..d12a9dbe45a7 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -28,7 +28,7 @@ static int atmel_ecc_kpp_refcnt; DECLARE_COMPLETION(atmel_ecc_unreg_done); static bool atmel_ecc_unreg_active; =20 -static struct atmel_ecc_driver_data driver_data; +static struct atmel_ecc_driver_data atmel_i2c_mgmt; =20 /** * struct atmel_ecdh_ctx - transformation context @@ -214,14 +214,14 @@ static struct i2c_client *atmel_ecc_i2c_client_alloc(= void) int min_tfm_cnt =3D INT_MAX; int tfm_cnt; =20 - spin_lock(&driver_data.i2c_list_lock); + spin_lock(&atmel_i2c_mgmt.i2c_list_lock); =20 - if (list_empty(&driver_data.i2c_client_list)) { - spin_unlock(&driver_data.i2c_list_lock); + if (list_empty(&atmel_i2c_mgmt.i2c_client_list)) { + spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); return ERR_PTR(-ENODEV); } =20 - list_for_each_entry(i2c_priv, &driver_data.i2c_client_list, + list_for_each_entry(i2c_priv, &atmel_i2c_mgmt.i2c_client_list, i2c_client_list_node) { if (!i2c_priv->ready) continue; @@ -239,7 +239,7 @@ static struct i2c_client *atmel_ecc_i2c_client_alloc(vo= id) client =3D min_i2c_priv->client; } =20 - spin_unlock(&driver_data.i2c_list_lock); + spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); =20 return client; } @@ -334,11 +334,11 @@ static int atmel_ecc_probe(struct i2c_client *client) i2c_priv =3D i2c_get_clientdata(client); i2c_priv->ready =3D false; =20 - spin_lock(&driver_data.i2c_list_lock); + spin_lock(&atmel_i2c_mgmt.i2c_list_lock); list_add_tail(&i2c_priv->i2c_client_list_node, - &driver_data.i2c_client_list); + &atmel_i2c_mgmt.i2c_client_list); i2c_priv->ready =3D true; - spin_unlock(&driver_data.i2c_list_lock); + spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); =20 mutex_lock(&atmel_ecc_kpp_lock); /* @@ -352,12 +352,11 @@ static int atmel_ecc_probe(struct i2c_client *client) timeout =3D wait_for_completion_timeout(&atmel_ecc_unreg_done, msecs_to_jiffies(2000)); mutex_lock(&atmel_ecc_kpp_lock); - if (timeout =3D=3D 0) { - spin_lock(&driver_data.i2c_list_lock); + spin_lock(&atmel_i2c_mgmt.i2c_list_lock); i2c_priv->ready =3D false; list_del(&i2c_priv->i2c_client_list_node); - spin_unlock(&driver_data.i2c_list_lock); + spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); mutex_unlock(&atmel_ecc_kpp_lock); =20 dev_err(&client->dev, "probe timed out, former driver instance not full= y deregistered\n"); @@ -368,10 +367,10 @@ static int atmel_ecc_probe(struct i2c_client *client) if (atmel_ecc_kpp_refcnt =3D=3D 0) { ret =3D crypto_register_kpp(&atmel_ecdh_nist_p256); if (ret) { - spin_lock(&driver_data.i2c_list_lock); + spin_lock(&atmel_i2c_mgmt.i2c_list_lock); i2c_priv->ready =3D false; list_del(&i2c_priv->i2c_client_list_node); - spin_unlock(&driver_data.i2c_list_lock); + spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); mutex_unlock(&atmel_ecc_kpp_lock); =20 dev_err(&client->dev, "%s alg registration failed\n", @@ -391,9 +390,9 @@ static void atmel_ecc_remove(struct i2c_client *client) struct atmel_i2c_client_priv *i2c_priv =3D i2c_get_clientdata(client); bool trigger_unreg =3D false; =20 - spin_lock(&driver_data.i2c_list_lock); + spin_lock(&atmel_i2c_mgmt.i2c_list_lock); i2c_priv->ready =3D false; - spin_unlock(&driver_data.i2c_list_lock); + spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); =20 /* * The Linux crypto core automatically blocks until all active @@ -413,9 +412,9 @@ static void atmel_ecc_remove(struct i2c_client *client) if (atomic_read(&i2c_priv->tfm_count)) wait_for_completion(&i2c_priv->remove_done); =20 - spin_lock(&driver_data.i2c_list_lock); + spin_lock(&atmel_i2c_mgmt.i2c_list_lock); list_del(&i2c_priv->i2c_client_list_node); - spin_unlock(&driver_data.i2c_list_lock); + spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); =20 /* * The driver registers once an algorithm, but maintains a list of @@ -459,8 +458,8 @@ static struct i2c_driver atmel_ecc_driver =3D { =20 static int __init atmel_ecc_init(void) { - spin_lock_init(&driver_data.i2c_list_lock); - INIT_LIST_HEAD(&driver_data.i2c_client_list); + spin_lock_init(&atmel_i2c_mgmt.i2c_list_lock); + INIT_LIST_HEAD(&atmel_i2c_mgmt.i2c_client_list); return i2c_add_driver(&atmel_ecc_driver); } =20 --=20 2.39.5 From nobody Sun May 24 20:33:25 2026 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59800386C2C for ; Fri, 22 May 2026 23:01:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490912; cv=none; b=MnZ6fzj9doihDNpbsuaLnGAVx9A99+F8JBgx4JiCydoVummcALBADZSLsIX2ZsVseoeI1pJ5/5r/eq8eGPRs2zI5h4jbp7Z1A9UevX+e0p9kCJxVnNmtlOyLkFypXaiLnLBaDb6awFlU7DpXIntbCZ4XkwlxcNGtk19CXzwnvH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490912; c=relaxed/simple; bh=DR3UsQTK+NNUD6IDUcIq7ubGv0mDBUfxKOqc2gCxbaM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oqBBH/e9A1aIyp/U/X3jolEK8oRq/MkFQ2qUTBIMeSsTxWpL2tPM0LIRR7W3H+9U1aZiPrQ7I4zUaKgsuXZFPgU6AeWuGZ3tKpUS8Aot8a+P7tZNZoWV76pfeVwg7lN25XhcTLYJtjI7m7MaEdZLBTNQT6mQdceT8x74wYN5vu0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ld2kjpY/; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ld2kjpY/" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-43fe5574cb9so598213f8f.3 for ; Fri, 22 May 2026 16:01:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779490907; x=1780095707; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Sb5MNahpjnP/vNHphvg5+I/zYJ16o/85c7lKSptPrvw=; b=ld2kjpY/j6ANda6f55zLNjiMf+Es3knUpF2KnqR5kUQuiSJyBBLtxrWrqtOwt1Tdoj 0bBBvrV4oJ9v1MXuxivn1/EZSEeUyIDnxEWEdPkf3m1eiNHcYQLGR87r3AfhUwXRHlO2 oQJq/QcIlurqjr50OtrWXTIudpGFNpc2CiHZfbSvKwqY3MZSdmDbtjrYB+iGVSQC97mh m9ZCLIu+8sYwDnzO4MB6RgY42nqDAIY24bF1HKSagS+ljxLoFhUp1ZJORSpQjnMigkbg JKiwUahHUkhliGyx2i+8vzgpuW+ipkAfefaO0HnMC71lhbynF1dkVagV0R7hKE9JkpSu ADKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779490907; x=1780095707; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Sb5MNahpjnP/vNHphvg5+I/zYJ16o/85c7lKSptPrvw=; b=Ptyh1Bf4ZI1JATGH1rTRUkIqupZYwbTEx3AUM55LOXxKDh+7k5n4ruU+wVyzyepgnL F+6Pc5qOSqDr6Hb/HQ8XVK4qKoWwZq24JS68xa4TBQF0OuQntyV00lPeFm6BJ903x/1C 3lm6WFqR9AgJlUqXqnIvl7yUjxJBcm9it1/OHhsEChly3GrhSFgAiBgqn/M90jcA+jWO DCLm2hpz+alX9rBIBJC1mpC+J6+3gUD/nghWwkYkDTpWmZgzEao/IqqidiHjzqeAGCBW qoaqkhoHfojb89mCB9YDSofPn1dxVecspPJfgepiXHpfuCxi9qJI4xDWDohs/Qx6ylg0 bPhA== X-Forwarded-Encrypted: i=1; AFNElJ+u7TgIbomUzFYJiIMxfLEJhfKgbEVfvXyjXQEtkz48lxv7CCyu6szrOy5H/FGulKNJBsnqdF4tq6wx16c=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2Tt31hk2Qg4XDDMgZxjHuuhw9SCsB3ckSMN9k104u5VZrwXZ8 XfipaJNy5oS3+34ynXi9jhzAqU2crGHuyyWovM5qn3osiOhJq6gMgb8E X-Gm-Gg: Acq92OH9ncBPBt0XobeMegLzIXq59NiY5StbOgBG8nlaMQ8VQPlFJtRyuhNrRzqha68 jY64Vas6Gio2fqNFzbqty1bCNwpObGPTBWM0XNMJ7QXphBkSe1Y3/I8sRH/tBxyDddti5nfOMQT Ko33exDm8tumhdyP7L/ICfLDqDnVIVE3RAX7OXOnSE40vldD71PYYEww9te/CT0qhl3yIN1mj5V 8ZG5/AKPcAnu80lZI7a4uzL4lQgsW3z7isP/UzNlzln6H5KYdVA6cKy4mhLID+/lw0VWGMiXEal uzQaqwQ1GHz+dBkshvCOkGaxQ9nm/6rE3UrcYNtJyHOMRPADyAiZo5PQp94DPAHTeooS3AwzbEk dxMz3JKYMTKwqA3Yo2wenHHfTxd9pSfcMtbftc70q5CObhSw6jEZgxHj7KpYMZWtvNtHbn1lBwO frOjPEypAhhWEt5nrPzYJe+eQIsU06paUUnT1Q9fGiaLXvLcLyZbomI6/8B1e0kfVc0CDTXtfTU Q== X-Received: by 2002:a05:600c:a09:b0:48e:65f3:a950 with SMTP id 5b1f17b1804b1-4904248ad8cmr37124745e9.1.1779490906790; Fri, 22 May 2026 16:01:46 -0700 (PDT) Received: from menon.v.cablecom.net (84-74-0-139.dclient.hispeed.ch. [84.74.0.139]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490456274ebsm67100265e9.15.2026.05.22.16.01.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 16:01:46 -0700 (PDT) From: Lothar Rubusch To: thorsten.blum@linux.dev, herbert@gondor.apana.org.au, davem@davemloft.net, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, tudor.ambarus@linaro.org, ardb@kernel.org, linusw@kernel.org, krzk+dt@kernel.org Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, l.rubusch@gmail.com Subject: [PATCH v4 05/12] crypto: atmel - rename atmel_ecc_driver_data to atmel_i2c_client_mgmt Date: Fri, 22 May 2026 23:01:27 +0000 Message-Id: <20260522230134.32414-6-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260522230134.32414-1-l.rubusch@gmail.com> References: <20260522230134.32414-1-l.rubusch@gmail.com> 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 Content-Type: text/plain; charset="utf-8" Rename struct atmel_ecc_driver_data to atmel_i2c_client_mgmt to reflect its generic role in shared I2C client tracking and locking. A subsequent change will move the client management infrastructure into the atmel-i2c core driver. No functional changes intended. Signed-off-by: Lothar Rubusch --- drivers/crypto/atmel-ecc.c | 2 +- drivers/crypto/atmel-i2c.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index d12a9dbe45a7..d6ae113c45df 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -28,7 +28,7 @@ static int atmel_ecc_kpp_refcnt; DECLARE_COMPLETION(atmel_ecc_unreg_done); static bool atmel_ecc_unreg_active; =20 -static struct atmel_ecc_driver_data atmel_i2c_mgmt; +static struct atmel_i2c_client_mgmt atmel_i2c_mgmt; =20 /** * struct atmel_ecdh_ctx - transformation context diff --git a/drivers/crypto/atmel-i2c.h b/drivers/crypto/atmel-i2c.h index b320559e50eb..660ca861b705 100644 --- a/drivers/crypto/atmel-i2c.h +++ b/drivers/crypto/atmel-i2c.h @@ -115,7 +115,7 @@ struct atmel_i2c_cmd { #define ECDH_PREFIX_MODE 0x00 =20 /* Used for binding tfm objects to i2c clients. */ -struct atmel_ecc_driver_data { +struct atmel_i2c_client_mgmt { struct list_head i2c_client_list; spinlock_t i2c_list_lock; } ____cacheline_aligned; --=20 2.39.5 From nobody Sun May 24 20:33:25 2026 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3966A82866 for ; Fri, 22 May 2026 23:01:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490913; cv=none; b=VnVR2p96Sv/a0WT/9ogiGZ7OBjUWD6NI1sbME/Hbcf3pi/zNEQs7wK0IxU8W3c9w3UFHO74epL0Ej8ITfB0afd+6UYseIJhPt99jKM0e+tW6u6yIkND6iQHrDdXxCnjvlSTLmL5DfPa/oJGR9+0W4on7kfihQkqeuMwOSnB6bIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490913; c=relaxed/simple; bh=lLAfj7LcfoRlLXCDmBp3fzB+hmnVRfZLW5UuPbQYpsw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Eacsqx03hoymypu+0Pat8Pn9kVxnxMzhcsWXdAU1ZW4y1lyAg/kBhJKXDA1CGsYFIaeB97mD7RXJmTcSZlMZTDJIWngHJQPTieGACRo5sCeZelaq71IcE2q4GqMEtRh1s/cUvu8xvdnFY9UlCLBA8/sKBkYYkvN3/sJnLQAfa+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EDQTLb1D; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EDQTLb1D" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-45ea5252a63so249709f8f.1 for ; Fri, 22 May 2026 16:01:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779490909; x=1780095709; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MSCRzF6jccIrpW3KuBs+JWgBL0z6wfFkzmIVCZCEAZo=; b=EDQTLb1DX9XO1KCn2z49CzSX7sf0eEy1ZO9Z9WYBkR6jHTqgjHULk/x1y86dfAMFhr e0CmSxlktBHveULUtYQmwn4YFKG9jTpY50rLJYxON5KnbtWPNq3O9+KeGF4ezRaZcdOU xfwZ2oE6LTXWMjW11jD7NPKkRMvWKRSuMqnwXzfsxukK1tnio/WFEH33rAmhPrQxT/Xj yblyLARY1EXF22kGWdQpr5owtmYWq0PQHqwmNCgJmADDthI844k9JMGOg4UQSqhjM8Y8 olU76I+5xeC8+qz79+zYQl5amjkFrx+OlbHmd/IfvT5rEGs3UuGZR6LkNeWQx8ymTL9V VAjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779490909; x=1780095709; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=MSCRzF6jccIrpW3KuBs+JWgBL0z6wfFkzmIVCZCEAZo=; b=X2UN8Xsa1Lzae+95iNsrhNhfoqvP75KBpF7r2mHB8yzSS0dHYfrqpn1V5Raol+l2Zz 6r13cFWpRWsT5ZSCSF3HiVd39TMXEmVQmqowNB0H7AT9K1b6I4PRL7nMbj1bO+zr29/F BTopCE7NvwhEMf+ESOaTJo4fRZ7KJxGbwGEakfe5HEiiloiqJmBL10855za/x9/VtEyA FgIuN7+13KrEAz2VPGUM4EgctPOuKiopA540dTmL48RTMLcJX9Nuq3KIfB9SolXMCnus 0bbCYbc2+ST4MZppqZA2Mu/8bnGxLUJzRt6WIOdJ6lI58yUG4i8fdeNoegqpZ8cYasi6 Z92w== X-Forwarded-Encrypted: i=1; AFNElJ9xom1fD1CE+7kcbjFgaNx5ihvK1me4zikENsbzw346swpowOtHycjeAEzlf+I0Dbi42ZHnnNT290gZC2w=@vger.kernel.org X-Gm-Message-State: AOJu0YzJr3uRLXaL3JZJpEkPQ7ex37iSg4N5ZJDiDQ/haHWI+SQX9pKj A/3vXjgJNuxdQMOqW07KlKcD/lxrbfPF99Sa900/HN/o2MGnmqFfvR8l X-Gm-Gg: Acq92OFhrDtdURjLvK6JEbSibmC6d50qGEV5c6ygVERO1QEnIn/oDuzpcboehq0XE/A wB5QdLCEs57aowFUL7zEYBGEgrsnLHh+Od2/8hEp7cTxWHlZRz94+fNlUcFYH54vruVmliJBAcV XqIlxfUNEoIJDlZ0PXIZCr7A/qz3r9IQjW0mvMFiimN9dHs4YO6x07eRPumo8eeMXOXTmSOcU5B BSLSMD3oe+QHtTrT15+aAM7YtyFeMfvry93fBOV7tZTvUzEfO9Iqe2MF4rchjmmVR9BEPdI0prL BaY1oH7eCOEO6spkZYkjkgJ3T5Zgs6B54bg4To7Fsu3mfFYe6j4bPQWIPEvwioF/uTxKuOSgMLQ P+grL5haIF45bmD6weaN3Pu9Rb2aLGYoTFcMe9PQZphKR00l6x2pkoEdzHBQLpYw1RUsNXBmzLS zjLMQ7z2tK3O5iH+/jnpc1fIIxblKOFwLB1agMVLOmJLasNqOBwRJlLpKarSIw1whO2Km2wLmS2 g== X-Received: by 2002:a05:600c:1f8f:b0:490:3cb8:b853 with SMTP id 5b1f17b1804b1-49042cf87abmr35801335e9.7.1779490908611; Fri, 22 May 2026 16:01:48 -0700 (PDT) Received: from menon.v.cablecom.net (84-74-0-139.dclient.hispeed.ch. [84.74.0.139]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490456274ebsm67100265e9.15.2026.05.22.16.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 16:01:48 -0700 (PDT) From: Lothar Rubusch To: thorsten.blum@linux.dev, herbert@gondor.apana.org.au, davem@davemloft.net, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, tudor.ambarus@linaro.org, ardb@kernel.org, linusw@kernel.org, krzk+dt@kernel.org Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, l.rubusch@gmail.com Subject: [PATCH v4 06/12] crypto: atmel-i2c - move client management instance into core Date: Fri, 22 May 2026 23:01:28 +0000 Message-Id: <20260522230134.32414-7-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260522230134.32414-1-l.rubusch@gmail.com> References: <20260522230134.32414-1-l.rubusch@gmail.com> 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 Content-Type: text/plain; charset="utf-8" Move the global 'atmel_i2c_mgmt' tracking instance out of the ECC driver and into the atmel-i2c core library. This change consolidates the shared I2C client infrastructure into a central core driver. This centralization allows both the ECC and upcoming SHA204A driver modules to access and reference a unified, common device-management context. As part of this relocation, replace the explicit runtime initialization calls inside the module init block with static, compile-time macros (__SPIN_LOCK_UNLOCKED and LIST_HEAD_INIT). Export the tracking structure via EXPORT_SYMBOL_GPL() to make it available to dependent sub-modules. No functional change intended. Signed-off-by: Lothar Rubusch --- drivers/crypto/atmel-ecc.c | 4 ---- drivers/crypto/atmel-i2c.c | 6 ++++++ drivers/crypto/atmel-i2c.h | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index d6ae113c45df..1ae9c52812df 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -28,8 +28,6 @@ static int atmel_ecc_kpp_refcnt; DECLARE_COMPLETION(atmel_ecc_unreg_done); static bool atmel_ecc_unreg_active; =20 -static struct atmel_i2c_client_mgmt atmel_i2c_mgmt; - /** * struct atmel_ecdh_ctx - transformation context * @client : pointer to i2c client device @@ -458,8 +456,6 @@ static struct i2c_driver atmel_ecc_driver =3D { =20 static int __init atmel_ecc_init(void) { - spin_lock_init(&atmel_i2c_mgmt.i2c_list_lock); - INIT_LIST_HEAD(&atmel_i2c_mgmt.i2c_client_list); return i2c_add_driver(&atmel_ecc_driver); } =20 diff --git a/drivers/crypto/atmel-i2c.c b/drivers/crypto/atmel-i2c.c index ff19857894d0..a42b0ea30033 100644 --- a/drivers/crypto/atmel-i2c.c +++ b/drivers/crypto/atmel-i2c.c @@ -21,6 +21,12 @@ #include #include "atmel-i2c.h" =20 +struct atmel_i2c_client_mgmt atmel_i2c_mgmt =3D { + .i2c_list_lock =3D __SPIN_LOCK_UNLOCKED(atmel_i2c_mgmt.i2c_list_lock), + .i2c_client_list =3D LIST_HEAD_INIT(atmel_i2c_mgmt.i2c_client_list), +}; +EXPORT_SYMBOL_GPL(atmel_i2c_mgmt); + static const struct { u8 value; const char *error_text; diff --git a/drivers/crypto/atmel-i2c.h b/drivers/crypto/atmel-i2c.h index 660ca861b705..82321c35c21f 100644 --- a/drivers/crypto/atmel-i2c.h +++ b/drivers/crypto/atmel-i2c.h @@ -119,6 +119,7 @@ struct atmel_i2c_client_mgmt { struct list_head i2c_client_list; spinlock_t i2c_list_lock; } ____cacheline_aligned; +extern struct atmel_i2c_client_mgmt atmel_i2c_mgmt; =20 /** * atmel_i2c_client_priv - i2c_client private data --=20 2.39.5 From nobody Sun May 24 20:33:25 2026 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E52823D2A1 for ; Fri, 22 May 2026 23:01:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490913; cv=none; b=tICf4zpUQnQbVflASbH5pcY1jPB4oD1lIgmupglyVB1TWM+NFooC/oHwdcUwX6FGaMAHksWV9UiRoQw0Y5lInpYx2KFMmaKImMtWWRrA+hvVmaiIQQ9In/qgCKa5jCz8pEoZYoNA2xEA+uFFc5AmbzNmkdvBGcZQvjhZT1WSfVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490913; c=relaxed/simple; bh=aGTNuggTjsMi8IqadRKQSxAgL+xgnUXNuaYDOu+9S3Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=T+SD1txkPipaAjRBZ3N9nGqgbmZLTtxX7V/BUd58DUmufmLxzp/Rmv10WzREjiWHs32QiYXEXE22ib3XJFtNKr0zAGHCrL1xNuTvLl37WFrcs3h7ZAnSdUCsgMeJZsWYxVdMkmxvEYs5yNYSOItHlNhp5VaI3OY4GKTLUYYes88= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gEHn/7dg; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gEHn/7dg" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-43d7dab87e1so1005686f8f.3 for ; Fri, 22 May 2026 16:01:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779490910; x=1780095710; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6/v/8SwP1OMGt6X7FpwGNnrj1hJ2WLb5Kzz8Rnl3t28=; b=gEHn/7dggFo1CGr6ragbo2NKF02riePaZz+CxT2CFWmkFlqponO+gJqYX06lNDDMNs sJIn5bIflj2etpvmwFeDkPvzU8eh6vvWxCFuy1oZHKhQsb03rsBdSBKy5cYJasmfBh3R UcLyUispQ/qZTDNTnzEHJgUEGV7jlqIBiGEXx/9xcGjiNBgKJIGQuJ+hV+KVxAf+4xJ7 t77NFygLqhNDB5h2ZD1n0C/4hq+tXatJH5tP/BUOXsj6qNqqg0nU4OeiJDWgQsdN1RNI EYOzwiGdOl0oeYJ8uwrmWeaU24px7HvorIayvwBU1G58xhv1E11fJAjkyYOjuBGwz6h3 RZTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779490910; x=1780095710; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6/v/8SwP1OMGt6X7FpwGNnrj1hJ2WLb5Kzz8Rnl3t28=; b=qEklHj591WjYMRDBFajMqsdlpKvgp3lbY/X7AsDDjkiilw7qCKSgkPQAA5JnBoprgx Pez3boTWXefopBxbhwpsyDxYrVit6eM3Y0Ef6ssQcb2Fxy1cfIP2RUInTr+byaHIoUO6 2nv6ifV2oypY9CpAfOPhiNnhAWfwbdfEMS5AaT44/k9KkJVia0sXVwBEUzBNXpXBeRqE oG81jReODlJClAFV2kiKkljeeGDRs0y5BA505+BUPJNkA2652V3C5JZ4HM+N5VVMDM53 Suz5scPO0FWF+6Sun1B6xE/Hhwf0NFQegSe7scCRGIfHyaEZw/pstOky1o2Aqdhvn4AB wl+Q== X-Forwarded-Encrypted: i=1; AFNElJ+0G4qESZnvqvrWFcLbB9ZqesA+BXO7llI948OmG9Yy7PIIRZIDkI35g7by0/Msr7roZNL4RrBihc35BJo=@vger.kernel.org X-Gm-Message-State: AOJu0YwIkToxJTSxTgjqzhhlHvDZ8zK/EZQOQekYRlthxKruM1vuaFYe aFu3xVecxFBHPv3C2/P5sm3jc9eqFaWcDvK3etSEprwXRpk+yt7TppYjT3em8Q== X-Gm-Gg: Acq92OGBSo6NQYl4yDP1O/MV5cPDuEtt3oujUGoTTwsLB1JaMIOLOP00j73DNXrY2NT tVy+qfa3qCJ0UExkNdv/fGKjuikTi6aFqB3z+35XmSeWAmDS2+Kf3vKNb+pUnIwjkKL3loJEoBz /tGU4S5jt/YyjHcuc6k0JcBaMmacXxtvxUoGWu6VjTGMDHhburDoA64lCR6AM3+PIMA8q9l2Rxm hCt7RA7/rBuChgUN+umBBqNUbeRL5GKpqaEKm4FdKrr4GQaaDqQkojhrMnJMIHrE74Mr6qU6ACq tMZH0Lp7znoySP7+ySij2aEQFe+zNUuZMqX5L+DHQiK5XwiQdmVHtVB8sbvjl4CidfuFdpBzJdv 3kvYu1yxpl7m97hD2ZKgwwUnvNCHtdh+PLmd2AQJWWXkyaMWYrWsjVELMKsONchP8PdFZ/y1pl4 7skTLB/DtlsxLRogyocnfPuQos6q53oLNNeGpJMGT1zujZBdBAHN0uSwGqW7q/IsU= X-Received: by 2002:a05:600c:3547:b0:490:3d3c:22f1 with SMTP id 5b1f17b1804b1-490428e6d5dmr38350275e9.7.1779490909725; Fri, 22 May 2026 16:01:49 -0700 (PDT) Received: from menon.v.cablecom.net (84-74-0-139.dclient.hispeed.ch. [84.74.0.139]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490456274ebsm67100265e9.15.2026.05.22.16.01.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 16:01:49 -0700 (PDT) From: Lothar Rubusch To: thorsten.blum@linux.dev, herbert@gondor.apana.org.au, davem@davemloft.net, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, tudor.ambarus@linaro.org, ardb@kernel.org, linusw@kernel.org, krzk+dt@kernel.org Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, l.rubusch@gmail.com Subject: [PATCH v4 07/12] crypto: atmel-i2c - introduce shared teardown helpers and fix queue flush Date: Fri, 22 May 2026 23:01:29 +0000 Message-Id: <20260522230134.32414-8-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260522230134.32414-1-l.rubusch@gmail.com> References: <20260522230134.32414-1-l.rubusch@gmail.com> 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 Content-Type: text/plain; charset="utf-8" Introduce atmel_i2c_deactivate_client() and atmel_i2c_unregister_client() helpers in the atmel-i2c core library to modularize client teardown. This encapsulates common client state tracking and list manipulation operations. Convert the ECC driver's error recovery and device removal paths to utilize these new helpers, ensuring consistent execution ordering when modifying device-readiness states and deleting linked-list nodes. Additionally, migrate the atmel_i2c_flush_queue() call out of the module exit path. It now runs inside the core unregistration helper. Export both new tracking symbols via EXPORT_SYMBOL_GPL() to match the existing core driver licensing standard. Signed-off-by: Lothar Rubusch --- drivers/crypto/atmel-ecc.c | 25 ++++++------------------- drivers/crypto/atmel-i2c.c | 20 ++++++++++++++++++++ drivers/crypto/atmel-i2c.h | 3 +++ 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 1ae9c52812df..e6d3e6574251 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -351,12 +351,8 @@ static int atmel_ecc_probe(struct i2c_client *client) msecs_to_jiffies(2000)); mutex_lock(&atmel_ecc_kpp_lock); if (timeout =3D=3D 0) { - spin_lock(&atmel_i2c_mgmt.i2c_list_lock); - i2c_priv->ready =3D false; - list_del(&i2c_priv->i2c_client_list_node); - spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); - mutex_unlock(&atmel_ecc_kpp_lock); - + atmel_i2c_deactivate_client(i2c_priv); + atmel_i2c_unregister_client(i2c_priv); dev_err(&client->dev, "probe timed out, former driver instance not full= y deregistered\n"); return -ETIMEDOUT; } @@ -365,12 +361,8 @@ static int atmel_ecc_probe(struct i2c_client *client) if (atmel_ecc_kpp_refcnt =3D=3D 0) { ret =3D crypto_register_kpp(&atmel_ecdh_nist_p256); if (ret) { - spin_lock(&atmel_i2c_mgmt.i2c_list_lock); - i2c_priv->ready =3D false; - list_del(&i2c_priv->i2c_client_list_node); - spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); - mutex_unlock(&atmel_ecc_kpp_lock); - + atmel_i2c_deactivate_client(i2c_priv); + atmel_i2c_unregister_client(i2c_priv); dev_err(&client->dev, "%s alg registration failed\n", atmel_ecdh_nist_p256.base.cra_driver_name); return ret; @@ -388,9 +380,7 @@ static void atmel_ecc_remove(struct i2c_client *client) struct atmel_i2c_client_priv *i2c_priv =3D i2c_get_clientdata(client); bool trigger_unreg =3D false; =20 - spin_lock(&atmel_i2c_mgmt.i2c_list_lock); - i2c_priv->ready =3D false; - spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); + atmel_i2c_deactivate_client(i2c_priv); =20 /* * The Linux crypto core automatically blocks until all active @@ -410,9 +400,7 @@ static void atmel_ecc_remove(struct i2c_client *client) if (atomic_read(&i2c_priv->tfm_count)) wait_for_completion(&i2c_priv->remove_done); =20 - spin_lock(&atmel_i2c_mgmt.i2c_list_lock); - list_del(&i2c_priv->i2c_client_list_node); - spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); + atmel_i2c_unregister_client(i2c_priv); =20 /* * The driver registers once an algorithm, but maintains a list of @@ -461,7 +449,6 @@ static int __init atmel_ecc_init(void) =20 static void __exit atmel_ecc_exit(void) { - atmel_i2c_flush_queue(); i2c_del_driver(&atmel_ecc_driver); } =20 diff --git a/drivers/crypto/atmel-i2c.c b/drivers/crypto/atmel-i2c.c index a42b0ea30033..db818ce55033 100644 --- a/drivers/crypto/atmel-i2c.c +++ b/drivers/crypto/atmel-i2c.c @@ -354,6 +354,26 @@ static int device_sanity_check(struct i2c_client *clie= nt) return ret; } =20 +void atmel_i2c_deactivate_client(struct atmel_i2c_client_priv *i2c_priv) +{ + spin_lock(&atmel_i2c_mgmt.i2c_list_lock); + i2c_priv->ready =3D false; + spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); +} +EXPORT_SYMBOL_GPL(atmel_i2c_deactivate_client); + +void atmel_i2c_unregister_client(struct atmel_i2c_client_priv *i2c_priv) +{ + spin_lock(&atmel_i2c_mgmt.i2c_list_lock); + if (!list_empty(&i2c_priv->i2c_client_list_node)) + list_del_init(&i2c_priv->i2c_client_list_node); + spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); + + /* don't sleep inside spin locks */ + atmel_i2c_flush_queue(); +} +EXPORT_SYMBOL_GPL(atmel_i2c_unregister_client); + int atmel_i2c_probe(struct i2c_client *client) { struct atmel_i2c_client_priv *i2c_priv; diff --git a/drivers/crypto/atmel-i2c.h b/drivers/crypto/atmel-i2c.h index 82321c35c21f..07fd2248e20b 100644 --- a/drivers/crypto/atmel-i2c.h +++ b/drivers/crypto/atmel-i2c.h @@ -193,4 +193,7 @@ void atmel_i2c_init_genkey_cmd(struct atmel_i2c_cmd *cm= d, u16 keyid); int atmel_i2c_init_ecdh_cmd(struct atmel_i2c_cmd *cmd, struct scatterlist *pubkey); =20 +void atmel_i2c_deactivate_client(struct atmel_i2c_client_priv *i2c_priv); +void atmel_i2c_unregister_client(struct atmel_i2c_client_priv *i2c_priv); + #endif /* __ATMEL_I2C_H__ */ --=20 2.39.5 From nobody Sun May 24 20:33:25 2026 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A05433F8A6 for ; Fri, 22 May 2026 23:01:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490913; cv=none; b=NkHxqC3t649Gl4YOrp68BSY55HBKRMraMXqia7xlLcUFa5OPwbGOTZLvj/HLlaFDm+a122gB8Fen8gpeQi9YhYc5rwFaZakbCmdsXChKbDDwt1SoblvWn3sSugdhjutOQhVYMiwt6Uuo+kZd4M6KHodlLJgU4IXn+cp57p4ZVkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490913; c=relaxed/simple; bh=y6gvHfSWjliLefCmgznPVVvqnmtLA4twQizeFJStDhY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Bb6bv6Q4mDwrDI4O3kT73FbOFBaccuMm8aGCrJGpg7NiUZ2yhiqlJKvNNCnmgrVAvYDEabi2YqxrJkSMd9QghwEnUXAXge5KlW78nK8OpfMbHTQTpsbDHC0RODd7+Skh5AIuLVuQLd4TJBi9fEMrIxE24nB1Bd0RRcXiILvNmUQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZS3+Q6cW; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZS3+Q6cW" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-43d7dab87e1so1005691f8f.3 for ; Fri, 22 May 2026 16:01:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779490911; x=1780095711; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sANsrQm+/9rauufhu0v06B+xNWc+JsN4ukD6rF0U2uA=; b=ZS3+Q6cW5gHEIPk3HLSaVF/s83zyQ4OHoS0npkU436zTHNJVg8jd9MtK8A2lTjBHPd Flibtm69WpdK9Sq5LyjjklcupXZmudDVTT/fSow+zFvk/XSEGt+DRn6XpF7s3I2oOkoy LP6dSM8NIb6HLNUJmiORF4qnR6PHJ0uByrGR/OvCLAVo3Mxfko2+i5AHdlrfIBMvsNqw 3gjtyLVZpA12xz/8dVfLj5e/1WLR12EAgI/eOOXZ2S8f6Hn65XIlm9arrIGSPA1y72h5 V1q1/iQCCE+dEeFpqf7kLdGmnjzP2M3RsP03/gSq+q4zCJIm+h6VA+pDH/PyOUccPBTp B3uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779490911; x=1780095711; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=sANsrQm+/9rauufhu0v06B+xNWc+JsN4ukD6rF0U2uA=; b=oHeGvXZhuMB4DBE4TATYvyy4Rn6zh76CrZ1skuwxpj64PZwSEUTF7x5sQtANi4dCBW J1oqKCMswsAzVNEPz7dFVSghyTv/vXbbnsBvsyJZGTlv+oVWnhL56T1jgrk+VM9+cG1X Cxwfoo/nK2hQqfmFq9RUYp6rXTIgZzNO1QbHAdELM6Ip/Mdb2X1gPqWgQTpM1/VuzrIt oGc+6GmQCiIjhYi12Cu0/02zXsCmYUCps/vngbbjp7ctcaM/ayPRVls0zHTz3UzWJrSO F+kmheyFkYKJF0Us9u/+ghHNg4zOtNpffS+1GmukIdpeTFbAwrp5BA7JoyRWv1uCpkdJ 5bjA== X-Forwarded-Encrypted: i=1; AFNElJ9s3gViVa1ejjfwTsgFXPupAHjz1TksnbbY33JGTh19J3YhA1t8R4fAB11RdHu7v4ZUUvGL4kmbjSA/rx4=@vger.kernel.org X-Gm-Message-State: AOJu0YxEgVvwIhduObVRl5DcT5l5sGKErTMMD0XEoowDytUDz7OMbu0x +jcUsecmJl7pV7nQ0x351T8Tg+CV6z/fksNU0ZU/Elg2fle9AdxOwt3k X-Gm-Gg: Acq92OEX05tU2S9+lgpc1xp4LEMCzKzp+ARKT0Md1lSgjWBYoLE/CW44M48F+JeT8cX FItAu1tgXVUuvwzAZzIIzur/YQ0pGOnQgbiQVKqycJI8y8O/oNxAmVie2luYdrTwcbVjr+m5QR4 dLaxd3nFLx649dybt5NbqHLUOVNB+OxK6Ha0agqqDM0rKMnsreZWwxHTCzzzsuSO8boDA86m0GN AuFauJDJbwVzmF0F2m+L9NVIRLheuCvXtbYMx6WFLoA1mWEy7YAdQ1VSeMj9QC3Sxt36y0mBeBc tpu6d1JeZK6GQCZoBjp3LYnDp14DWgJ3kl6jvfhAsFd+O9Klhi2+1paNrDl+5O7F+xKiSTKys4b o6gSmd9PGGWXkBKR1f8JudYdgKvDH1XNfc5qT/nR97N4G6GwrDPMyxU6BgwL2M8GYWZcRpkLVdh cuMz3HG4+dgsQnzdfBrhIkkE42dk6R2r3RZZQh5zrTewz/sX10t4cgXuNavPWhORT4/1fSPDZnW g== X-Received: by 2002:a05:600c:4fc7:b0:488:a797:f099 with SMTP id 5b1f17b1804b1-490428cb441mr41259825e9.3.1779490910803; Fri, 22 May 2026 16:01:50 -0700 (PDT) Received: from menon.v.cablecom.net (84-74-0-139.dclient.hispeed.ch. [84.74.0.139]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490456274ebsm67100265e9.15.2026.05.22.16.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 16:01:50 -0700 (PDT) From: Lothar Rubusch To: thorsten.blum@linux.dev, herbert@gondor.apana.org.au, davem@davemloft.net, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, tudor.ambarus@linaro.org, ardb@kernel.org, linusw@kernel.org, krzk+dt@kernel.org Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, l.rubusch@gmail.com Subject: [PATCH v4 08/12] crypto: atmel-ecc - switch to module_i2c_driver Date: Fri, 22 May 2026 23:01:30 +0000 Message-Id: <20260522230134.32414-9-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260522230134.32414-1-l.rubusch@gmail.com> References: <20260522230134.32414-1-l.rubusch@gmail.com> 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 Content-Type: text/plain; charset="utf-8" Remove custom boilerplate module configuration code and convert the module init/exit paths to use the modern module_i2c_driver() helper macro. This shortens and simplifies driver initialization. Custom structure setup is no longer required here since management tracking context initialization was already safely moved into the atmel-i2c core library module. Signed-off-by: Lothar Rubusch --- drivers/crypto/atmel-ecc.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index e6d3e6574251..d2490693a198 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -442,18 +442,7 @@ static struct i2c_driver atmel_ecc_driver =3D { .id_table =3D atmel_ecc_id, }; =20 -static int __init atmel_ecc_init(void) -{ - return i2c_add_driver(&atmel_ecc_driver); -} - -static void __exit atmel_ecc_exit(void) -{ - i2c_del_driver(&atmel_ecc_driver); -} - -module_init(atmel_ecc_init); -module_exit(atmel_ecc_exit); +module_i2c_driver(atmel_ecc_driver); =20 MODULE_AUTHOR("Tudor Ambarus"); MODULE_DESCRIPTION("Microchip / Atmel ECC (I2C) driver"); --=20 2.39.5 From nobody Sun May 24 20:33:25 2026 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5BBF3876C1 for ; Fri, 22 May 2026 23:01:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490916; cv=none; b=B40yVgSd5+eFtLzFZX++2FWnk8KakdKcyGm89yzbmuzwRqMgrKnmQE/CZnc/2RS/683hNCg445n3+IJQW7+Tb9C1asxWWJzq8NpF3IwmHgyBf23Ctp8o9yI45cMZZ5PmUgUDiLLSVrRtNDuaZQCyEFQysaFPn09Pygy9dlr3qlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490916; c=relaxed/simple; bh=dAoA7wZBGyBgkuKW+C/Nr5C9eNtwpsHK4EAheW9cuBU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JjA8RO3WSF5aWFScHQghDHAUWZY/5tRLcLIT3hianDo5QW2hh+2yLat6nfc4Dm/1JyMLCKpOE1852wnQo1EU4H61GX56+5N1r3pr0lQoX42zwLfYcXSPTGRmLT1l5DKrVeQkj9OWtfZ/W0Gvgn9KQoELeitmvQPJMDD2oUHnc1M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TkTjOjzF; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TkTjOjzF" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-44ad87a57f6so612372f8f.2 for ; Fri, 22 May 2026 16:01:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779490912; x=1780095712; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MfLcGNZgqb+V+WxyXEnSFJnXPIqON2cg7XA1OePB+Uk=; b=TkTjOjzFpwxChgb3MpeuJR+7f+lWr54PndPLHzy0T5qeXMBg7su+fdnkOF21IooLhR pvZOe0NJZmPr6RTBA2a8has8R6E4Cnv4RnEveY+BB5qAu6dD/SSMmKFExEcLvEEsasBO mBFtPFexQ/MEJtJjl0f62RCosHbWhRzCtnAgOAUGaOjsr7tQyzV7tTnYPYEggA+y1vCR L08QN7DErzZbsORkj1LL5ZX54M1NUOsj0WoaitiFaGwKch3W7vZokubsDoCXT+fT0Wu+ WxpXJ0gOO8yQYJDHpIHSGs6yJFytfN6CiEykMYffHwqQuDgmh0FTVgr2f63Uxh/4/az/ XK4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779490912; x=1780095712; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=MfLcGNZgqb+V+WxyXEnSFJnXPIqON2cg7XA1OePB+Uk=; b=cLyRZuXzGrBFfmMv4PnXlzTaKwpqo8rbPD/qjIoQRvp4IJK1kUedbl1ofXlGrIIp+/ 45ETVtqLIHiYpPNdqcKnwskZwzpMhHjC3Ss9uiDPwwHXeqQAW2PAzPMuF9W3g3ODAMKE 11i3jH9r2TmDG+BxHtrCxQkz6lq1yFckCAQSJVPSxhcNyOGXD5l1NZAD7xk6MCPtxKuZ OEXypdxtV5WYkxKM4kuRJi3Y8DMTSo17s7Mrks/PKQx4vczqoPVK/JdoIwi8+YV3J+21 Zf2+TOAUS3nFvELZ+AdbFPbhwKyc1tbjwLGEYAdKK9dpAMm3swdiMtLVCgQAB+DMyhNJ jRCw== X-Forwarded-Encrypted: i=1; AFNElJ/kJOF6RpkMqbd50bjaHNMLqX3FCLp7BbG24iLte7S3bH603d1QbH3uwetwT9YSvphaGp7QwSCCf1zcI94=@vger.kernel.org X-Gm-Message-State: AOJu0YzIF+FV6od4WWzbgSbAiSlu/9ofBlucl+R8eM4y7c2cxNP+aST4 Mn0l74mGPUnvXaWgEBv8+5W0ur7ougy+4ZxL4uUtlJrZyA2s/TagSJu6 X-Gm-Gg: Acq92OF/Kbgcgi5xzF+QS1iGDAdfvD3KURDvRX9jd3gln6FxX2K5vZAlJciZ67/JlpF aZjt0Fw0P4GBNp+RfuFYuoZG+hbW5D8l6zG7y/KnSgRuVYOTLFrJ+aqALDHgJ9D3bPwsVKHsz1A eYB8NHtTKIHYHMMLCUEWHTjunBz60s7iMlS/cvukCplTePxLHi1Tuha4W++RgyL5dmna+W4BYhe qOP3OYbNuNNrqQxxlAV4yUQYDq+Fu2o8LgCBbmW+AXeYhgTIS1Ls6iJtD0EnRJEFu127nAF7dMN uIhFJI+Wo75XUtXIFexeofbk5nGCi2GH+ofX0ExFgYErJYXT6pRMuX0mm5zxo4O/4bVjtWcDorz JNMJnMa56kWlSutWJV2mbQVwHaqVnV2lHy4JYKHWWt3+h+IS6WRt/iUJQOchGhsdxaqG4fliGKz wylVqQCQRIuzpCXhHsOKlfCf41da1yDMWfcrDZLKUzmjp1D6E2s/XryxYcDuNEcMI= X-Received: by 2002:a05:600c:590f:b0:488:a2ac:a338 with SMTP id 5b1f17b1804b1-490426cc0dbmr28853145e9.5.1779490911959; Fri, 22 May 2026 16:01:51 -0700 (PDT) Received: from menon.v.cablecom.net (84-74-0-139.dclient.hispeed.ch. [84.74.0.139]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490456274ebsm67100265e9.15.2026.05.22.16.01.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 16:01:51 -0700 (PDT) From: Lothar Rubusch To: thorsten.blum@linux.dev, herbert@gondor.apana.org.au, davem@davemloft.net, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, tudor.ambarus@linaro.org, ardb@kernel.org, linusw@kernel.org, krzk+dt@kernel.org Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, l.rubusch@gmail.com Subject: [PATCH v4 09/12] crypto: atmel-i2c - move shared client allocation logic to core Date: Fri, 22 May 2026 23:01:31 +0000 Message-Id: <20260522230134.32414-10-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260522230134.32414-1-l.rubusch@gmail.com> References: <20260522230134.32414-1-l.rubusch@gmail.com> 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 Content-Type: text/plain; charset="utf-8" Migrate the I2C client allocation and runtime load-balancing routines out of the ECC driver code and into the central atmel-i2c core library module. Export the symmetric lifecycle helper interfaces atmel_i2c_client_alloc() and atmel_i2c_client_free() using EXPORT_SYMBOL_GPL() to expose a unified client management API. This consolidation enables the dynamic selection subsystem (which chooses the least-loaded client device based on the active transformation count) to be shared by both the ECC driver and upcoming Atmel crypto modules. Refactor the ECC driver's transformation context initialization (init_tfm) and teardown (exit_tfm) paths to use this centralized core API. No functional change is intended. Signed-off-by: Lothar Rubusch --- drivers/crypto/atmel-ecc.c | 51 +++----------------------------------- drivers/crypto/atmel-i2c.c | 47 +++++++++++++++++++++++++++++++++++ drivers/crypto/atmel-i2c.h | 3 +++ 3 files changed, 53 insertions(+), 48 deletions(-) diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index d2490693a198..16e607cd06c4 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -205,51 +205,6 @@ static int atmel_ecdh_compute_shared_secret(struct kpp= _request *req) return ret; } =20 -static struct i2c_client *atmel_ecc_i2c_client_alloc(void) -{ - struct atmel_i2c_client_priv *i2c_priv, *min_i2c_priv =3D NULL; - struct i2c_client *client =3D ERR_PTR(-ENODEV); - int min_tfm_cnt =3D INT_MAX; - int tfm_cnt; - - spin_lock(&atmel_i2c_mgmt.i2c_list_lock); - - if (list_empty(&atmel_i2c_mgmt.i2c_client_list)) { - spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); - return ERR_PTR(-ENODEV); - } - - list_for_each_entry(i2c_priv, &atmel_i2c_mgmt.i2c_client_list, - i2c_client_list_node) { - if (!i2c_priv->ready) - continue; - tfm_cnt =3D atomic_read(&i2c_priv->tfm_count); - if (tfm_cnt < min_tfm_cnt) { - min_tfm_cnt =3D tfm_cnt; - min_i2c_priv =3D i2c_priv; - } - if (!min_tfm_cnt) - break; - } - - if (min_i2c_priv) { - atomic_inc(&min_i2c_priv->tfm_count); - client =3D min_i2c_priv->client; - } - - spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); - - return client; -} - -static void atmel_ecc_i2c_client_free(struct i2c_client *client) -{ - struct atmel_i2c_client_priv *i2c_priv =3D i2c_get_clientdata(client); - - if (atomic_dec_and_test(&i2c_priv->tfm_count)) - complete(&i2c_priv->remove_done); -} - static int atmel_ecdh_init_tfm(struct crypto_kpp *tfm) { const char *alg =3D kpp_alg_name(tfm); @@ -257,7 +212,7 @@ static int atmel_ecdh_init_tfm(struct crypto_kpp *tfm) struct atmel_ecdh_ctx *ctx =3D kpp_tfm_ctx(tfm); =20 ctx->curve_id =3D ECC_CURVE_NIST_P256; - ctx->client =3D atmel_ecc_i2c_client_alloc(); + ctx->client =3D atmel_i2c_client_alloc(); if (IS_ERR(ctx->client)) { pr_err("tfm - i2c_client binding failed\n"); return PTR_ERR(ctx->client); @@ -267,7 +222,7 @@ static int atmel_ecdh_init_tfm(struct crypto_kpp *tfm) if (IS_ERR(fallback)) { dev_err(&ctx->client->dev, "Failed to allocate transformation for '%s': = %ld\n", alg, PTR_ERR(fallback)); - atmel_ecc_i2c_client_free(ctx->client); + atmel_i2c_client_free(ctx->client); return PTR_ERR(fallback); } =20 @@ -284,7 +239,7 @@ static void atmel_ecdh_exit_tfm(struct crypto_kpp *tfm) kfree(ctx->public_key); if (ctx->fallback) crypto_free_kpp(ctx->fallback); - atmel_ecc_i2c_client_free(ctx->client); + atmel_i2c_client_free(ctx->client); } =20 static unsigned int atmel_ecdh_max_size(struct crypto_kpp *tfm) diff --git a/drivers/crypto/atmel-i2c.c b/drivers/crypto/atmel-i2c.c index db818ce55033..92d3e28f9d9a 100644 --- a/drivers/crypto/atmel-i2c.c +++ b/drivers/crypto/atmel-i2c.c @@ -57,6 +57,53 @@ static void atmel_i2c_checksum(struct atmel_i2c_cmd *cmd) *__crc16 =3D cpu_to_le16(bitrev16(crc16(0, data, len))); } =20 +struct i2c_client *atmel_i2c_client_alloc(void) +{ + struct atmel_i2c_client_priv *i2c_priv, *min_i2c_priv =3D NULL; + struct i2c_client *client =3D ERR_PTR(-ENODEV); + int min_tfm_cnt =3D INT_MAX; + int tfm_cnt; + + spin_lock(&atmel_i2c_mgmt.i2c_list_lock); + + if (list_empty(&atmel_i2c_mgmt.i2c_client_list)) { + spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); + return ERR_PTR(-ENODEV); + } + + list_for_each_entry(i2c_priv, &atmel_i2c_mgmt.i2c_client_list, + i2c_client_list_node) { + if (!i2c_priv->ready) + continue; + tfm_cnt =3D atomic_read(&i2c_priv->tfm_count); + if (tfm_cnt < min_tfm_cnt) { + min_tfm_cnt =3D tfm_cnt; + min_i2c_priv =3D i2c_priv; + } + if (!min_tfm_cnt) + break; + } + + if (min_i2c_priv) { + atomic_inc(&min_i2c_priv->tfm_count); + client =3D min_i2c_priv->client; + } + + spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); + + return client; +} +EXPORT_SYMBOL_GPL(atmel_i2c_client_alloc); + +void atmel_i2c_client_free(struct i2c_client *client) +{ + struct atmel_i2c_client_priv *i2c_priv =3D i2c_get_clientdata(client); + + if (atomic_dec_and_test(&i2c_priv->tfm_count)) + complete(&i2c_priv->remove_done); +} +EXPORT_SYMBOL_GPL(atmel_i2c_client_free); + void atmel_i2c_init_read_config_cmd(struct atmel_i2c_cmd *cmd) { cmd->word_addr =3D COMMAND; diff --git a/drivers/crypto/atmel-i2c.h b/drivers/crypto/atmel-i2c.h index 07fd2248e20b..ddab80bc1a72 100644 --- a/drivers/crypto/atmel-i2c.h +++ b/drivers/crypto/atmel-i2c.h @@ -193,6 +193,9 @@ void atmel_i2c_init_genkey_cmd(struct atmel_i2c_cmd *cm= d, u16 keyid); int atmel_i2c_init_ecdh_cmd(struct atmel_i2c_cmd *cmd, struct scatterlist *pubkey); =20 +struct i2c_client *atmel_i2c_client_alloc(void); +void atmel_i2c_client_free(struct i2c_client *client); + void atmel_i2c_deactivate_client(struct atmel_i2c_client_priv *i2c_priv); void atmel_i2c_unregister_client(struct atmel_i2c_client_priv *i2c_priv); =20 --=20 2.39.5 From nobody Sun May 24 20:33:25 2026 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9DC7391836 for ; Fri, 22 May 2026 23:01:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490925; cv=none; b=AoHMDxN5ZLxcGaCD28C0AXvsKbgMy6mScvKtIvqcfNJlK8uDi/elWoUeNvOS6YjUkX4WtbFMeBPtOBQ+todF6emqtyq4PoXX0Vi4G/r83qm/qfkwnfPMfvspS5nu+RrCgoOOdVM+BHmX90UkgL9PJXzNnpQDArAxt1ExWmRNvJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490925; c=relaxed/simple; bh=5t9imB8TQUpIuhr2NaXIAgQ086dM4YJDsGiJoMdidVE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eYOzfNoZ0tLTHfm+AwoQB6CEx9iNYusiI4Ku6bZPA5Dxzpu+1BqnE4CAAhJ+qLWgj7FJkXmOis88h01YvqD7TkJJmz+swXyqgmjD5t1CblHpDcsQs1Whf0S0HFctIIrVQobA8YDD0efiEUpXyOlJ8jHahcZp74SD5We/L/rjaWI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eFSkcNjs; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eFSkcNjs" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-44b7e8b65faso599541f8f.1 for ; Fri, 22 May 2026 16:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779490913; x=1780095713; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CYnl6H7JNYvzOK1yTCqArfWOoQ9aVJm0Lozs66ZGulI=; b=eFSkcNjsPZS3FJs3s6NrviCofWhwl+DyXZls+h4VK/QK2jdZj9Nn6WBFEVbUDg+MSF qPrrXQOiuh1tDYKDkNoQcmmcuErigjPCvlOekFBaFxCifnlK/jT18gxyCZca8rkGkkJC tOTDrQH8hUS9RQOjICHKC7oPABZ4lLRyl1oMqBTGfiHoJ2o9sX4fOz1zrjyU/BarJemd 8lzQV+EjnCgVHmnGhteiMl6vlpP1K+UFHWYC53amMkzRwmWNcA7pd4o5g6MnQIedu4RF JoyxrwME8A6fjXjbjaRFSj8xIEsKsIUUWK8lelu65d/d5lrSdCBqDFuK+jbQmfhZUCya 7Xqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779490913; x=1780095713; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=CYnl6H7JNYvzOK1yTCqArfWOoQ9aVJm0Lozs66ZGulI=; b=RpzfXbPLVgbnIhKamMwOORsIeD7ezMVI+VWQ3e2sQKloo/JZNUZZc8aW3QR+7/P20t /fAMDjLRXQuRbTMbAuM/G4qxjzfnjikyfOjAI08Yr1ywEqqKDempcIin2Z2D19OCfZSA pZDJI1/bwByxVC6PiuZZ2MNSYhanON7gmW1KtH3I/Oxrt0kzHfOptNaxrqqTNbuchii0 2h7U6THDt7lm12ZmoIOA5KT3ZtVJ9l4O9hsel9ZavUrrrr0Q7jARnJu9ht2Jb6Nn14hf PZsZqnGXZyMUj+FVSlBaPgNIluaLBzxYqJjVxyvYqACrMD2YJIKaWfGaia0R+WR/H37Q q7iw== X-Forwarded-Encrypted: i=1; AFNElJ/TK/dNizEzAN+ma3SOTeVCrUPKZ/vK8GgWspgGcXHXeDMwV6JvC5abMJRuB5p4NmzKpXLBBhRwgbCXZaY=@vger.kernel.org X-Gm-Message-State: AOJu0YzPTJOevQY05Vj6jQW9tjMEMJIs537S8Y30nAm9w2ZV5jHPigwd 9gYfy3mr6lzVYubKEPObHwh0QKxiIz1a43uCykVFz9tX3q4PEkRbHmKC X-Gm-Gg: Acq92OHFaD0lHdGgBJqpcsAhMpJGwXR2Dxk66o96siruSPyHbGSCcPZUs2M+YQwEvPS m/vud/CCLyGjYyeI3zcBkuLdGypX08x1G5XWroI1nJT57EMFLayuU0FZwRe2wHSkBQ0i1XlD50K x45h+nDeO24zNOaFxIiZVgvUvN7i/hiQ+fiCo7FQS8VfAkN3w3TM7nco5A7AWfoVwsiiByCHdyd pmCXakYh/QzZrf7XHxRfAh7b2L8gjmCiF22iAxCB7jJLkP+AVXlEmHE/uJC2Z0nDGkn8zTLUHce SrFYLw1k+4TgAOha/wn6Iq/XeuWCjQemtBa1hXdTnnGnKvrh0AWfiE/eItAEocJgg+ma6dNAXKg ar9BwfJ2r64FUXsts/x4lRoyMv+44/FNU7pBS0zCCriXj0MFGkB+u1OivLxPDTr/IfFSCGRIhfi AB/H0KPKTZAcVEMp8XdGH119PoWZXoaZNToDtVXOfFLq14EuvVzcMt6T6pKhpx7Sc= X-Received: by 2002:a05:600c:444e:b0:48e:7a10:1f5e with SMTP id 5b1f17b1804b1-4904248ab61mr37470595e9.2.1779490913007; Fri, 22 May 2026 16:01:53 -0700 (PDT) Received: from menon.v.cablecom.net (84-74-0-139.dclient.hispeed.ch. [84.74.0.139]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490456274ebsm67100265e9.15.2026.05.22.16.01.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 16:01:52 -0700 (PDT) From: Lothar Rubusch To: thorsten.blum@linux.dev, herbert@gondor.apana.org.au, davem@davemloft.net, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, tudor.ambarus@linaro.org, ardb@kernel.org, linusw@kernel.org, krzk+dt@kernel.org Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, l.rubusch@gmail.com Subject: [PATCH v4 10/12] crypto: atmel-i2c - implement capability-based client selection Date: Fri, 22 May 2026 23:01:32 +0000 Message-Id: <20260522230134.32414-11-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260522230134.32414-1-l.rubusch@gmail.com> References: <20260522230134.32414-1-l.rubusch@gmail.com> 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 Content-Type: text/plain; charset="utf-8" Extend the shared I2C client allocation interface to support feature-aware hardware selection by introducing capability filtering. Add a 'caps' mask to 'struct atmel_i2c_client_priv' alongside an 'atmel_i2c_capability' enum. The allocator now explicitly filters hardware nodes by a requested capability bit while retaining the least-loaded device load-balancing scheme. Update the ECC driver to advertise ATMEL_CAP_ECDH configuration capability during probe, and adapt the tfm context setup execution path to request this specific capability variant. Initialize the bitmask field to zero inside the SHA204A driver context for now. Signed-off-by: Lothar Rubusch --- drivers/crypto/atmel-ecc.c | 4 +++- drivers/crypto/atmel-i2c.c | 6 +++++- drivers/crypto/atmel-i2c.h | 8 +++++++- drivers/crypto/atmel-sha204a.c | 2 ++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 16e607cd06c4..76b8f9e7c2e1 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -212,7 +212,7 @@ static int atmel_ecdh_init_tfm(struct crypto_kpp *tfm) struct atmel_ecdh_ctx *ctx =3D kpp_tfm_ctx(tfm); =20 ctx->curve_id =3D ECC_CURVE_NIST_P256; - ctx->client =3D atmel_i2c_client_alloc(); + ctx->client =3D atmel_i2c_client_alloc(ATMEL_CAP_ECDH); if (IS_ERR(ctx->client)) { pr_err("tfm - i2c_client binding failed\n"); return PTR_ERR(ctx->client); @@ -287,6 +287,8 @@ static int atmel_ecc_probe(struct i2c_client *client) i2c_priv =3D i2c_get_clientdata(client); i2c_priv->ready =3D false; =20 + i2c_priv->caps =3D BIT(ATMEL_CAP_ECDH); + spin_lock(&atmel_i2c_mgmt.i2c_list_lock); list_add_tail(&i2c_priv->i2c_client_list_node, &atmel_i2c_mgmt.i2c_client_list); diff --git a/drivers/crypto/atmel-i2c.c b/drivers/crypto/atmel-i2c.c index 92d3e28f9d9a..4953b8fcb02d 100644 --- a/drivers/crypto/atmel-i2c.c +++ b/drivers/crypto/atmel-i2c.c @@ -57,7 +57,7 @@ static void atmel_i2c_checksum(struct atmel_i2c_cmd *cmd) *__crc16 =3D cpu_to_le16(bitrev16(crc16(0, data, len))); } =20 -struct i2c_client *atmel_i2c_client_alloc(void) +struct i2c_client *atmel_i2c_client_alloc(enum atmel_i2c_capability cap) { struct atmel_i2c_client_priv *i2c_priv, *min_i2c_priv =3D NULL; struct i2c_client *client =3D ERR_PTR(-ENODEV); @@ -75,6 +75,10 @@ struct i2c_client *atmel_i2c_client_alloc(void) i2c_client_list_node) { if (!i2c_priv->ready) continue; + + if (!(i2c_priv->caps & BIT(cap))) + continue; + tfm_cnt =3D atomic_read(&i2c_priv->tfm_count); if (tfm_cnt < min_tfm_cnt) { min_tfm_cnt =3D tfm_cnt; diff --git a/drivers/crypto/atmel-i2c.h b/drivers/crypto/atmel-i2c.h index ddab80bc1a72..af2e49332ab6 100644 --- a/drivers/crypto/atmel-i2c.h +++ b/drivers/crypto/atmel-i2c.h @@ -115,6 +115,10 @@ struct atmel_i2c_cmd { #define ECDH_PREFIX_MODE 0x00 =20 /* Used for binding tfm objects to i2c clients. */ +enum atmel_i2c_capability { + ATMEL_CAP_ECDH =3D 0, +}; + struct atmel_i2c_client_mgmt { struct list_head i2c_client_list; spinlock_t i2c_list_lock; @@ -131,6 +135,7 @@ extern struct atmel_i2c_client_mgmt atmel_i2c_mgmt; * @tfm_count : number of active crypto transformations on i2c c= lient * @hwrng : hold the hardware generated rng * @ready : hw client is ready to use + * @caps : feature capability of the particular driver * * Reads and writes from/to the i2c client are sequential. The first byte * transmitted to the device is treated as the byte size. Any attempt to s= end @@ -149,6 +154,7 @@ struct atmel_i2c_client_priv { struct hwrng hwrng; struct completion remove_done; bool ready; + u32 caps; }; =20 /** @@ -193,7 +199,7 @@ void atmel_i2c_init_genkey_cmd(struct atmel_i2c_cmd *cm= d, u16 keyid); int atmel_i2c_init_ecdh_cmd(struct atmel_i2c_cmd *cmd, struct scatterlist *pubkey); =20 -struct i2c_client *atmel_i2c_client_alloc(void); +struct i2c_client *atmel_i2c_client_alloc(enum atmel_i2c_capability cap); void atmel_i2c_client_free(struct i2c_client *client); =20 void atmel_i2c_deactivate_client(struct atmel_i2c_client_priv *i2c_priv); diff --git a/drivers/crypto/atmel-sha204a.c b/drivers/crypto/atmel-sha204a.c index 33e5a66b843c..0c5b5cdbfcbc 100644 --- a/drivers/crypto/atmel-sha204a.c +++ b/drivers/crypto/atmel-sha204a.c @@ -178,6 +178,8 @@ static int atmel_sha204a_probe(struct i2c_client *clien= t) =20 i2c_priv =3D i2c_get_clientdata(client); =20 + i2c_priv->caps =3D 0; + memset(&i2c_priv->hwrng, 0, sizeof(i2c_priv->hwrng)); =20 i2c_priv->hwrng.name =3D dev_name(&client->dev); --=20 2.39.5 From nobody Sun May 24 20:33:25 2026 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99E9E39479F for ; Fri, 22 May 2026 23:01:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490921; cv=none; b=ClQOBTLS2xaeimHLOqi1giIHeKWOqgb5xjGD5i3H/cCYA3TvUGCFGlA5pGc/4+p/Ben451ovNTQITVIDnz81mqdXN7gJZqKzqcfuw67upt2GTRwWpa/tM/cqZFFLcQkIb34/ljI25Lpuqyw27OjaJzVxP/dzvhrbkBMuH1p5ZUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490921; c=relaxed/simple; bh=lKGPcQDLn9w68YKEAYXZZehbSZlsT66QfLnnSBn/f4c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TsJN18MHrPESWlmokQPOCq1fXFzbjEIGIWJaI5ONjS54FmkC6dIFruHFQHkDVbcWTM2/qSqfa8ysZ+GL1P240ncfZS4tzJxPZy4BZR5ZNHDTGs+fWN2QTA+PcHD0h4Zyjx+mzX6s+XFxjtxXS+pz49bdGzA3ibZnWUBIOBjVLKU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BxvsQUWR; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BxvsQUWR" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-4493cf2f982so705310f8f.2 for ; Fri, 22 May 2026 16:01:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779490915; x=1780095715; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uuVvbPMfCmoiXjDpDixu/ffXb2eS9sn4npWm18kEdeo=; b=BxvsQUWRXnEVgtqY7TnUgGWrckxjvfh5Sai8ZlUwNOFgSOLnD8U2S8j8YQmMtUpSDg RmBB2yUk2Nq+wrudUX2RfKlwD6qpCRRwh4vXsEzi9qB2ISMZUorV0rP57tv0DQhKW+UP w7AInzl8koo0ySVdV+Ylun92DV3+ErxB2gbHAzc+Vd1YUhAD/CO/95l8rMx2uxnbKT46 yqsJIvuyVtKZt1yk6WOr5Q4H3vrrylzVRaNxDMANOIG7xKyTS+PU6wrI36yWloKUJZHU AryOxET2SuIm6PnuktLWcpezESM1CN6CdGFsDmfF0M+ObyXiYuhINcN53iQxzO5IxUc+ mLPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779490915; x=1780095715; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=uuVvbPMfCmoiXjDpDixu/ffXb2eS9sn4npWm18kEdeo=; b=JFR5U26WlDeE3pV/9iK/kYbFNy/NWKyJa1xpnYA5ZoaiXLK52FbntmPR0l2mPd2Mh9 fOiKOKPjhJ8G8/O8muC9oNH0eighUq1lepBw34un6oPZ6NZLHwDTJsghKU7/oxAitnMK PkU+bPjNRbQpweMRD2z8ThDT7sxN9E9RyfjCwSEtEWzFpci94kYF/FeNuKdrka17RfYL WdpJkITr29PKCrPX8XLnRUIbPVQY/0AXK4ioOcjxRDIKxZZxPJFtyTAV0JiYLwFDEXB3 Lsvjf0H08HfTF1mNKTktD5cw3TM3vEAhrwioYLh9JyPqfCWZIqWhgQwIikFbLBtxRmQ0 ElXA== X-Forwarded-Encrypted: i=1; AFNElJ+5wRdAN9mGTjMjq/I1PGw3R47yeD5u8Ycj6Nqrq/YpD7xhn97JcqfGirwuhi7YDhNfwogKQo1s+hhfU1w=@vger.kernel.org X-Gm-Message-State: AOJu0Yx6teQRw/WiCs5BLUXxjj9cC1d6FcFEuCjF2ujLKtrPfF1PVvn6 qfK3tESk1+hAVgZccqSW1uxprqzdJOKM5iF2Gwa9j9pG5yy7l/NcDz/X X-Gm-Gg: Acq92OHzv8IiDlJA0p7W/7q1z62GX4RBFWk/NxRpjDbyDBDpz3s/sTJk2Fy5rHKbU8O SFyPFUpNYxSzLKFjzUeJadOO8XPd9eI9nymxKquyIbUFQf0Ov+t6UlvjvLKuxAYEMTk1MX4NNHn TGNcZDwAdQaTe3qRdjn6Jjf36LwLu1ea9G6VwzIDaQirNkttJEjlbHQt9eGQqz+ZJTgRS9FZcob HJxd+QbrnlZ7Pb3AM0+YThcFnc61FJnoVt0RLyz5cqRdoEXt7xMsqyZlxYmtmYrb3XKJoCtOS1u HvMgEu2CkPo85Ahsd/yAAyhCyhliTLX2XKUy7A3eQF9tI4T9xlLPkf0ycMdcWd5IAfUaex9DFV1 AvWQk64NGYJDRaUV0hIVZh03b+ndbGvSHY4cOfBuWf+chJNM0A6Zbo8FzjHdngmeAehowOoqOuL 2CG//lFAyBrQ1NE/FjiN+DNRz3MzGCr37JScMgEj1LCJ9RP+IP5mt0hCZADH0tO6M= X-Received: by 2002:a05:600c:1386:b0:490:6ab:406a with SMTP id 5b1f17b1804b1-49042be7044mr34931885e9.8.1779490914815; Fri, 22 May 2026 16:01:54 -0700 (PDT) Received: from menon.v.cablecom.net (84-74-0-139.dclient.hispeed.ch. [84.74.0.139]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490456274ebsm67100265e9.15.2026.05.22.16.01.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 16:01:54 -0700 (PDT) From: Lothar Rubusch To: thorsten.blum@linux.dev, herbert@gondor.apana.org.au, davem@davemloft.net, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, tudor.ambarus@linaro.org, ardb@kernel.org, linusw@kernel.org, krzk+dt@kernel.org Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, l.rubusch@gmail.com Subject: [PATCH v4 11/12] crypto: atmel-sha204a - integrate into core management tracking Date: Fri, 22 May 2026 23:01:33 +0000 Message-Id: <20260522230134.32414-12-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260522230134.32414-1-l.rubusch@gmail.com> References: <20260522230134.32414-1-l.rubusch@gmail.com> 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 Content-Type: text/plain; charset="utf-8" Register the SHA204A I2C device instance into the shared atmel_i2c client management tracking list during the probe phase. This allows the driver to participate in the central hardware selection infrastructure. Rework the error-unwind paths inside atmel_sha204a_probe() to prevent stale entries from remaining in the global tracking structures if a partial initialization failure occurs. If sysfs group creation fails, explicitly trigger devm_hwrng_unregister() to preserve the strict lifecycle ordering introduced in previous stability fixes. Convert the removal path to use the core teardown helpers. Ensure the device readiness state is deactivated using atmel_i2c_deactivate_client() and the tracking node is removed via atmel_i2c_unregister_client() before local memory resources are freed. This guarantees that any in-flight work queue items are unconditionally flushed, eliminating a potential Use-After-Free (UAF) window during device removal. No functional change intended beyond improved lifecycle handling. Signed-off-by: Lothar Rubusch --- drivers/crypto/atmel-sha204a.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/atmel-sha204a.c b/drivers/crypto/atmel-sha204a.c index 0c5b5cdbfcbc..86a68f2a27e0 100644 --- a/drivers/crypto/atmel-sha204a.c +++ b/drivers/crypto/atmel-sha204a.c @@ -177,9 +177,15 @@ static int atmel_sha204a_probe(struct i2c_client *clie= nt) return ret; =20 i2c_priv =3D i2c_get_clientdata(client); + i2c_priv->ready =3D false; =20 i2c_priv->caps =3D 0; =20 + spin_lock(&atmel_i2c_mgmt.i2c_list_lock); + list_add_tail(&i2c_priv->i2c_client_list_node, + &atmel_i2c_mgmt.i2c_client_list); + spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); + memset(&i2c_priv->hwrng, 0, sizeof(i2c_priv->hwrng)); =20 i2c_priv->hwrng.name =3D dev_name(&client->dev); @@ -192,15 +198,26 @@ static int atmel_sha204a_probe(struct i2c_client *cli= ent) ret =3D devm_hwrng_register(&client->dev, &i2c_priv->hwrng); if (ret) { dev_err(&client->dev, "failed to register RNG (%d)\n", ret); - return ret; + goto err_list_del; } =20 ret =3D sysfs_create_group(&client->dev.kobj, &atmel_sha204a_groups); if (ret) { dev_err(&client->dev, "failed to create sysfs group (%d)\n", ret); - return ret; + goto err_hwrng_unregister; } =20 + spin_lock(&atmel_i2c_mgmt.i2c_list_lock); + i2c_priv->ready =3D true; + spin_unlock(&atmel_i2c_mgmt.i2c_list_lock); + + return 0; + +err_hwrng_unregister: + devm_hwrng_unregister(&client->dev, &i2c_priv->hwrng); +err_list_del: + atmel_i2c_unregister_client(i2c_priv); + return ret; } =20 @@ -208,9 +225,11 @@ static void atmel_sha204a_remove(struct i2c_client *cl= ient) { struct atmel_i2c_client_priv *i2c_priv =3D i2c_get_clientdata(client); =20 + atmel_i2c_deactivate_client(i2c_priv); + sysfs_remove_group(&client->dev.kobj, &atmel_sha204a_groups); devm_hwrng_unregister(&client->dev, &i2c_priv->hwrng); - atmel_i2c_flush_queue(); + atmel_i2c_unregister_client(i2c_priv); =20 kfree((void *)i2c_priv->hwrng.priv); } @@ -245,7 +264,6 @@ static int __init atmel_sha204a_init(void) =20 static void __exit atmel_sha204a_exit(void) { - atmel_i2c_flush_queue(); i2c_del_driver(&atmel_sha204a_driver); } =20 --=20 2.39.5 From nobody Sun May 24 20:33:25 2026 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFBB03921E3 for ; Fri, 22 May 2026 23:01:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490925; cv=none; b=S1V5Nk8wT2MbkjGOmlEuVVNeopi06pdTHpZCTsA5mXyawbzKsaFXWIjM255cDDdOQP+jFzztAa1GObQlNtGVhhoreMHOq3mK8GUSgV7qPg5cBTM9yGW7+SqN9cIbu9zLftn7DWYaPpITtWWSdMK17Ih5HNVgO5hjZu/T0T1rgDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779490925; c=relaxed/simple; bh=cILOBnvDwNoAaw6TFLiy0E5sbUtN7dlvslPX/+r/UjM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WG1inI3194Gx6HxH673M8yLYuY7gPEjJytqmVXQFVJj1mn6Dyf1UWmoc1NVPWfWfva3f8GnGD1pClCyOzztP5gm/VuBMIuupWsgVjBLDe5+LQ2HMxZMtMrRfgw9kykPl1rg+KB75bBZdbEEUeNuapAzIDo1zcHJeYB9EZVGOFno= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=duIFNigS; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="duIFNigS" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-49048a8ca1bso485815e9.1 for ; Fri, 22 May 2026 16:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779490916; x=1780095716; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rwP1TF7NDrWi/kVnVYhZYtclyhtFTXoBjciS6AkRDbs=; b=duIFNigSoup2krUBUJbT6rMT8q57BQWAUK7Z6Xgq20xRrQac4UA6llHwOLbdRqL27l rgAQiMXfh7LXQST2AjcwtyBSDlIdrYEqv+1yvVe/ITuVM+HdmZXjOyTewZJdqXCzFYYs EhmKTmWHbkCRjJJ/CiuGonxvih96VwAOQgAKH2WP4Ap9NQmAr267+ibkpHcnDgaw4tU9 hflKsayDrJUonOvs8qdAZv4u1xkG2pvhdwQsV351OKuON6YPA64rXJfjPi+/tkpySI+o fnJnZJf6Xz1YQrtS8IivWQGVhze4553CXoK4iOCFmui+j+QmAWuFiRSdVxeHMcYfzWuh l6HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779490916; x=1780095716; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=rwP1TF7NDrWi/kVnVYhZYtclyhtFTXoBjciS6AkRDbs=; b=ihJtm1bKdiwcATj2gVwZeV645KkOiabAChXcf6cvN8lBp0Irmybi08/g0HyGTr5oO8 4sf63hg4BpvwKfLF6611OdSAbpTCRkXf37/H7v+0UFGhANBXhCpCnGhqwcpztazPYt9/ b5syyETHO19RHOT4fbpdGWCRDpEXgNfU8k3WjgHer+kVW28g6b6o4mfg9SFaPXaabyno 9AlUQ/rMvHU28xPpJenGon3rXMAWus+Jph4OOal4BKr+Vg/kFf+9esZvghFPlUBrviYL 7dRQT5Q4kKGFM37w6pZK+WGAofuGO/Ay6VBNwsW/LNF05J1vGjhMbvQzQa4vRx35eYQ7 uZWA== X-Forwarded-Encrypted: i=1; AFNElJ9TaM2q+mKKbICwYXtZNg/0wdbZpRw3Kg3WlltNTU5HfnMCsZfhBpLiWpbyuuq7mHmZf3+3QcXIPIZr95U=@vger.kernel.org X-Gm-Message-State: AOJu0YxDTNPQBeHzaAlVj/HnVPqypmqzSVnTPKZUp3tF4t+q63UeeeDW U1vpxhcvWnkgCqQD1RizhaExFHL91CO5kPkQ2TNpPNZgEaTJM2KrDInB X-Gm-Gg: Acq92OGzFYg2MuQz7iF9j9+z54PLO3/gqlzG4zDiKQfhMmlnCYBLuSiy33RbdIl8CCp RO6ilgyQ3njZ6puLqaryReGDae/J+EaZQVHLpGhR3MnwgaClHu5vxjk20opFle8Sm039E7hw4Vb aU5ZmlLcqaD+kD0NtjchWhHPDYVWfmxUoAxYyGVz76gnxpWIMA7rQEptFrbnhqnTtVo9GzYchGl vkJyWk2LS6F+0QrxIto8tteN8K86G1c0zR5gtxXWQz8GC1xDJkuppdViPfUzGxHzo8iSqlxcktU u1lALyncpQ0+s55zNjOblsOte9vcnr4kgktIVTHanoBUJg8PoVsn2JrDFHjVcyj3vTHQ1uZDx/+ vWylw93hZZvSAai53O49qxVmKG6+waRuQothVfNJMiImCZmdedesQvas6QguTqxg0qyJx41VXpP +AcYQT9keUHBZq86PpDJLH64t5cweY7viwjXth9QlS0l0mXz4IlP9mADbqk3nf1YiLVfQqE08QR g== X-Received: by 2002:a05:600c:8484:b0:48a:56d4:7274 with SMTP id 5b1f17b1804b1-490428ce814mr38170445e9.3.1779490916058; Fri, 22 May 2026 16:01:56 -0700 (PDT) Received: from menon.v.cablecom.net (84-74-0-139.dclient.hispeed.ch. [84.74.0.139]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490456274ebsm67100265e9.15.2026.05.22.16.01.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 16:01:55 -0700 (PDT) From: Lothar Rubusch To: thorsten.blum@linux.dev, herbert@gondor.apana.org.au, davem@davemloft.net, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, tudor.ambarus@linaro.org, ardb@kernel.org, linusw@kernel.org, krzk+dt@kernel.org Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, l.rubusch@gmail.com Subject: [PATCH v4 12/12] crypto: atmel-sha204a - switch to module_i2c_driver Date: Fri, 22 May 2026 23:01:34 +0000 Message-Id: <20260522230134.32414-13-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260522230134.32414-1-l.rubusch@gmail.com> References: <20260522230134.32414-1-l.rubusch@gmail.com> 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 Content-Type: text/plain; charset="utf-8" Replace explicit module init and exit boilerplate functions with the module_i2c_driver() macro helper to simplify the driver registration path. Signed-off-by: Lothar Rubusch --- drivers/crypto/atmel-sha204a.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/crypto/atmel-sha204a.c b/drivers/crypto/atmel-sha204a.c index 86a68f2a27e0..74f91e176713 100644 --- a/drivers/crypto/atmel-sha204a.c +++ b/drivers/crypto/atmel-sha204a.c @@ -257,18 +257,7 @@ static struct i2c_driver atmel_sha204a_driver =3D { .driver.of_match_table =3D atmel_sha204a_dt_ids, }; =20 -static int __init atmel_sha204a_init(void) -{ - return i2c_add_driver(&atmel_sha204a_driver); -} - -static void __exit atmel_sha204a_exit(void) -{ - i2c_del_driver(&atmel_sha204a_driver); -} - -module_init(atmel_sha204a_init); -module_exit(atmel_sha204a_exit); +module_i2c_driver(atmel_sha204a_driver); =20 MODULE_AUTHOR("Ard Biesheuvel "); MODULE_DESCRIPTION("Microchip / Atmel SHA204A (I2C) driver"); --=20 2.39.5