Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934754AbcJUPdM (ORCPT ); Fri, 21 Oct 2016 11:33:12 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:51874 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933754AbcJUPdL (ORCPT ); Fri, 21 Oct 2016 11:33:11 -0400 From: Arnd Bergmann To: "James E.J. Bottomley" , "Martin K. Petersen" Cc: Arnd Bergmann , Hannes Reinecke , Shaun Tancheff , Jens Axboe , Damien Le Moal , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] sd: fix uninitialized variable access in error handling Date: Fri, 21 Oct 2016 17:32:24 +0200 Message-Id: <20161021153246.3456962-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:BLf3F6tghCYUZQTDuCXIWiOIBI6ef/QeoBfYGTIT76ouPAyzZI9 zGK1w3wBjnpT0LBrc+5AykWvD7y19lXjPocoXUdbBL0gLtEGzgDsiS0gZBrufFeCUf2KhPE lQq1XqDegfN4/pDwrl/V941Qc0mm9prdDJ1ixSm0OFnuSZRxmetPocyXIf98GZTJSqLacYX zZhcM0g8z58lYwruaZPBg== X-UI-Out-Filterresults: notjunk:1;V01:K0:XSUoxkHrG+A=:EhJeVI0fQa+g64KFF2RHVv t0EpdiWEVMKJuZgZmxyPbQmDZJ2EMeVIyS4NoXq0MFKemwcDHEC5iyVbBU6NmS4SX1qYg/3fS EH8TUPxttVANsBgO2GCa7K07F9sYt9vUvrDmbGb9iK7GkvkIu0FDkdcOonSCOk7qiqdp4AYNs 5h0NIZGIbLzWvMGdJMWe+RaQBMCwuW9fgRZs1WseHt7jeZpaQKEmT8VhB6j/HZ4KV+TxaeYVg imaFutbdusOqaHoeKSYd3DnT7Iecv/zyUQ8tC6DYJF5Bztt98e+ttoTXNNkQ9Bo4cvFGfDz8V 6hnb06rKsw1qTlt4PB/eww79a9jAl8mQvw8UYhPgVWaaul1Zqj9nP6JW7/4EoZKlPpK9lihR/ GKdJcV0oDNwuPmrlDG6HjW6AQqNAk8v4QpXIBSTrDrFWBu7kYBc4kg2wuRjLvyoOJlsvNYbWi zC3gKXC6dIt/J8+y57bF9GH2gYxqVSF/X5G8hMT7yxGzT58sH7cjilp2kvsooOo4SZN8zH9+F XIOLrNPqFFUjq1BEwYvv0FcykWpcau1vRwyPjPsQf1/Aim4O0JpaNrsJbVx7epAe/0gMg6c8i nBxgbp5Rlp80Hvu1/wFzartZl3VaXGGFXjZWxGFL1/iqqlTMiWBr3wV9x6FQ89KkdqdK6gb6F 87D4OLsNlfOuKGeBXAwG1lyOQZIfXRY/NB/t316i4rRFINSqPSitkRpFgGaLESHv5yjC10iTl GOqUZC1ZmVodUJ6z Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1079 Lines: 33 If sd_zbc_report_zones fails, the check for 'zone_blocks == 0' later in the function accesses uninitialized data: drivers/scsi/sd_zbc.c: In function ‘sd_zbc_read_zones’: drivers/scsi/sd_zbc.c:520:7: error: ‘zone_blocks’ may be used uninitialized in this function [-Werror=maybe-uninitialized] This sets it to zero, which has the desired effect of leaving the sd_zbc_read_zones successfully with sdkp->zone_blocks = 0. Fixes: 89d947561077 ("sd: Implement support for ZBC devices") Signed-off-by: Arnd Bergmann --- drivers/scsi/sd_zbc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index 16d3fa62d8ac..d5b3bd915d9e 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -455,8 +455,10 @@ static int sd_zbc_check_zone_size(struct scsi_disk *sdkp) /* Do a report zone to get the same field */ ret = sd_zbc_report_zones(sdkp, buf, SD_ZBC_BUF_SIZE, 0); - if (ret) + if (ret) { + zone_blocks = 0; goto out; + } same = buf[4] & 0x0f; if (same > 0) { -- 2.9.0