From patchwork Mon Nov 9 16:30:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matan Barak X-Patchwork-Id: 7585491 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 689E8C05C6 for ; Mon, 9 Nov 2015 16:34:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 87FD7205B4 for ; Mon, 9 Nov 2015 16:34:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB4F620551 for ; Mon, 9 Nov 2015 16:34:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751419AbbKIQeO (ORCPT ); Mon, 9 Nov 2015 11:34:14 -0500 Received: from [193.47.165.129] ([193.47.165.129]:37083 "EHLO mellanox.co.il" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751168AbbKIQeN (ORCPT ); Mon, 9 Nov 2015 11:34:13 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from matanb@mellanox.com) with ESMTPS (AES256-SHA encrypted); 9 Nov 2015 18:33:45 +0200 Received: from rsws33.mtr.labs.mlnx (dev-r-vrt-064.mtr.labs.mlnx [10.212.64.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id tA9GXj38019781; Mon, 9 Nov 2015 18:33:45 +0200 From: Matan Barak To: Eli Cohen Cc: linux-rdma@vger.kernel.org, Doug Ledford , Matan Barak , Eran Ben Elisha , Yann Droneaud Subject: [PATCH for-next 2/4] IB/core: Add ib_is_udata_cleared Date: Mon, 9 Nov 2015 18:30:55 +0200 Message-Id: <1447086657-15358-3-git-send-email-matanb@mellanox.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1447086657-15358-1-git-send-email-matanb@mellanox.com> References: <1447086657-15358-1-git-send-email-matanb@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Extending core and vendor verb commands require us to check that the unknown part of the user's given command is all zeros. Adding ib_is_udata_cleared in order to do so. Signed-off-by: Matan Barak Acked-by: Eli Cohen --- include/rdma/ib_verbs.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index e4cc389..43f3cf2 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -1855,6 +1855,26 @@ static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0; } +static inline bool ib_is_udata_cleared(struct ib_udata *udata, + char cleared_char, + size_t offset, + size_t len) +{ + short i; + + for (i = 0; i < len; i++) { + char c; + + if (copy_from_user(&c, udata->inbuf + offset + i, sizeof(c))) + return false; + + if (c != cleared_char) + return false; + } + + return true; +} + /** * ib_modify_qp_is_ok - Check that the supplied attribute mask * contains all required attributes and no attributes not allowed for