From patchwork Thu Oct 13 17:53:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 2249 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp413530wrs; Thu, 13 Oct 2022 11:13:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5N7CZzybBM62h0pKrPptMecTxDw8Boax9/kc88a6Uuv3AvRRPSGB/M74Z3vVDHONoTE4wT X-Received: by 2002:a65:56cb:0:b0:460:442e:b293 with SMTP id w11-20020a6556cb000000b00460442eb293mr972919pgs.49.1665684804260; Thu, 13 Oct 2022 11:13:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665684804; cv=none; d=google.com; s=arc-20160816; b=ZO2nk60KNX5EvZgSV/0/XG4G6QUkca637G0wSxvkUP5YLMreDNfioxjEwCYLqhCaHg Fur6bSUdaP2L1m13GfwUjCbEHhrBFgI8h1Ulgpre3YOy+NdA2ZcXQqW84o2JEqdxbi8y x5j0wDBEKTsoEr2NXVPpJzX+xxTx00ZeAlVscMGSY/KyUBOlV6+K0hMBrZ7WSHVBUScU WawK60JqJF5VnSrOrdapOAcA0lJuowiZs6BrTfdO6bjMH7j4iwG5Yl8SrG0DraRpa/i+ jzeZsuA2BkpN+8t2a+3ecAtVwHEcMW7bVPUWW527/h4MCfutz8dABoHo8nNoq3EAsFqV QvHw== 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=QBP5F87SYBm/xfjbwjhlSPEMskqgC/mUgKBzQmX4mhvfJYAbG8ytgNjjsrmEbCH6Ti S1hUWdHG1XFZwSJXOFCSjYF8TKZrMK/f5Nwa14lUBywNrWbOnEDVJiYubhu8T8t7QKWJ J2qnco3qDEd0Lkcw9/ZWd7aaSitxr2aSocS3AfMmguUF98L8NwQpEWCstDQNBhFaLnQr NSJKO2NznAAxzc5s0Gk3P3B9IlfedpgK7mdZiEvCgG74PSC80uLK5G6Tu8XeGCp0y4Nw VwPCdhQVA/Apou8bucsSqaZ5ekGFLFSxrEnZrzpvaofMffS75T05P+bZaXy7t0Lip9DF MLRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ymuI6cIf; 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 g1-20020a056a000b8100b00554f1b32131si23082028pfj.362.2022.10.13.11.13.11; Thu, 13 Oct 2022 11:13:24 -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=ymuI6cIf; 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 S231779AbiJMSM4 (ORCPT + 99 others); Thu, 13 Oct 2022 14:12:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231756AbiJMSM2 (ORCPT ); Thu, 13 Oct 2022 14:12:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C21CE170DC0; Thu, 13 Oct 2022 11:09:16 -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 ams.source.kernel.org (Postfix) with ESMTPS id 46E47B8206A; Thu, 13 Oct 2022 18:02:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E21DC433D6; Thu, 13 Oct 2022 18:02:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665684146; bh=d76VYFuP2IkY/Fd+zNHwxmqro3iVPoBaVndsGkcmcJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ymuI6cIfiqQD387ATdl1a0FMMiKoIJLaBxPc7BNta4jz1QxBPZoa5vyz3r1O9gSoM xroVCS9G8hHtcQiKUP4b1+U6t6C1QLtbtHAbvUnTIvpTfGoVSB/5B4FTOfLNpD3ojl pvV5+shEmr70wgZjnM5aDqxZJU1VBwEpvAAG5Jzc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shunsuke Mie , stable Subject: [PATCH 6.0 33/34] misc: pci_endpoint_test: Aggregate params checking for xfer Date: Thu, 13 Oct 2022 19:53:11 +0200 Message-Id: <20221013175147.365846516@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175146.507746257@linuxfoundation.org> References: <20221013175146.507746257@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?1746597109428209265?= X-GMAIL-MSGID: =?utf-8?q?1746597109428209265?= 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)