Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4147737rwb; Tue, 6 Sep 2022 03:22:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR6/Ehc5yg+8y/Eh/qXc1ngbsFivpy8jWEHv40gNQhOtsOfjFEBbSQA7N/P1BH+AB//kV1Od X-Received: by 2002:a17:902:6bc9:b0:173:f3f:4a8c with SMTP id m9-20020a1709026bc900b001730f3f4a8cmr54257971plt.96.1662459750701; Tue, 06 Sep 2022 03:22:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662459750; cv=none; d=google.com; s=arc-20160816; b=pzrW3IpSs7KL95ukMDVHNfgEfcsB3Q7nwsbJTQofrsH0sdydzcBfYhC/us96sk6mPo lEgX7SkXj5tXIXQUbzlQv5rHxs+T39XzNv4rNrzRE9BZjBDEX/yrmm1zyMJcgLg3DJ4V k4LxZAHC5uJ8UP0WBwl3s6PA1qWRWGHAZ4clGzPD29zfHXWJUrapqlBLrYa0l4CM1xGW LFAGp93aelT7gHZIrzs2om1FpgIxQ/gkc7PCQmPKBz4ZSZixABnBFFC6X0rZyXJ7ZI8m Y1zsc/1XBvH+/YaV196mGYI+avVupFvA88+3bTL2eqFevW9UH/msW2vTSBbMEOtHW09U 3pVw== 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=hXiNAyvQQWIBJxUajZXg5TzJhz9BDXjhOqmjIrcqoMg=; b=Kp0uSgSMV2Qi8SxQcr+70VgOq1ZikB8VqzUGwYmU11ziFPix7SI4AQPhsY3sTG7Tf4 pROn4dHvdCuNSkxk3lGGRZFtGHBpK5oBeRDSPWjUIGMH3vpdcT4LHPKFJUsWAVwn57tM lEfaNR+DGWgqjbofiPCxTyEs6/mz+K2hppQei1Tpam/c//JcbzZhbmz3NUksMSwREdZs L8bKkKM1qRzxwuCmC4opnMd0yVGJSConxEY2lwVOeCcw27kB55q5+XAKwmesyCDK7Ove kMua0/UQuuZI+MKBSphFfZWjeEEp4UsaLjkoN62IvFyNX3HLWb74M9tXwWZXGZxBN/mB P2RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@igel-co-jp.20210112.gappssmtp.com header.s=20210112 header.b="U/WzBdX6"; 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 d12-20020a65620c000000b0041db5a647a9si12605265pgv.744.2022.09.06.03.22.19; Tue, 06 Sep 2022 03:22:30 -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="U/WzBdX6"; 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 S238792AbiIFKQK (ORCPT + 99 others); Tue, 6 Sep 2022 06:16:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233592AbiIFKQI (ORCPT ); Tue, 6 Sep 2022 06:16:08 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FF642CCBA for ; Tue, 6 Sep 2022 03:16:02 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id bh13so10225976pgb.4 for ; Tue, 06 Sep 2022 03:16:02 -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=hXiNAyvQQWIBJxUajZXg5TzJhz9BDXjhOqmjIrcqoMg=; b=U/WzBdX6suz8BGPmr7TORZNTIMN2KAe/OX9ejIWK4DHDWoUKD57SIvvoc5Q+rp+Iry VK4z4Ohy08BiYvvsKuxlgkIPZKvoxmEpZTV1mgUfMLmjjiZxch4F9IZcc9fCcqomXMEz +tRzS1/Kgn4fsuGpBM8IxXrmn4mfYgNMteMPs/pgonR+h2QKob+Oz0S8nh5PgzJvoOTa j9lfKECe5c2FQ1qimcKaHRzUU9N5C207+Sw/XntYgjclSYappwPuH39+olrz66fIvGDg QAH9M9tlXojbDsSUYBWbQB/wX6qq1+Li6LRG+9nb/KewYxm5/NvE15oH5W81FZs/GJ2Q +NzQ== 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=hXiNAyvQQWIBJxUajZXg5TzJhz9BDXjhOqmjIrcqoMg=; b=1JIn31JEwx93AwObavfPiWIm4wWXZege+b8u9k3mJnfF61TBx+UUj1cpYvKJ2FL5XX OJF5wJ3jBntk/p5/d5JgQ3iPhocLy3VyetUtF+6LOTxgwCFI6YdWxycw0basUynr2jDB LbeghNUpt5AT1jnjIqCgLNnF3RAPPN1p0DEaPI77HPmsSrI0ZUGuO0ElsiXJsW2PZGbE YpoleCLWo1IXUCGAmT9+CioFa3o1jbghw3UHlPxq/Y8UasBARPUhcHOiTCSuX82Sqv1D z9OicaryjawbwECwDRcaz+aknSaKNLTzE2bGrUjl+ZIAMRKqGpKsFY6is2pN/qWU6LY9 d3bg== X-Gm-Message-State: ACgBeo2fJgFAIebYxAwlX9TMa/BxUBygS/mQJ0qSe6PFTP8nIzdsxRMp Prjnoj2Y18wfVdpbiTB6lkB/Ng== X-Received: by 2002:a05:6a00:1894:b0:537:2e86:c7df with SMTP id x20-20020a056a00189400b005372e86c7dfmr54511206pfh.18.1662459361496; Tue, 06 Sep 2022 03:16:01 -0700 (PDT) Received: from tyrell.hq.igel.co.jp (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id f62-20020a625141000000b0053b723a74f7sm7914151pfb.90.2022.09.06.03.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 03:16:00 -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: [RFC PATCH v2 1/2] misc: pci_endpoint_test: Aggregate params checking for xfer Date: Tue, 6 Sep 2022 19:15:54 +0900 Message-Id: <20220906101555.106033-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 v2: * New patch --- --- drivers/misc/pci_endpoint_test.c | 35 ++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 8f786a225dcf..3bd9f135cdac 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_err(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,13 @@ 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) { + dev_err(dev, "Invalid parameter\n"); + 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 +512,13 @@ 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) { + dev_err(dev, "Invalid parameter\n"); + 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 +614,13 @@ 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) { + dev_err(dev, "Invalid parameter\n"); + 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