From nobody Wed Apr 1 13:43:27 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 52EAB3DCDA6 for ; Tue, 31 Mar 2026 08:21:21 +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=1774945283; cv=none; b=DgVqdM1DQbxD9dJbplsn9ok/QdWewYmY3OvDh1pabQxJp/H5XadSgTRbgluZIfmJhM/oIf/emK0sU17gLx5n6kf4eyciqMARb7osx2NtofIk3nfxg1ZZwKlAhGuLmk0Ob9RvGoy0RI/NxQpM7wbrF6Qrn2/tdYL+2IA5c/ilOn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774945283; c=relaxed/simple; bh=2flK/UJa1UrZ/JEeL6RqU15Vn2qjY+wp87o+KBrBy54=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dMUZf7aA3WOZqlf4QlIR213+ZgNwixhWE3S7rti4EyFb6y9EY9N4m/tBPOE9CxMWaOVPsVAJnwUouMVaFDGHVDFceDfu598itDq+bPz9Y39lka+QZCc/wO+FnyH/v1pnx+pDZy6xI1ttt9nmdnO45ldAZPce+3mWSoynCD641gc= 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=ifqEdwyA; 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="ifqEdwyA" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-43b99df9649so318146f8f.3 for ; Tue, 31 Mar 2026 01:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774945280; x=1775550080; 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=pzLIANwxZ+5V5JDtMYwIGXlBV/CrkOF0yZpzbS4Kpx4=; b=ifqEdwyAxEcS/UMN6E1KXgwW8Mv/IvRIVmdNS4bzGwztqNxUDMfmUOBfmjAJ7HeAnW G8tObCYK8KvjlmfwANAJ9eJyKSeA/ZN5eeIj53EKElK4AeiBjz7ZwS+yw0OUOGp0vI5W MefpLiP6kbdCL0nzQxrKSuJ5nwjMNGdcinyzPG02KSDXw+HdolB+SRIZHmfnRyDL5swb q/MuSBCeFy78QtAfwgbKHyqIrjhpyMZXopMUDU/GT1KeHhEtYFWVv/ponzoxtTh47Ti7 07P2qrX9UUG+zjhBGPtyfiFPnjdEXA1PirbCp4dlLKJ7KNPj3eovZqVuxNWdQatuk2Ne HDpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774945280; x=1775550080; 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=pzLIANwxZ+5V5JDtMYwIGXlBV/CrkOF0yZpzbS4Kpx4=; b=S5NvhqiI7tv4vkPImc8GEvRzDxRTCcvWYVWtF+aIv0uJ8o5J4TvFZ3yUfVAdsb71Ei AlWsw9+r/pUGgB8L3AGBODqXxfIph/+9N+INJk+MVtVeOfcqOElTg5jczpbwWdi0V6fW J6nI+kJocNaUbR58ausrOqAqCp5KTJbJpq5DhzVmKszkTE9Ubm5QWPoRG327tssMD/XI XbnReqiYlAH1KPHuu0TjejwYxhZymUXkWFo65Yx7g/FmMpbHTGL1/1mDyzo1m0f5lhST DXxMhDibrdO7jtD1cNPOby9qatO3dFge96W0Rq1LqX2oIaFgPvDTpth5Gu+hRcjPtUMA IMGA== X-Forwarded-Encrypted: i=1; AJvYcCUK59SYkhPbQDZt6MSSYORYozLtHsXDASg2Gg5y8PqkR//vFm7QwxUpCaWgmjYwYn5y5Luflueu3GuSrVE=@vger.kernel.org X-Gm-Message-State: AOJu0YxWorG0d/OTLK3sTrS9SgcMzQyeEehkqZP8qwD55IT65EJnMRCW V6Jz+iLQGyQB+BsyhVWXK9/oSMlebBWVg7+RvBMsSwL41LJ+T2E/Qb23 X-Gm-Gg: ATEYQzwEb/YrWIwNhzl4lk0OilRj0SFe92Xad4E6OpGC0pYvJRLKqN+2EDR0KSN/FKA eF6wZGXP6wpnvr9Xmrm/6pbOXmM4NhIiSsEw+1OpA0RSyTSXFkRgHVF0Yy06cW90UT6VQ06MM8M FJSuuc8KFXaWNC4hEuiegejILxO3XdqRVoIVtdWICeMAqXYaV+jswGMVe0Oupaxb6LUZ5OYlWvr jhPZkjgNLKiYPmotiQzPOH4aNWyPZj/VQo0gUFEVG6RCHBUrZaTGgQIUuqvzTVsGSuEbQ8wdoed BmWZ/iArl4GOoCH89+lkVXNlbN2jOVHZiHqGNL0VshwkMxUXaqahzIvx83sPkUNRHN/KGWtBb/j RrSVVVvDhC2W+lud+1qFsxH+1QzHXidbQ9bBAOx+gfoxofz4ir1D0iwvLzpzeef2Bgt9Eo70Ov4 pnRCVz7f3A4NRsJ1Ni7iHAoctsVqmi0cfL6gZLBkHs/XIUt3Te8nSbfHGLtpfOxGc= X-Received: by 2002:a05:600c:1d1c:b0:487:1fbb:5a28 with SMTP id 5b1f17b1804b1-48727f2d043mr122939545e9.1.1774945279542; Tue, 31 Mar 2026 01:21:19 -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-4887ad8d28bsm14542485e9.10.2026.03.31.01.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2026 01:21:19 -0700 (PDT) From: Lothar Rubusch To: herbert@gondor.apana.org.au, davem@davemloft.net, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, ardb@kernel.org, linusw@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 v2 3/3] crypto: atmel-sha204a - fix non-blocking read logic Date: Tue, 31 Mar 2026 08:21:05 +0000 Message-Id: <20260331082105.697468-4-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260331082105.697468-1-l.rubusch@gmail.com> References: <20260331082105.697468-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" The non-blocking path was (also) failing to provide valid entropy due to improper buffer management and a lack of hardware execution time. Ensure cmd.msecs (30ms) and cmd.rxsize (35ms) are initialized before enqueuing the background work. Fix the data offset to skip the 1-byte hardware count header when copying bits to the caller. Correctly return 0 (busy) to the hwrng core while hardware execution is in progress, preventing zero-filled buffers, which was the situation before. With this fix applied, tests will look similar to this: $ socat -u OPEN:/dev/hwrng,nonblock - | head -c 32 | hexdump -C 00000000 23 cc 42 3c 90 b1 38 fc 54 37 35 4b 09 c5 e1 0d |#.B<..8.T75K..= ..| 2026/03/23 14:30:18 socat[858] E read(5, 0x55be363000, 8192): Resource temp= orarily unavailable 00000010 73 3b af d9 02 70 76 bd 2d 59 4b 12 01 ac ae 2b |s;...pv.-YK...= .+| 00000020 Fixes: da001fb651b0 ("crypto: atmel-i2c - add support for SHA204A random nu= mber generator") Signed-off-by: Lothar Rubusch --- drivers/crypto/atmel-sha204a.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/atmel-sha204a.c b/drivers/crypto/atmel-sha204a.c index 350ba8618c69..c0a1d34bbd9e 100644 --- a/drivers/crypto/atmel-sha204a.c +++ b/drivers/crypto/atmel-sha204a.c @@ -32,7 +32,6 @@ static void atmel_sha204a_rng_done(struct atmel_i2c_work_= data *work_data, "i2c transaction failed (%d)\n", status); kfree(work_data); - rng->priv =3D 0; atomic_dec(&i2c_priv->tfm_count); return; } @@ -49,20 +48,19 @@ static int atmel_sha204a_rng_read_nonblocking(struct hw= rng *rng, void *data, =20 i2c_priv =3D container_of(rng, struct atmel_i2c_client_priv, hwrng); =20 - /* Verify if data available from last run */ if (rng->priv) { work_data =3D (struct atmel_i2c_work_data *)rng->priv; - max =3D min(sizeof(work_data->cmd.data), max); - memcpy(data, &work_data->cmd.data, max); + max =3D min_t(size_t, ATMEL_RNG_BLOCK_SIZE, max); + memcpy(data, &work_data->cmd.data[1], max); =20 - /* Now, free memory */ + /* Free memory and clear the in-flight flag */ kfree(work_data); rng->priv =3D 0; atomic_dec(&i2c_priv->tfm_count); return max; } =20 - /* When a request is still in-flight but not processed */ + /* If a request is still in-flight, return 0 (busy) */ if (atomic_read(&i2c_priv->tfm_count) > 0) return 0; =20 @@ -76,8 +74,14 @@ static int atmel_sha204a_rng_read_nonblocking(struct hwr= ng *rng, void *data, work_data->client =3D i2c_priv->client; =20 atmel_i2c_init_random_cmd(&work_data->cmd); + + /* Set the execution time for the RNG command (from datasheet) */ + work_data->cmd.msecs =3D ATMEL_RNG_EXEC_TIME; + work_data->cmd.rxsize =3D RANDOM_RSP_SIZE; + atmel_i2c_enqueue(work_data, atmel_sha204a_rng_done, rng); =20 + /* Return 0 to indicate 'busy', data will be ready on next call */ return 0; } =20 --=20 2.39.5