From nobody Tue Feb 10 04:56:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1558553410; cv=none; d=zoho.com; s=zohoarc; b=gAkVAJSwuyVCQkbWLeSCBRwQCkJzndZtWGfJiumrCZzKw/5OcwaNcW23MSk2MLMGtG7rqdVmnOzAQoh6nQV7Xu0jvdUG0PEwLec1z5QFqdrCEwtoJ7KRt98gqgErKPSi3/T2Ne1qSeHyWdo2p36vt7isw6mLPGae9Soba+Eya7U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558553410; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=VqY3mH4YRn0WtpmEi7qlWT5KRhdZPDg5AxBMBXlF56s=; b=LP5tOYXhh3Frx0W681pA2sUaGL0d1CTE3c15tgITnrK50u8H93CKYtEwMv6hQfZ+5Pz/5QwyuZB9SOo1XGUCosa91rpFw6DAsBvQZvkWvUsQ+Edx49RHmrRZzzDwRogtZ/59naOXKlRT0uDm5UmT0uJ+medQzUPGmQo/YohmgDo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558553410061189.8074777814029; Wed, 22 May 2019 12:30:10 -0700 (PDT) Received: from localhost ([127.0.0.1]:50150 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWw4-0004kA-SL for importer@patchew.org; Wed, 22 May 2019 15:30:00 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOr-00086d-Be for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWC9-00082C-II for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:34 -0400 Received: from mail-yb1-xb43.google.com ([2607:f8b0:4864:20::b43]:33820) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWC9-00081c-CR for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:33 -0400 Received: by mail-yb1-xb43.google.com with SMTP id v78so1266115ybv.1 for ; Wed, 22 May 2019 11:42:33 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VqY3mH4YRn0WtpmEi7qlWT5KRhdZPDg5AxBMBXlF56s=; b=C2fXklttaFB55rJ9U5Po24wtMKgUXJCFBv8eyRy82xHDen3Y67tB6R0FHjz+XIxhMf TVbBFlEUBGn1mwgOeIZL/Z5mWUeY6SXf3L2gSVrD2L4Gnp0/1Icf6W1+MExagrXiN/12 wU/NZ1W3Cc4ROgH8/iDeGkNrbYnZGzpRk49VISUf52ZbwxMuN0MZPTaFQFbZ1rxLi+DY XCrAIpwqUveEhfbZ/Oh9p/7EgU1UYTCUzQHAZGlkFvYKEj/MPZrnncqxTvn2/pPKEHks 5ZvNIjd5vcVHdRoyHQo9RB9bXUAnemWYvxIXTqQLn961ErKS79Sju/WZyruO9q3UaUK3 7sUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VqY3mH4YRn0WtpmEi7qlWT5KRhdZPDg5AxBMBXlF56s=; b=lEq42MIfoHqVnkhYviWu2BdIcbJrzk548BHCuxxRYEPMqhcB4kLrmiORDmYw3J3Uxp hbezfEl+xoIspqnCT9WtcyK0+Q2E+zsW5EHjuh4z14SARclsZZL57SYWiuTDgKqspsQC 6r24atuvEjciKoyQhvTwVBulwwG38J0yH/4l+nQ21ak/5Cf72WN2c2o4raYzMPGUa5xY xf/ed1sykS4yXRjtPbry+CtH2C4HM4PehgsfKWPZRqgjeKQI2WxgzJLiOmCbl/D16RjI Iz+YOMVlPwTdNvamqsNxxsh4t8mcn5UAvhbJthAE1AYY4mq7s9obK+NPz59E1T0NklfF 3dNQ== X-Gm-Message-State: APjAAAUgKOZU0xZscQUDRXzqWtIMnuila7MbAzKRWYqpDpy3T0vO1ESZ efMhX5awJpmM1CsczcG4vSbuekcBkEs= X-Google-Smtp-Source: APXvYqy8eEUipVxpaPl1CVfaByk2gkpzdFvmNdfkTtG9SGEsERhvwYj1QhIG3aPxTmZY0sCX2qh2jQ== X-Received: by 2002:a25:ef10:: with SMTP id g16mr10101072ybd.510.1558550552342; Wed, 22 May 2019 11:42:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:05 -0400 Message-Id: <20190522184226.17871-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::b43 Subject: [Qemu-devel] [PULL 04/25] crypto: Do not fail for EINTR during qcrypto_random_bytes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We can always get EINTR for read; /dev/urandom is no exception. Rearrange the order of tests for likelihood; allow degenerate buflen=3D=3D0 case to perform a no-op zero-length read. This means that the normal success path is a straight line with a single test for success. Reviewed-by: Laurent Vivier Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Richard Henderson --- crypto/random-platform.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/crypto/random-platform.c b/crypto/random-platform.c index f995fc0ef1..260b64564d 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -65,29 +65,23 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, "Unable to read random bytes"); return -1; } - - return 0; #else - int ret =3D -1; - int got; - - while (buflen > 0) { - got =3D read(fd, buf, buflen); - if (got < 0) { - error_setg_errno(errp, errno, - "Unable to read random bytes"); - goto cleanup; - } else if (!got) { - error_setg(errp, - "Unexpected EOF reading random bytes"); - goto cleanup; + while (1) { + ssize_t got =3D read(fd, buf, buflen); + if (likely(got =3D=3D buflen)) { + return 0; + } + if (got > 0) { + buflen -=3D got; + buf +=3D got; + } else if (got =3D=3D 0) { + error_setg(errp, "Unexpected EOF reading random bytes"); + return -1; + } else if (errno !=3D EINTR) { + error_setg_errno(errp, errno, "Unable to read random bytes"); + return -1; } - buflen -=3D got; - buf +=3D got; } - - ret =3D 0; - cleanup: - return ret; #endif + return 0; } --=20 2.17.1