From nobody Wed Apr 8 14:27:49 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26BD9C3F6B0 for ; Fri, 19 Aug 2022 14:50:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349644AbiHSOup (ORCPT ); Fri, 19 Aug 2022 10:50:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349635AbiHSOui (ORCPT ); Fri, 19 Aug 2022 10:50:38 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA171EEC77 for ; Fri, 19 Aug 2022 07:50:37 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id k14so4561172pfh.0 for ; Fri, 19 Aug 2022 07:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=PJbWCWiBLM+YzpJrLJ/X7qT7YEAaUvAS4mt01XLF6Uk=; b=MU2I1lddeHrrzqtQsTQDtJj0NNNjZ5X1rjGFTJEs7Ud2l3mNhqYXwmiANpOMznrvPa f8Rvl1qwL+pyQWvt4FczZwTmvLUsCE58LMlaB8FB5ok6vaJ2Ci9WyGd+5FherYreVyOs kT8VLn8ycPzTCWbLIAws1zek9hiVZJwI2/tncJwfCHF7ufHF8P1Ik2tu120uSZJ2c2I+ WRgdrBzSkd1ncCKLJZ2QD6uNTLYqcTD1IGW4f4GWQyQNdNCYu6vQsXNJ7g60NJ0rtYj8 4ot8tb5GIUe/9wONJ2z5IxbFmWZ8Oeb2snlFHLybqrncKpzJDuG7Szi9DX/5rjSYyAtx 0JnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=PJbWCWiBLM+YzpJrLJ/X7qT7YEAaUvAS4mt01XLF6Uk=; b=tbTWY5YHj3rKfUrNyXQb/C/9LVwHg14X5P6LNiPSKtH4bKKWVS3IlF7wX1JjijGqII nIOihYmgE4T7zwPuAbpBkbp8/fOUR/cwZCCruhYqn6+W23phptU+7WY1aKNRnnXPqrrw DOLoqtmIcmJaa2Ekbba0KhYp9dOdn59yav0q3IFaowzBoCT7wUoTMO+mPD3c0Dl8bd7s XX5C5FFJZhNxVHchg4z5fgnpdm2W50QtPlt6/rq5wyiDYFsfwAJ33o0hXb3Ug0Zl/fvj q/f/kbY/GMUmDNawnoJycwlzRsbZs5RDfnY5xJDB87y/YX6dtMxDzcaAcznyGZWATd9P qqMg== X-Gm-Message-State: ACgBeo2QjOaBW/GH3wb8f2DMsSRDpzX44mKhjJTiM7VLAhitcQDO8NPr 9EGTSLqjEBkwTDR6zsM0GerN X-Google-Smtp-Source: AA6agR42P6SZZnI/0zFyyrx2bpwyApLhI7YVElhyb1v5PABvvNFHnmCTvXuytbQk5pasJ1vRFW66ZA== X-Received: by 2002:a05:6a00:2393:b0:535:58e7:8f90 with SMTP id f19-20020a056a00239300b0053558e78f90mr8241569pfc.84.1660920637056; Fri, 19 Aug 2022 07:50:37 -0700 (PDT) Received: from localhost.localdomain ([117.217.188.127]) by smtp.gmail.com with ESMTPSA id x24-20020a17090a789800b001f312e7665asm3268380pjk.47.2022.08.19.07.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 07:50:36 -0700 (PDT) From: Manivannan Sadhasivam To: kishon@ti.com, gregkh@linuxfoundation.org, lpieralisi@kernel.org Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, mie@igel.co.jp, kw@linux.com, Manivannan Sadhasivam Subject: [PATCH 2/5] misc: pci_endpoint_test: Fix the return value of IOCTL Date: Fri, 19 Aug 2022 20:20:15 +0530 Message-Id: <20220819145018.35732-3-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220819145018.35732-1-manivannan.sadhasivam@linaro.org> References: <20220819145018.35732-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" IOCTLs are supposed to return 0 for success and negative error codes for failure. Currently, this driver is returning 0 for failure and 1 for success, that's not correct. Hence, fix it! Signed-off-by: Manivannan Sadhasivam --- drivers/misc/pci_endpoint_test.c | 163 ++++++++++++++----------------- 1 file changed, 76 insertions(+), 87 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_t= est.c index db0458039d7d..bbf903c5a5bd 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -174,13 +174,12 @@ static void pci_endpoint_test_free_irq_vectors(struct= pci_endpoint_test *test) test->irq_type =3D IRQ_TYPE_UNDEFINED; } =20 -static bool pci_endpoint_test_alloc_irq_vectors(struct pci_endpoint_test *= test, +static int pci_endpoint_test_alloc_irq_vectors(struct pci_endpoint_test *t= est, int type) { - int irq =3D -1; + int irq =3D -EINVAL; struct pci_dev *pdev =3D test->pdev; struct device *dev =3D &pdev->dev; - bool res =3D true; =20 switch (type) { case IRQ_TYPE_LEGACY: @@ -202,15 +201,16 @@ static bool pci_endpoint_test_alloc_irq_vectors(struc= t pci_endpoint_test *test, dev_err(dev, "Invalid IRQ type selected\n"); } =20 + test->irq_type =3D type; + if (irq < 0) { - irq =3D 0; - res =3D false; + test->num_irqs =3D 0; + return irq; } =20 - test->irq_type =3D type; test->num_irqs =3D irq; =20 - return res; + return 0; } =20 static void pci_endpoint_test_release_irq(struct pci_endpoint_test *test) @@ -225,7 +225,7 @@ static void pci_endpoint_test_release_irq(struct pci_en= dpoint_test *test) test->num_irqs =3D 0; } =20 -static bool pci_endpoint_test_request_irq(struct pci_endpoint_test *test) +static int pci_endpoint_test_request_irq(struct pci_endpoint_test *test) { int i; int err; @@ -240,7 +240,7 @@ static bool pci_endpoint_test_request_irq(struct pci_en= dpoint_test *test) goto fail; } =20 - return true; + return 0; =20 fail: switch (irq_type) { @@ -260,10 +260,10 @@ static bool pci_endpoint_test_request_irq(struct pci_= endpoint_test *test) break; } =20 - return false; + return err; } =20 -static bool pci_endpoint_test_bar(struct pci_endpoint_test *test, +static int pci_endpoint_test_bar(struct pci_endpoint_test *test, enum pci_barno barno) { int j; @@ -272,7 +272,7 @@ static bool pci_endpoint_test_bar(struct pci_endpoint_t= est *test, struct pci_dev *pdev =3D test->pdev; =20 if (!test->bar[barno]) - return false; + return -ENOMEM; =20 size =3D pci_resource_len(pdev, barno); =20 @@ -285,13 +285,13 @@ static bool pci_endpoint_test_bar(struct pci_endpoint= _test *test, for (j =3D 0; j < size; j +=3D 4) { val =3D pci_endpoint_test_bar_readl(test, barno, j); if (val !=3D 0xA0A0A0A0) - return false; + return -EINVAL; } =20 - return true; + return 0; } =20 -static bool pci_endpoint_test_legacy_irq(struct pci_endpoint_test *test) +static int pci_endpoint_test_legacy_irq(struct pci_endpoint_test *test) { u32 val; =20 @@ -303,12 +303,12 @@ static bool pci_endpoint_test_legacy_irq(struct pci_e= ndpoint_test *test) val =3D wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); if (!val) - return false; + return -ETIMEDOUT; =20 - return true; + return 0; } =20 -static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test, +static int pci_endpoint_test_msi_irq(struct pci_endpoint_test *test, u16 msi_num, bool msix) { u32 val; @@ -324,19 +324,18 @@ static bool pci_endpoint_test_msi_irq(struct pci_endp= oint_test *test, val =3D wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); if (!val) - return false; + return -ETIMEDOUT; =20 - if (pci_irq_vector(pdev, msi_num - 1) =3D=3D test->last_irq) - return true; + if (pci_irq_vector(pdev, msi_num - 1) !=3D test->last_irq) + return -EINVAL; =20 - return false; + return 0; } =20 -static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, +static int pci_endpoint_test_copy(struct pci_endpoint_test *test, unsigned long arg) { struct pci_endpoint_test_xfer_param param; - bool ret =3D false; void *src_addr; void *dst_addr; u32 flags =3D 0; @@ -360,12 +359,12 @@ static bool pci_endpoint_test_copy(struct pci_endpoin= t_test *test, err =3D copy_from_user(¶m, (void __user *)arg, sizeof(param)); if (err) { dev_err(dev, "Failed to get transfer param\n"); - return false; + return -EFAULT; } =20 size =3D param.size; if (size > SIZE_MAX - alignment) - goto err; + return -EINVAL; =20 use_dma =3D !!(param.flags & PCITEST_FLAGS_USE_DMA); if (use_dma) @@ -373,22 +372,21 @@ static bool pci_endpoint_test_copy(struct pci_endpoin= t_test *test, =20 if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX) { dev_err(dev, "Invalid IRQ type option\n"); - goto err; + return -EINVAL; } =20 orig_src_addr =3D kzalloc(size + alignment, GFP_KERNEL); if (!orig_src_addr) { dev_err(dev, "Failed to allocate source buffer\n"); - ret =3D false; - goto err; + return -ENOMEM; } =20 get_random_bytes(orig_src_addr, size + alignment); orig_src_phys_addr =3D dma_map_single(dev, orig_src_addr, size + alignment, DMA_TO_DEVICE); - if (dma_mapping_error(dev, orig_src_phys_addr)) { + err =3D dma_mapping_error(dev, orig_src_phys_addr); + if (err) { dev_err(dev, "failed to map source buffer address\n"); - ret =3D false; goto err_src_phys_addr; } =20 @@ -412,15 +410,15 @@ static bool pci_endpoint_test_copy(struct pci_endpoin= t_test *test, orig_dst_addr =3D kzalloc(size + alignment, GFP_KERNEL); if (!orig_dst_addr) { dev_err(dev, "Failed to allocate destination address\n"); - ret =3D false; + err =3D -ENOMEM; goto err_dst_addr; } =20 orig_dst_phys_addr =3D dma_map_single(dev, orig_dst_addr, size + alignment, DMA_FROM_DEVICE); - if (dma_mapping_error(dev, orig_dst_phys_addr)) { + err =3D dma_mapping_error(dev, orig_dst_phys_addr); + if (err) { dev_err(dev, "failed to map destination buffer address\n"); - ret =3D false; goto err_dst_phys_addr; } =20 @@ -453,8 +451,8 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_= test *test, DMA_FROM_DEVICE); =20 dst_crc32 =3D crc32_le(~0, dst_addr, size); - if (dst_crc32 =3D=3D src_crc32) - ret =3D true; + if (dst_crc32 !=3D src_crc32) + err =3D -EINVAL; =20 err_dst_phys_addr: kfree(orig_dst_addr); @@ -465,16 +463,13 @@ static bool pci_endpoint_test_copy(struct pci_endpoin= t_test *test, =20 err_src_phys_addr: kfree(orig_src_addr); - -err: - return ret; + return err; } =20 -static bool pci_endpoint_test_write(struct pci_endpoint_test *test, +static int pci_endpoint_test_write(struct pci_endpoint_test *test, unsigned long arg) { struct pci_endpoint_test_xfer_param param; - bool ret =3D false; u32 flags =3D 0; bool use_dma; u32 reg; @@ -492,14 +487,14 @@ static bool pci_endpoint_test_write(struct pci_endpoi= nt_test *test, int err; =20 err =3D copy_from_user(¶m, (void __user *)arg, sizeof(param)); - if (err !=3D 0) { + if (err) { dev_err(dev, "Failed to get transfer param\n"); - return false; + return -EFAULT; } =20 size =3D param.size; if (size > SIZE_MAX - alignment) - goto err; + return -EINVAL; =20 use_dma =3D !!(param.flags & PCITEST_FLAGS_USE_DMA); if (use_dma) @@ -507,23 +502,22 @@ static bool pci_endpoint_test_write(struct pci_endpoi= nt_test *test, =20 if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX) { dev_err(dev, "Invalid IRQ type option\n"); - goto err; + return -EINVAL; } =20 orig_addr =3D kzalloc(size + alignment, GFP_KERNEL); if (!orig_addr) { dev_err(dev, "Failed to allocate address\n"); - ret =3D false; - goto err; + return -ENOMEM; } =20 get_random_bytes(orig_addr, size + alignment); =20 orig_phys_addr =3D dma_map_single(dev, orig_addr, size + alignment, DMA_TO_DEVICE); - if (dma_mapping_error(dev, orig_phys_addr)) { + err =3D dma_mapping_error(dev, orig_phys_addr); + if (err) { dev_err(dev, "failed to map source buffer address\n"); - ret =3D false; goto err_phys_addr; } =20 @@ -556,24 +550,21 @@ static bool pci_endpoint_test_write(struct pci_endpoi= nt_test *test, wait_for_completion(&test->irq_raised); =20 reg =3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); - if (reg & STATUS_READ_SUCCESS) - ret =3D true; + if (!(reg & STATUS_READ_SUCCESS)) + err =3D -EINVAL; =20 dma_unmap_single(dev, orig_phys_addr, size + alignment, DMA_TO_DEVICE); =20 err_phys_addr: kfree(orig_addr); - -err: - return ret; + return err; } =20 -static bool pci_endpoint_test_read(struct pci_endpoint_test *test, +static int pci_endpoint_test_read(struct pci_endpoint_test *test, unsigned long arg) { struct pci_endpoint_test_xfer_param param; - bool ret =3D false; u32 flags =3D 0; bool use_dma; size_t size; @@ -592,12 +583,12 @@ static bool pci_endpoint_test_read(struct pci_endpoin= t_test *test, err =3D copy_from_user(¶m, (void __user *)arg, sizeof(param)); if (err) { dev_err(dev, "Failed to get transfer param\n"); - return false; + return -EFAULT; } =20 size =3D param.size; if (size > SIZE_MAX - alignment) - goto err; + return -EINVAL; =20 use_dma =3D !!(param.flags & PCITEST_FLAGS_USE_DMA); if (use_dma) @@ -605,21 +596,20 @@ static bool pci_endpoint_test_read(struct pci_endpoin= t_test *test, =20 if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX) { dev_err(dev, "Invalid IRQ type option\n"); - goto err; + return -EINVAL; } =20 orig_addr =3D kzalloc(size + alignment, GFP_KERNEL); if (!orig_addr) { dev_err(dev, "Failed to allocate destination address\n"); - ret =3D false; - goto err; + return -ENOMEM; } =20 orig_phys_addr =3D dma_map_single(dev, orig_addr, size + alignment, DMA_FROM_DEVICE); - if (dma_mapping_error(dev, orig_phys_addr)) { + err =3D dma_mapping_error(dev, orig_phys_addr); + if (err) { dev_err(dev, "failed to map source buffer address\n"); - ret =3D false; goto err_phys_addr; } =20 @@ -651,50 +641,51 @@ static bool pci_endpoint_test_read(struct pci_endpoin= t_test *test, DMA_FROM_DEVICE); =20 crc32 =3D crc32_le(~0, addr, size); - if (crc32 =3D=3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CHECKSUM= )) - ret =3D true; + if (crc32 !=3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CHECKSUM)) + err =3D -EINVAL; =20 err_phys_addr: kfree(orig_addr); -err: - return ret; + return err; } =20 -static bool pci_endpoint_test_clear_irq(struct pci_endpoint_test *test) +static int pci_endpoint_test_clear_irq(struct pci_endpoint_test *test) { pci_endpoint_test_release_irq(test); pci_endpoint_test_free_irq_vectors(test); - return true; + + return 0; } =20 -static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test, +static int pci_endpoint_test_set_irq(struct pci_endpoint_test *test, int req_irq_type) { struct pci_dev *pdev =3D test->pdev; struct device *dev =3D &pdev->dev; + int err; =20 if (req_irq_type < IRQ_TYPE_LEGACY || req_irq_type > IRQ_TYPE_MSIX) { dev_err(dev, "Invalid IRQ type option\n"); - return false; + return -EINVAL; } =20 if (test->irq_type =3D=3D req_irq_type) - return true; + return 0; =20 pci_endpoint_test_release_irq(test); pci_endpoint_test_free_irq_vectors(test); =20 - if (!pci_endpoint_test_alloc_irq_vectors(test, req_irq_type)) - goto err; - - if (!pci_endpoint_test_request_irq(test)) - goto err; + err =3D pci_endpoint_test_alloc_irq_vectors(test, req_irq_type); + if (err) + return err; =20 - return true; + err =3D pci_endpoint_test_request_irq(test); + if (err) { + pci_endpoint_test_free_irq_vectors(test); + return err; + } =20 -err: - pci_endpoint_test_free_irq_vectors(test); - return false; + return 0; } =20 static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, @@ -812,10 +803,9 @@ static int pci_endpoint_test_probe(struct pci_dev *pde= v, =20 pci_set_master(pdev); =20 - if (!pci_endpoint_test_alloc_irq_vectors(test, irq_type)) { - err =3D -EINVAL; + err =3D pci_endpoint_test_alloc_irq_vectors(test, irq_type); + if (err) goto err_disable_irq; - } =20 for (bar =3D 0; bar < PCI_STD_NUM_BARS; bar++) { if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) { @@ -850,10 +840,9 @@ static int pci_endpoint_test_probe(struct pci_dev *pde= v, goto err_ida_remove; } =20 - if (!pci_endpoint_test_request_irq(test)) { - err =3D -EINVAL; + err =3D pci_endpoint_test_request_irq(test); + if (err) goto err_kfree_test_name; - } =20 misc_device =3D &test->miscdev; misc_device->minor =3D MISC_DYNAMIC_MINOR; --=20 2.25.1