From patchwork Tue May 15 17:27:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 135906 Delivered-To: patches@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1308921lji; Tue, 15 May 2018 10:27:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZojZX1I6jMYSWKyqn1ciq3WVMrshN+i2EE4KAQQeod0BIe7DDN2HJjMn0UuZCwuX8bb+hU5 X-Received: by 2002:adf:a0b8:: with SMTP id m53-v6mr11434259wrm.269.1526405251873; Tue, 15 May 2018 10:27:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526405251; cv=none; d=google.com; s=arc-20160816; b=fWTAPGP3BQk/WxAUrTEI6H/vD2kCAtfVJekEL9pMv3lQlekrybsokrxBvgI4Qp0FlN Cn3cI5e2qBoukG1pEOMTzc35kai0fVM30wJvIDubWwBwqgolSqDnD5AATRGSejLtti5I nQ1Q/RhT+8wjt6FLvyvC2W+A7J7VCtbcMR5CNFfTbGovRJjLwFOctchjieUUlX0Kkn/Y WzS0m7JZwHPQPLFeC1dJM89lVtw8saK6zAYXB+PtVVSyaonAfcji9p16Kab51OWuZq2J aU3M5mDHuGSs9GujdeV29PNOmB8w85V4kwvc7b2Cal6oDgDwUWWfnOqVL7R0Reu5t+VJ KXGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=PnQF3B82IYPdzCsRMXquxj52g2mfVPQPqLRB8zXCtIY=; b=aj7+JaTGJ5va9CR9uTTG8STCSwNVGuAaHi9uOJQg6BP5kdpZUBxoq2pq9+6tSlNAh2 q35eiKh94gTdSyjKeu39gCnvRCusgj15gXNb3D8Mi/ngxuoGG6JDl17hVdJZVFQxNmU+ PCp3/JOC4pL8ro1P1c1Wt4VvSlr9Fjy0o2vbtkva9auzluySIntDr424iOMPmKSyBnzo ZMrDB4CfsjeLjCS/gl2frfsSA1154yKHEyz1J4pRTnLy72dDJpR2uXhkn1mMo9a3kSeF GIGyrRj1Dj/OqeDkDTLEsULf8Bse+lITPhpAua04abizYSjRRgohNF1HPOR8jw8+OwM3 +o/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id 62-v6si422487wrr.454.2018.05.15.10.27.31 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 May 2018 10:27:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1fIdjW-0001dg-ON; Tue, 15 May 2018 18:27:30 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH] memfd: Avoid Coverity warning about integer overflow Date: Tue, 15 May 2018 18:27:29 +0100 Message-Id: <20180515172729.24564-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.17.0 Coverity complains about qemu_memfd_create() (CID 1385858) because we calculate a bit position htsize which could be up to 63, but then use it in "1 << htsize" which is a 32-bit integer calculation and could push the 1 off the top of the value. Silence the complaint bu using "1ULL"; this isn't a bug in practice since a hugetlbsize of 4GB is not very plausible. Signed-off-by: Peter Maydell --- util/memfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.0 Reviewed-by: Marc-André Lureau Reviewed-by: Alex Bennée diff --git a/util/memfd.c b/util/memfd.c index b3ecbac19e..d248a53c3c 100644 --- a/util/memfd.c +++ b/util/memfd.c @@ -66,7 +66,7 @@ int qemu_memfd_create(const char *name, size_t size, bool hugetlb, { int htsize = hugetlbsize ? ctz64(hugetlbsize) : 0; - if (htsize && 1 << htsize != hugetlbsize) { + if (htsize && 1ULL << htsize != hugetlbsize) { error_setg(errp, "Hugepage size must be a power of 2"); return -1; }