From patchwork Wed Feb 19 10:39:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 65900 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4BA63A0555; Wed, 19 Feb 2020 11:40:08 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 178981BF78; Wed, 19 Feb 2020 11:40:08 +0100 (CET) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by dpdk.org (Postfix) with ESMTP id 2A84A1B951 for ; Wed, 19 Feb 2020 11:40:07 +0100 (CET) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id CBE26220F4; Wed, 19 Feb 2020 05:40:06 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 19 Feb 2020 05:40:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=mesmtp; bh=nU8rQQy5RU5f/xSZZLb1MTm 6kQeNKYJSutsk1yu2iKw=; b=LhpfLssbYsN0omE6qXS3ZI552iuLZuv6mr7XW6B s7WoxK0A6keqo1K9+ZJjcru/iE7YTwNN51kcooDZlrP5kb4DnYCxxMsTqFyzqBEc yWdYloAcV65tBMbW86DrcqJBXvzZRLyHHSWyEBaHnWLuFM9iTF/2H+eY/SzAuYVJ BESU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=nU8rQQy5RU5f/xSZZ Lb1MTm6kQeNKYJSutsk1yu2iKw=; b=NsrVrt5zcF3Zo6OI1oL1zgE1Zijrh8YpR 26f2VHjjqO6ccAnF/H11RZhYAQQTHO8+rVEi6DrIViFcUhP3cSz7jD7+XQiy7VyW 6OF0RKn6rIGZGXX2Dy0MJ9N+oINqZnRnj0C7AtqI0Cqqy5Hp5x6rUVLMWRuN+/Rm +pFowbxiAeImEB1ok6Rwc447YRERxYkfLrj8DJGPA9WdzHmLNn+vQZb3I8O75jiD xfAtbw1et0VERVkkgqHqaa4F/0ach0Gnn9CNuROuAYcVifMWXZ2z3IYSSMP4Ysm8 jbv51G5Qs/4vAj/VCc618G7SyQ6iNKFZi/lG6xuNwAAo+8zOSFOoA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrkedtgddukecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgggfestdekredtredttdenucfhrhhomhepvfhhohhmrghsucfo ohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenucfkphepje ejrddufeegrddvtdefrddukeegnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghm pehmrghilhhfrhhomhepthhhohhmrghssehmohhnjhgrlhhonhdrnhgvth X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id D67333280067; Wed, 19 Feb 2020 05:40:05 -0500 (EST) From: Thomas Monjalon To: dev@dpdk.org Cc: Maxime Coquelin , Tiwei Bie , Zhihong Wang Date: Wed, 19 Feb 2020 11:39:22 +0100 Message-Id: <20200219103923.2259246-1-thomas@monjalon.net> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH] examples/vhost_blk: use common macros for min/max X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The macros RTE_MIN and RTE_MAX can be used in DPDK applications. This change implies fixing the sign of used_len as size_t as defined in vhost_strcpy_pad(). Signed-off-by: Thomas Monjalon Reviewed-by: Tiwei Bie Reviewed-by: Maxime Coquelin --- examples/vhost_blk/blk.c | 4 ++-- examples/vhost_blk/vhost_blk.h | 2 -- examples/vhost_blk/vhost_blk_compat.c | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/vhost_blk/blk.c b/examples/vhost_blk/blk.c index 1b0b764b22..0d1e038741 100644 --- a/examples/vhost_blk/blk.c +++ b/examples/vhost_blk/blk.c @@ -68,7 +68,7 @@ int vhost_bdev_process_blk_commands(struct vhost_block_dev *bdev, struct vhost_blk_task *task) { - int used_len; + size_t used_len; if (unlikely(task->data_len > (bdev->blockcnt * bdev->blocklen))) { fprintf(stderr, "read or write beyond capacity\n"); @@ -113,7 +113,7 @@ vhost_bdev_process_blk_commands(struct vhost_block_dev *bdev, case VIRTIO_BLK_T_GET_ID: if (!task->iovs_cnt || task->data_len) return VIRTIO_BLK_S_UNSUPP; - used_len = min(VIRTIO_BLK_ID_BYTES, task->data_len); + used_len = RTE_MIN((size_t)VIRTIO_BLK_ID_BYTES, task->data_len); vhost_strcpy_pad(task->iovs[0].iov_base, bdev->product_name, used_len, ' '); break; diff --git a/examples/vhost_blk/vhost_blk.h b/examples/vhost_blk/vhost_blk.h index 933e2b7c57..ce36c6e588 100644 --- a/examples/vhost_blk/vhost_blk.h +++ b/examples/vhost_blk/vhost_blk.h @@ -40,8 +40,6 @@ struct vhost_blk_queue { #define NUM_OF_BLK_QUEUES 1 -#define min(a, b) (((a) < (b)) ? (a) : (b)) - struct vhost_block_dev { /** ID for vhost library. */ int vid; diff --git a/examples/vhost_blk/vhost_blk_compat.c b/examples/vhost_blk/vhost_blk_compat.c index 51a1be6b6d..f6de83a5e4 100644 --- a/examples/vhost_blk/vhost_blk_compat.c +++ b/examples/vhost_blk/vhost_blk_compat.c @@ -60,7 +60,7 @@ vhost_blk_get_config(struct vhost_block_dev *bdev, uint8_t *config, fprintf(stdout, "block device:blk_size = %d, blkcnt = %"PRIx64"\n", blk_size, blkcnt); - memcpy(config, &blkcfg, min(len, sizeof(blkcfg))); + memcpy(config, &blkcfg, RTE_MIN(len, sizeof(blkcfg))); return 0; }