From patchwork Tue Jul 31 19:51:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10551279 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C2A896FA for ; Tue, 31 Jul 2018 19:52:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9AC0283D1 for ; Tue, 31 Jul 2018 19:52:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDB6428445; Tue, 31 Jul 2018 19:52:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89EBE284E4 for ; Tue, 31 Jul 2018 19:52:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732455AbeGaVes (ORCPT ); Tue, 31 Jul 2018 17:34:48 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:39412 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732552AbeGaVeC (ORCPT ); Tue, 31 Jul 2018 17:34:02 -0400 Received: by mail-pf1-f195.google.com with SMTP id j8-v6so6602294pff.6 for ; Tue, 31 Jul 2018 12:52:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=24hZXZaYjkBN7Mhw98yp1L0z0cLuLy+pImRF9czCj3g=; b=LRHJG5+dUthNvaTssITiGXrhVq67Uc2hLz9U5lGiVKe7K4gvHKd+1tKsYIS0KkHeUh 68+eP18my0QjNjWuFvA9fHkCPRm+0enDupu83c/IL60CZeGx2CTUUUFsh1TioStOG0QM Xn9AkZTZCCGhDr12kE+Hj7dbKw4VTnLG6aTYw= 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; bh=24hZXZaYjkBN7Mhw98yp1L0z0cLuLy+pImRF9czCj3g=; b=W8ndvute83pYD55XhJooFe+0Oywq4qfzM/vPojxPJYr6iiuXq0O4gF7fwBHdmcVfg/ x+yFnETH/+cNEwMDZPZnL4AgLMhe0j1RAZXfHT/lhSLe5cjGyZjctn4AisROmva79tL8 RFMEinGPj3H2m3B8PQ5vTNGKAPfUuXzKLIbFsGSJSc/3V9isc0S6ZOLgkC4aUs1wEmDB CaRBnRv/SgEkifPeh876vwqp3PtO3uh+cyohwOKgrF/SFcPm6DEqmi3B36bMVlv/Ondn 7SxKG6WU3fcdXVtYvnQ7z1dudMAFxsio1pv21vdomyHMQNJVUKs2axiER1jlpC9Yk/3L LkZA== X-Gm-Message-State: AOUpUlEAivS/7mEfapz8NE9LErutBR8D/TO+ofTLaiV76/zYTVsuN2mW 6lxaaGZJdzbHw2dnZYLt1DSupw== X-Google-Smtp-Source: AAOMgpezb9ER0QUYjK7xUFVvBclCtPAfOWAzBWZVqTZPPa3akynnaF5z8OkGZt7iSnJPxC8IIA3azA== X-Received: by 2002:a63:6d8b:: with SMTP id i133-v6mr22059745pgc.215.1533066729234; Tue, 31 Jul 2018 12:52:09 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id y27-v6sm34108464pff.181.2018.07.31.12.52.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 31 Jul 2018 12:52:07 -0700 (PDT) From: Kees Cook To: Jens Axboe Cc: Kees Cook , Christoph Hellwig , "Martin K. Petersen" , "James E.J. Bottomley" , Tejun Heo , Borislav Petkov , "David S. Miller" , "Manoj N. Kumar" , "Matthew R. Ochs" , Uma Krishnan , "Nicholas A. Bellinger" , Thomas Gleixner , Philippe Ombredanne , Stephen Boyd , Cyrille Pitchen , Juergen Gross , Viresh Kumar , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Sagar Dharia , Randy Dunlap , Vinod Koul , David Kershner , linux-block@vger.kernel.org, linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/9] ide-cd: Remove redundant sense buffer Date: Tue, 31 Jul 2018 12:51:51 -0700 Message-Id: <20180731195155.46664-7-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180731195155.46664-1-keescook@chromium.org> References: <20180731195155.46664-1-keescook@chromium.org> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is already able to process the sense buffer, so remove the redundant parsing during the failure path. This also fixes any possible stale values since the prior code did not check the sense length. Signed-off-by: Kees Cook Acked-by: David S. Miller Reviewed-by: Christoph Hellwig --- drivers/ide/ide-cd.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c index cb90560acf6e..023a7d94eb08 100644 --- a/drivers/ide/ide-cd.c +++ b/drivers/ide/ide-cd.c @@ -423,6 +423,7 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd, req_flags_t rq_flags) { struct cdrom_info *info = drive->driver_data; + struct scsi_sense_hdr local_sshdr; int retries = 10; bool failed; @@ -430,6 +431,9 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd, "rq_flags: 0x%x", cmd[0], write, timeout, rq_flags); + if (!sshdr) + sshdr = &local_sshdr; + /* start of retry loop */ do { struct request *rq; @@ -456,9 +460,8 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd, if (buffer) *bufflen = scsi_req(rq)->resid_len; - if (sshdr) - scsi_normalize_sense(scsi_req(rq)->sense, - scsi_req(rq)->sense_len, sshdr); + scsi_normalize_sense(scsi_req(rq)->sense, + scsi_req(rq)->sense_len, sshdr); /* * FIXME: we should probably abort/retry or something in case of @@ -470,12 +473,10 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd, * The request failed. Retry if it was due to a unit * attention status (usually means media was changed). */ - struct request_sense *reqbuf = scsi_req(rq)->sense; - - if (reqbuf->sense_key == UNIT_ATTENTION) + if (sshdr->sense_key == UNIT_ATTENTION) cdrom_saw_media_change(drive); - else if (reqbuf->sense_key == NOT_READY && - reqbuf->asc == 4 && reqbuf->ascq != 4) { + else if (sshdr->sense_key == NOT_READY && + sshdr->asc == 4 && sshdr->ascq != 4) { /* * The drive is in the process of loading * a disk. Retry, but wait a little to give