From patchwork Sat Sep 5 01:31:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 7126921 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6CE439F32B for ; Sat, 5 Sep 2015 01:37:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9E70F208AE for ; Sat, 5 Sep 2015 01:37:32 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id CD398208A2 for ; Sat, 5 Sep 2015 01:37:31 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C07AF182E35; Fri, 4 Sep 2015 18:37:31 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ml01.01.org (Postfix) with ESMTP id 061E4182E32 for ; Fri, 4 Sep 2015 18:37:30 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP; 04 Sep 2015 18:37:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,471,1437462000"; d="scan'208";a="798219870" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.137]) by orsmga002.jf.intel.com with ESMTP; 04 Sep 2015 18:37:30 -0700 Subject: [PATCH 06/11] ndctl: fix vendor command residue handling From: Dan Williams To: linux-nvdimm@lists.01.org Date: Fri, 04 Sep 2015 21:31:48 -0400 Message-ID: <20150905013148.28464.90056.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <20150905012538.28464.18136.stgit@dwillia2-desk3.amr.corp.intel.com> References: <20150905012538.28464.18136.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-8-g92dd MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It is not necessarily an error if the platform returns less than the requested number of bytes in the output buffer. Arrange for do_cmd() to populate the output buffer with all known valid data and update ndctl_cmd_vendor_get_output_size() to properly handle the case of positive cmd->status. Reported-by: Nicholas Moulin Tested-by: Nicholas Moulin Signed-off-by: Dan Williams --- lib/libndctl.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/libndctl.c b/lib/libndctl.c index 0b558df46893..be7d7678c3b6 100644 --- a/lib/libndctl.c +++ b/lib/libndctl.c @@ -1954,11 +1954,15 @@ NDCTL_EXPORT ssize_t ndctl_cmd_vendor_set_input(struct ndctl_cmd *cmd, NDCTL_EXPORT ssize_t ndctl_cmd_vendor_get_output_size(struct ndctl_cmd *cmd) { - if (cmd->type != ND_CMD_VENDOR || cmd->status > 0) + if (cmd->type != ND_CMD_VENDOR) return -EINVAL; - if (cmd->status < 0) + /* + * When cmd->status is non-zero it contains either a negative + * error code, or the number of bytes that are available in the + * output buffer. + */ + if (cmd->status) return cmd->status; - return to_vendor_tail(cmd)->out_length; } @@ -2297,14 +2301,14 @@ static int do_cmd(int fd, int ioctl_cmd, struct ndctl_cmd *cmd) iter->max_xfer); *(cmd->iter.offset) = offset; rc = ioctl(fd, ioctl_cmd, cmd->cmd_buf); - if (rc) + if (rc < 0) break; if (iter->dir == READ) memcpy(iter->total_buf + offset, iter->data, - iter->max_xfer); - if (*(cmd->firmware_status)) { - rc = iter->total_xfer - offset; + iter->max_xfer - rc); + if (*(cmd->firmware_status) || rc) { + rc = offset + iter->max_xfer - rc; break; } }