From patchwork Thu Oct 13 17:52:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 2188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp408696wrs; Thu, 13 Oct 2022 11:03:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4d8msZrYOKZxelIWkskN26O4BetsZMvgDM097rIu7me9iRToMdsm0mV3tkq922RfQX5J4E X-Received: by 2002:a63:1e05:0:b0:451:31d0:8c0f with SMTP id e5-20020a631e05000000b0045131d08c0fmr928326pge.227.1665684227146; Thu, 13 Oct 2022 11:03:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665684227; cv=none; d=google.com; s=arc-20160816; b=TsgUrNCKDWG5ubgtVi+am9GbiAqXcgwFMNB0YzPhc0zOnTey/fdPHi+cTUxN36e6Y6 5zlpCsu1MmEVc9QweWh6z+RVOPrlZVCAD4f73rWBWimKL6KCm7+L82/jAvvsmjZ2R5Xt k2qXgvkHYMU4DKfK0f5o+XsiJBwQnJ1HzSuVF+xLsRneq1qVH1cpQKGhbJI2uSFZ2e2m OU1W5E4tpI5O0rTKi8pRSUEFTN4A3YbkAmt4s7WkjYeCKyztE2JZySnkK2LUk1BtmNyZ OpHITmMSq413tLWHbw977B6xXZqQRUcWhmGDD1Ug0IWXM0C6tP6NQwYxSeh69AJSPCKs GRiw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bb7-20020a17090b008700b00203246e4383si172423pjb.145.2022.10.13.11.03.14; Thu, 13 Oct 2022 11:03:47 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746596504150185053?= X-GMAIL-MSGID: =?utf-8?q?1746596504150185053?= 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)