Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1337316rwi; Thu, 13 Oct 2022 12:13:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7sBJmM5vT6m2GGqcW59rGN/hqR8Dfd5E7zt9KvozMhPMdSDH89y4VtmqPjSmHGTQc+61wr X-Received: by 2002:a17:907:c05:b0:73d:6e0a:8d22 with SMTP id ga5-20020a1709070c0500b0073d6e0a8d22mr921054ejc.646.1665688383868; Thu, 13 Oct 2022 12:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665688383; cv=none; d=google.com; s=arc-20160816; b=DjAxZSOB6ki7zN44etazwD8t3vJPfpqzkNVoqpakaRYXsP4p1y9cDHIEerW4oQ876M CpU2i61ysjws39+d6WMPmDJpjTnZMAWvPsnqPfm9L+ODun2W0i0niU1u6FWFUf3nQi68 BC1Zxam2ijgd+vAA1qsk/ZZNYbqvtEhLfWD7UbVt3BvfRYdk/rGHHhfJdBgSCjykJVDf bxXbYp5Dy4vhcBu0VUYodZAwp3stqlo/W6TMS9dHSRPPDZSsYRkrmTFsY53xkEpHRleT 2lfKgCZYaOkq1nsN+K7WHAfgk6yngYE7uW7jBeKHLY0pA1qwh9f/2uXB0w90kHc+IxmJ wQsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nZhZQXfCKk7bnYk3QDLtn3RiiucS6JTrEp045IGadhE=; b=d4ClI5h1bsN3OwIhcSJCcD7NllKPMkoJJ7qS6VPpMxzjw3+4QFzagACU3Y10NJtCD6 wXhLgnuSlp2/22xzh59IoWhfjanXybb8EyyUrZrFaJMSeOHWkrz7RRRT8oTSocVlON5x TWLfdUW3Kzl+cbC6MUaqCmuyMfQO/yAlNLPOZfILuzZNpX262s2ripVXb8XKsVecWuaY DH2/9W1el8mrxSZCdWYrl1c75HX+ppFY6su7NdxJrT/qY9g8JNuqFTTRreEbxxhDhxi6 A/Bj9i4+Avdi1imKf/qsKpTZzA36E/c0LwAwnX+aVIn/qOxXjG2f2zqQFb9Grz/kL4fI xAIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=INVcvf42; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cr21-20020a170906d55500b00780837381d8si434058ejc.591.2022.10.13.12.12.37; Thu, 13 Oct 2022 12:13:03 -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=@linuxfoundation.org header.s=korg header.b=INVcvf42; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230380AbiJMSCX (ORCPT + 99 others); Thu, 13 Oct 2022 14:02:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230406AbiJMSB6 (ORCPT ); Thu, 13 Oct 2022 14:01:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF1A4160EC5; Thu, 13 Oct 2022 11:01:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6EE5A6191C; Thu, 13 Oct 2022 17:58:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 755E8C433C1; Thu, 13 Oct 2022 17:58:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665683904; bh=d76VYFuP2IkY/Fd+zNHwxmqro3iVPoBaVndsGkcmcJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=INVcvf42sHoMsvXZN0w3cEG90Vn9uK3TRsQcMYKQPDVlo9vKNczRPBKh7kY0+Aa6z O7mU0hk2El/lygsFG+fj0/FdszeCUR9gSyul7itRbdCchqVUjDZZh8JiP/9LgeXjCP vJGT5klaCAXKyobvMWFkgm6MsMEF6Ox14ak6sns8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shunsuke Mie , stable Subject: [PATCH 5.15 26/27] misc: pci_endpoint_test: Aggregate params checking for xfer Date: Thu, 13 Oct 2022 19:52:55 +0200 Message-Id: <20221013175144.511915824@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175143.518476113@linuxfoundation.org> References: <20221013175143.518476113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 From: Shunsuke Mie commit 3e42deaac06567c7e86d287c305ccda24db4ae3d upstream. Each transfer test functions have same parameter checking code. This patch unites those to an introduced function. Signed-off-by: Shunsuke Mie Cc: stable Link: https://lore.kernel.org/r/20220907020100.122588-1-mie@igel.co.jp Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pci_endpoint_test.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) --- 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(st 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(struc 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(stru 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(struc 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)