From patchwork Fri May 18 21:45:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 10412333 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5FE55602C2 for ; Fri, 18 May 2018 21:46:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EE6728AEC for ; Fri, 18 May 2018 21:46:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41F4D28AF2; Fri, 18 May 2018 21:46:12 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D6EF628AEC for ; Fri, 18 May 2018 21:46:11 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 79E802096DCD7; Fri, 18 May 2018 14:46:11 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.136; helo=mga12.intel.com; envelope-from=vishal.l.verma@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3C2A72096AEFB for ; Fri, 18 May 2018 14:46:10 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 May 2018 14:46:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,416,1520924400"; d="scan'208";a="42448082" Received: from vverma7-mobl4.lm.intel.com ([10.254.40.82]) by orsmga008.jf.intel.com with ESMTP; 18 May 2018 14:46:08 -0700 From: Vishal Verma To: Subject: [ndctl PATCH] ndctl: refactor validation of the ars_status command Date: Fri, 18 May 2018 15:45:59 -0600 Message-Id: <20180518214559.21134-1-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.14.3 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tomasz.rochumski@intel.com MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP The APIs that iterate over the information contained in an ars_atatus command require a prior, successfully completed ars_status command struct. We were neglecting to verify that the firmware status too indicates a success. Refactor this checking to mimic validate_ars_cap() which checks both the command status as well as the formware status. Reported-by: Tomasz Rochumski Cc: Dan Williams Signed-off-by: Vishal Verma --- ndctl/lib/ars.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/ndctl/lib/ars.c b/ndctl/lib/ars.c index 1ff6cf7..ef30617 100644 --- a/ndctl/lib/ars.c +++ b/ndctl/lib/ars.c @@ -216,15 +216,31 @@ NDCTL_EXPORT int ndctl_cmd_ars_in_progress(struct ndctl_cmd *cmd) return 0; } +static bool __validate_ars_stat(struct ndctl_cmd *ars_stat) +{ + if (ars_stat->type != ND_CMD_ARS_STATUS || ars_stat->status != 0) + return false; + if ((*ars_stat->firmware_status & ARS_STATUS_MASK) != 0) + return false; + return true; +} + +#define validate_ars_stat(ctx, ars_stat) \ +({ \ + bool __valid = __validate_ars_stat(ars_stat); \ + if (!__valid) \ + dbg(ctx, "expected sucessfully completed ars_stat command\n"); \ + __valid; \ +}) + NDCTL_EXPORT unsigned int ndctl_cmd_ars_num_records(struct ndctl_cmd *ars_stat) { struct ndctl_ctx *ctx = ndctl_bus_get_ctx(cmd_to_bus(ars_stat)); - if (ars_stat->type == ND_CMD_ARS_STATUS && ars_stat->status == 0) - return ars_stat->ars_status->num_records; + if (!validate_ars_stat(ctx, ars_stat)) + return 0; - dbg(ctx, "invalid ars_status\n"); - return 0; + return ars_stat->ars_status->num_records; } NDCTL_EXPORT unsigned long long ndctl_cmd_ars_get_record_addr( @@ -237,11 +253,10 @@ NDCTL_EXPORT unsigned long long ndctl_cmd_ars_get_record_addr( return 0; } - if (ars_stat->type == ND_CMD_ARS_STATUS && ars_stat->status == 0) - return ars_stat->ars_status->records[rec_index].err_address; + if (!validate_ars_stat(ctx, ars_stat)) + return 0; - dbg(ctx, "invalid ars_status\n"); - return 0; + return ars_stat->ars_status->records[rec_index].err_address; } NDCTL_EXPORT unsigned long long ndctl_cmd_ars_get_record_len( @@ -254,11 +269,10 @@ NDCTL_EXPORT unsigned long long ndctl_cmd_ars_get_record_len( return 0; } - if (ars_stat->type == ND_CMD_ARS_STATUS && ars_stat->status == 0) - return ars_stat->ars_status->records[rec_index].length; + if (!validate_ars_stat(ctx, ars_stat)) + return 0; - dbg(ctx, "invalid ars_status\n"); - return 0; + return ars_stat->ars_status->records[rec_index].length; } NDCTL_EXPORT struct ndctl_cmd *ndctl_bus_cmd_new_clear_error(