From patchwork Thu Oct 13 17:53:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 2226 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp411989wrs; Thu, 13 Oct 2022 11:09:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5cp3x2/53dU57aU/ij3uESbpzjOeBn5ukgtohmwxbAxMRzRdvi1Ty/fwh6t78WLg9SQepI X-Received: by 2002:a17:90b:4a8d:b0:20d:402d:6153 with SMTP id lp13-20020a17090b4a8d00b0020d402d6153mr1199307pjb.44.1665684581988; Thu, 13 Oct 2022 11:09:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665684581; cv=none; d=google.com; s=arc-20160816; b=amjhcy8s+/vHb+jzb83LFHFUACx5TgoZv6QN7xECVPPw8C21a5WU9QkGC7VaU1C5lZ iaWIaDbq4uRpSxggrpO1iFjCYsGRE2DkMpvWqv1YHgCaCcUlzEWibuGaoPfDqSiX3S9F O07121UH+SdwEXvIlwl0EZVb72TposerAUw361iphZjdVFMdwfL61jmQ2vIZtLb0um7o auemJM6Dlcdmnwj6rAFcxQTwbHZY/mjzpje2yg5RlS9t90OLkUVWkKA1nmfALWp4cd+E nnBnh9nIEe42jHsoVTHqfy/XlZKgfqbaxO2LbCo8q58Gi6hbyzNbOizPhIqK7uDxK8j+ 6o9A== 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=PCL5pFgru/fUumFFXvqpZdKJd4pWRl4dg2KrYlU1wcQ8QQ9O0vNPUKVaVC0jNckTAI ZFceL0qaAp+4yg/Ds2pFxJvIpi7RGI+a8Jbpx6Km/gP/PHimQnPdOJXOiMQi5Tc9slAR p77hJpFkb1kgI94P+wNuQ6QB6mKC3zKlyTO1Gte4YsStHTvHpqnnrH1BU7oiHffoODL7 pEqQ3NbfpCSKJJdxMluhDzzDUQkA2blnlwiU/Vf0QFYDITzJuMax1DEBLPqydhOmJ4Jj CDeWnswf3s63Aja0ZNgPq+ThsoCYfLiMzeqEI7LbgAGo1rEMKUxvOksePMMLT791qDIH I3Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pu4sKdDH; 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 t28-20020a056a00139c00b00557eeeb099csi26009239pfg.339.2022.10.13.11.09.24; Thu, 13 Oct 2022 11:09:41 -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=pu4sKdDH; 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 S231234AbiJMSJP (ORCPT + 99 others); Thu, 13 Oct 2022 14:09:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231664AbiJMSIU (ORCPT ); Thu, 13 Oct 2022 14:08:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56F2517899; Thu, 13 Oct 2022 11:05:53 -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 0FB596192F; Thu, 13 Oct 2022 18:00:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A53FC433B5; Thu, 13 Oct 2022 18:00:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665684014; bh=d76VYFuP2IkY/Fd+zNHwxmqro3iVPoBaVndsGkcmcJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pu4sKdDHDmz+USEbKtNMCD/7sr9nDlS8UXJ6rOOWxnZrhsxHzbuRzjMZ8BNjRMHL1 gh6DQupiMxNDWxImhnUqd3AUs/6ZNxxgxzv4vpoU80C681GBlH1d9GvBZ80mfB5Jq0 +mQL8E6nIJaiZrfq3LpMzM8kLH/TfM2G3wruSTfU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shunsuke Mie , stable Subject: [PATCH 5.19 32/33] misc: pci_endpoint_test: Aggregate params checking for xfer Date: Thu, 13 Oct 2022 19:53:04 +0200 Message-Id: <20221013175146.330866983@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175145.236739253@linuxfoundation.org> References: <20221013175145.236739253@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?1746596876576787705?= X-GMAIL-MSGID: =?utf-8?q?1746596876576787705?= 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)