From nobody Fri May 3 12:45:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490279840283360.45877104359795; Thu, 23 Mar 2017 07:37:20 -0700 (PDT) Received: from localhost ([::1]:56825 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr3rb-0004r4-3y for importer@patchew.org; Thu, 23 Mar 2017 10:37:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54997) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr3qr-0004XJ-Nb for qemu-devel@nongnu.org; Thu, 23 Mar 2017 10:36:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cr3qq-0007z0-VL for qemu-devel@nongnu.org; Thu, 23 Mar 2017 10:36:33 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:48909) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cr3qq-0007wx-OK; Thu, 23 Mar 2017 10:36:32 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1cr3qn-0001xH-D5; Thu, 23 Mar 2017 14:36:29 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 23 Mar 2017 14:36:28 +0000 Message-Id: <1490279788-12995-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH for-2.9 v2] block/file-posix.c: Fix unused variable warning on OpenBSD 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: Kevin Wolf , Max Reitz , qemu-block@nongnu.org, patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 On OpenBSD none of the ioctls probe_logical_blocksize() tries exist, so the variable sector_size is unused. Refactor the code to avoid this (and reduce the duplicated code). Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Jeff Cody --- v2: add (int) cast to avoid compiler warnings on some systems when the array is empty; use 'static const'. --- block/file-posix.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 53febd3..db8f0a8 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -219,28 +219,28 @@ static int probe_logical_blocksize(int fd, unsigned i= nt *sector_size_p) { unsigned int sector_size; bool success =3D false; + int i; =20 errno =3D ENOTSUP; - - /* Try a few ioctls to get the right size */ + static const unsigned long ioctl_list[] =3D { #ifdef BLKSSZGET - if (ioctl(fd, BLKSSZGET, §or_size) >=3D 0) { - *sector_size_p =3D sector_size; - success =3D true; - } + BLKSSZGET, #endif #ifdef DKIOCGETBLOCKSIZE - if (ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) >=3D 0) { - *sector_size_p =3D sector_size; - success =3D true; - } + DKIOCGETBLOCKSIZE, #endif #ifdef DIOCGSECTORSIZE - if (ioctl(fd, DIOCGSECTORSIZE, §or_size) >=3D 0) { - *sector_size_p =3D sector_size; - success =3D true; - } + DIOCGSECTORSIZE, #endif + }; + + /* Try a few ioctls to get the right size */ + for (i =3D 0; i < (int)ARRAY_SIZE(ioctl_list); i++) { + if (ioctl(fd, ioctl_list[i], §or_size) >=3D 0) { + *sector_size_p =3D sector_size; + success =3D true; + } + } =20 return success ? 0 : -errno; } --=20 2.7.4