From patchwork Mon Mar 20 18:33:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 95575 Delivered-To: patches@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1077188qgd; Mon, 20 Mar 2017 11:33:08 -0700 (PDT) X-Received: by 10.28.35.151 with SMTP id j145mr11223619wmj.50.1490034788447; Mon, 20 Mar 2017 11:33:08 -0700 (PDT) Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id q134si16299857wme.5.2017.03.20.11.33.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Mar 2017 11:33:08 -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.84_2) (envelope-from ) id 1cq276-0007gu-QU; Mon, 20 Mar 2017 18:33:04 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: Kevin Wolf , Max Reitz , qemu-block@nongnu.org, patches@linaro.org Subject: [PATCH for-2.9?] block/file-posix.c: Fix unused variable warning on OpenBSD Date: Mon, 20 Mar 2017 18:33:04 +0000 Message-Id: <1490034784-28177-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 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 --- The alternative would be to move the variable so it was local to a code block inside each #ifdef, but this seemed a bit nicer anyway. Tentatively tagged 'for-2.9' just because this is the only warning in the OpenBSD build, but I don't insist on it. I've opted to retain the existing behaviour of "try every ioctl available and use the last one that works" rather than "stop as soon as something worked". --- block/file-posix.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) -- 2.7.4 Reviewed-by: Jeff Cody Reviewed-by: Philippe Mathieu-Daudé diff --git a/block/file-posix.c b/block/file-posix.c index 53febd3..b980d23 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -219,28 +219,28 @@ static int probe_logical_blocksize(int fd, unsigned int *sector_size_p) { unsigned int sector_size; bool success = false; + int i; errno = ENOTSUP; - - /* Try a few ioctls to get the right size */ + unsigned long ioctl_list[] = { #ifdef BLKSSZGET - if (ioctl(fd, BLKSSZGET, §or_size) >= 0) { - *sector_size_p = sector_size; - success = true; - } + BLKSSZGET, #endif #ifdef DKIOCGETBLOCKSIZE - if (ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) >= 0) { - *sector_size_p = sector_size; - success = true; - } + DKIOCGETBLOCKSIZE, #endif #ifdef DIOCGSECTORSIZE - if (ioctl(fd, DIOCGSECTORSIZE, §or_size) >= 0) { - *sector_size_p = sector_size; - success = true; - } + DIOCGSECTORSIZE, #endif + }; + + /* Try a few ioctls to get the right size */ + for (i = 0; i < ARRAY_SIZE(ioctl_list); i++) { + if (ioctl(fd, ioctl_list[i], §or_size) >= 0) { + *sector_size_p = sector_size; + success = true; + } + } return success ? 0 : -errno; }