From patchwork Thu Oct 5 19:40:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 729926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21042E92736 for ; Thu, 5 Oct 2023 19:42:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231966AbjJETmw (ORCPT ); Thu, 5 Oct 2023 15:42:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231791AbjJETmb (ORCPT ); Thu, 5 Oct 2023 15:42:31 -0400 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F3F7107; Thu, 5 Oct 2023 12:42:17 -0700 (PDT) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1c62d61dc96so10141545ad.0; Thu, 05 Oct 2023 12:42:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696534937; x=1697139737; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/amIXBh2OmwTU85hCgujumlTfo/mnD8IJjMcbcGdMyM=; b=vv27DmDL7zWSB583n/mJGOtOn5INCxZu5+OHayjRLz5dhbuWtCUwzptwTVc8qiD1c4 uk+DLY8iJpEPH5j/KTMH38WdvZm4V32/gsEtsZNhQE+UyIonDrwqFiMkPpILxcsP63RL 2Gep/TNjj+0N09xG1V0nh4ciQQ8SSvtavUW7oeqfKs2Z8L8GXi79WhqR5jdxEFKotK6b pB0UUzlC0JduCEz+yzfYaBrDKBVFB1ZeC6rlPLhUhKyWVcfcunW675C1WDVILAxggQgP 6ttRXGoGiSYXag8EdSM1mtfPuyOuab8ZsG1O2zD/BMTxmtvE2Ump/Kfg0VK0fvxdRxOZ pSMw== X-Gm-Message-State: AOJu0YyKx6YsjUM1QjUMvgkMjQFM/ZyfMlOve+y7s681FILtaH0WiO32 l+SBuhkcByo89mS2TEM9YaQ= X-Google-Smtp-Source: AGHT+IFk3N/FjIbIYcLBhr7sGR7pTC+1m/qWoHgLTgCYetfPFWLrX1Q8+pQ1AXb9dacfs6RRbnHI/g== X-Received: by 2002:a17:903:48f:b0:1c5:ad14:908f with SMTP id jj15-20020a170903048f00b001c5ad14908fmr5476780plb.39.1696534936763; Thu, 05 Oct 2023 12:42:16 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ca3e:70ef:bad:2f]) by smtp.gmail.com with ESMTPSA id u4-20020a170902e5c400b001a9b29b6759sm2129596plf.183.2023.10.05.12.42.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 12:42:16 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v2 11/15] scsi_debug: Rework page code error handling Date: Thu, 5 Oct 2023 12:40:57 -0700 Message-ID: <20231005194129.1882245-12-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog In-Reply-To: <20231005194129.1882245-1-bvanassche@acm.org> References: <20231005194129.1882245-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Instead of tracking whether or not the page code is valid in a boolean variable, jump to error handling code if an unsupported page code is encountered. Cc: Martin K. Petersen Cc: Douglas Gilbert Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 88cba9374166..6b87d267c9c5 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -2327,7 +2327,7 @@ static int resp_mode_sense(struct scsi_cmnd *scp, unsigned char *ap; unsigned char arr[SDEBUG_MAX_MSENSE_SZ]; unsigned char *cmd = scp->cmnd; - bool dbd, llbaa, msense_6, is_disk, is_zbc, bad_pcode; + bool dbd, llbaa, msense_6, is_disk, is_zbc; dbd = !!(cmd[1] & 0x8); /* disable block descriptors */ pcontrol = (cmd[2] & 0xc0) >> 6; @@ -2391,7 +2391,6 @@ static int resp_mode_sense(struct scsi_cmnd *scp, mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); return check_condition_result; } - bad_pcode = false; switch (pcode) { case 0x1: /* Read-Write error recovery page, direct access */ @@ -2406,15 +2405,17 @@ static int resp_mode_sense(struct scsi_cmnd *scp, if (is_disk) { len = resp_format_pg(ap, pcontrol, target); offset += len; - } else - bad_pcode = true; + } else { + goto bad_pcode; + } break; case 0x8: /* Caching page, direct access */ if (is_disk || is_zbc) { len = resp_caching_pg(ap, pcontrol, target); offset += len; - } else - bad_pcode = true; + } else { + goto bad_pcode; + } break; case 0xa: /* Control Mode page, all devices */ len = resp_ctrl_m_pg(ap, pcontrol, target); @@ -2467,18 +2468,17 @@ static int resp_mode_sense(struct scsi_cmnd *scp, } break; default: - bad_pcode = true; - break; - } - if (bad_pcode) { - mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, 5); - return check_condition_result; + goto bad_pcode; } if (msense_6) arr[0] = offset - 1; else put_unaligned_be16((offset - 2), arr + 0); return fill_from_dev_buffer(scp, arr, min_t(u32, alloc_len, offset)); + +bad_pcode: + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, 5); + return check_condition_result; } #define SDEBUG_MAX_MSELECT_SZ 512