Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5112562rwb; Tue, 6 Sep 2022 19:18:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR7XjGYR5RTw0RT4Z+y5krI2W+y9m3IhgdzE4aONbz9BNKHHlb2Fpw4NtoRmqRJwwp4Jk8PB X-Received: by 2002:a17:906:cc0c:b0:73d:d6ce:5d6b with SMTP id ml12-20020a170906cc0c00b0073dd6ce5d6bmr891401ejb.24.1662517109020; Tue, 06 Sep 2022 19:18:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662517109; cv=none; d=google.com; s=arc-20160816; b=IPI63SUp+NSBxav2JM1BldzDh5B3C4e4AnxGbfqpg3CgXoaxhrHOka28dcOzG8tNEL AfgZTgcZxRDBo8YUifWenRlj6sD/ocEZADyjG1dh0b/VLYGEcNfSXTFEU2BQgt7hhvSS YA/qdjZT29+IOMmDo2IzFgU+mmey8wH0xzH+YHyFde2bLcSRwFDqRn1GuzOJ91Y2j152 vXmjHq1vDABWtEY9iZbTCS/Cqdn1yOlFuQCzYo9G95W0TW9bOL/OxaB71p64uyXfs1pK HWSVmpKvaKV0nhjY3g5qKgInp4bANq3X+huAXXqFkXUMtet1ez5drcBYKO3oc6NN6xqq 8L6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=wMmXTxb9LbCsYqga95mJwmvC4k81ZDpljIpjJFQZtFw=; b=Ln7ZTpnf0fFJLRY98sj1h8I9Wd9Rfn1z8I3KKo/2+/ZWMrQT0uQEfs7h+1rzeT+gR8 q85vaf7ozh7j9QKJdDQr4/GdGEnIDI5AQpd9nb17FAeM5QxCb5YRvmR+ZnfjmOe+TSkl DwCDgJZ1T77U+OqQVwULxwlaKBXCDs7Rnq/SIAueetcogTaBsX9WHf/DzrqcqYl+W8Xq 8pUXutyM+uGb2zzOIK1iliiWlNN/bW/NkAFXjGGbBhwhndh3TWTbBwHzAUE3FhlpI5O8 b124KfCu7u/lUZcYHWMRmXM7en3SAjyPl3aExywn/0cwKHhOOVlNgrwYzL6zyYkkruPt iW0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@igel-co-jp.20210112.gappssmtp.com header.s=20210112 header.b=hn6hqpEU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b13-20020a056402278d00b00447225766cfsi12502355ede.535.2022.09.06.19.18.04; Tue, 06 Sep 2022 19:18:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@igel-co-jp.20210112.gappssmtp.com header.s=20210112 header.b=hn6hqpEU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229700AbiIGCBU (ORCPT + 99 others); Tue, 6 Sep 2022 22:01:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229692AbiIGCBN (ORCPT ); Tue, 6 Sep 2022 22:01:13 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D003686FE6 for ; Tue, 6 Sep 2022 19:01:10 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id x1-20020a17090ab00100b001fda21bbc90so16759404pjq.3 for ; Tue, 06 Sep 2022 19:01:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20210112.gappssmtp.com; s=20210112; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=wMmXTxb9LbCsYqga95mJwmvC4k81ZDpljIpjJFQZtFw=; b=hn6hqpEUxGoGhX68VXgTXpMCVKDJ5Pa6HLR3DTCS+p/PxteYYkJWtclUSQ+cFe8KTe jBdDF3N2kAMZp3qwCb8e0woljUxUquQSNV9Pq/AzMSLTHKXe69BXp+9OD1A2pWrD6sOL nWr92uWfuhzsfhJ4nN8KxkkF0zXIxxVezZkiWpzt+4LW8RKcR23HXmFvLGaKJMZXGWHJ JiEULAe6syHdCofXjyEvOs1ZVjq/pQrbYhRwPpX7bncI/u5VH5VkY4Jz5Mqj7AZEuA9D T4nap+kOtJo67m5mcrZwLQ7nMqT6vBLDeoe15kfsBhzkKTXO79GjcqeeX8jDIKyO1Mug jl6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=wMmXTxb9LbCsYqga95mJwmvC4k81ZDpljIpjJFQZtFw=; b=MsHUrLwh8yp1GBlYHUr9z+/fibvWny5ZWM6qNOsiTLllh3b/dmfUH5yKCNnM5h5JFg edrv52mvlpMz/csEYaDdBMQVULXUg+n4Xa+2UWRjXMV4SrwYEwDAeRW9rVNKG/5g07E5 TBay20PDlLVzbYjysOWRmFx3fkHM8lPFyI53p+ftF/CLKS3VViq6K9Sj4usYJgBJlzaP hnIx410aG/OYlsCfxpEzSCby3AcF7Bmq64OpjndiiMWIDYZd8sYP6YT7cQ08oz1XZFOh qOGxvNATPJmUoq8LCXyk8Uy//hch8sdJzPIZrcJVMte3cVDcGfxxjmj5RKfF3klmekOa OTsw== X-Gm-Message-State: ACgBeo1mjjsHX8asr4fMoIL/nI7qRn3iYyJe3pBPj25KLXW8wNVc1TyM US5jok6D98qAFCJFgyxyFPXeHQ== X-Received: by 2002:a17:902:ce8e:b0:16d:cebc:e92e with SMTP id f14-20020a170902ce8e00b0016dcebce92emr1241966plg.85.1662516069638; Tue, 06 Sep 2022 19:01:09 -0700 (PDT) Received: from tyrell.hq.igel.co.jp (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id s59-20020a17090a2f4100b002005c3d4d4fsm5182369pjd.19.2022.09.06.19.01.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 19:01:09 -0700 (PDT) From: Shunsuke Mie To: Kishon Vijay Abraham I Cc: Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Arnd Bergmann , Greg Kroah-Hartman , Dan Carpenter , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Shunsuke Mie Subject: [PATCH v3 1/2] misc: pci_endpoint_test: Aggregate params checking for xfer Date: Wed, 7 Sep 2022 11:00:59 +0900 Message-Id: <20220907020100.122588-1-mie@igel.co.jp> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Each transfer test functions have same parameter checking code. This patch unites those to an introduced function. Signed-off-by: Shunsuke Mie --- Changes in v3: * Remove duplicated logging and change to use dev_dbg(). Changes in v2: * New patch --- --- drivers/misc/pci_endpoint_test.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 8f786a225dcf..39d477bb0989 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -332,6 +332,17 @@ static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test, return false; } +static int pci_endpoint_test_validate_xfer_params(struct device *dev, + struct pci_endpoint_test_xfer_param *param, size_t alignment) +{ + if (param->size > SIZE_MAX - alignment) { + dev_dbg(dev, "Maximum transfer data size exceeded\n"); + return -EINVAL; + } + + return 0; +} + static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, unsigned long arg) { @@ -363,9 +374,11 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, return false; } + err = pci_endpoint_test_validate_xfer_params(dev, ¶m, alignment); + if (err) + return false; + size = param.size; - if (size > SIZE_MAX - alignment) - goto err; use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA); if (use_dma) @@ -497,9 +510,11 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test, return false; } + err = pci_endpoint_test_validate_xfer_params(dev, ¶m, alignment); + if (err) + return false; + size = param.size; - if (size > SIZE_MAX - alignment) - goto err; use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA); if (use_dma) @@ -595,9 +610,11 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test, return false; } + err = pci_endpoint_test_validate_xfer_params(dev, ¶m, alignment); + if (err) + return false; + size = param.size; - if (size > SIZE_MAX - alignment) - goto err; use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA); if (use_dma) -- 2.17.1