lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8225f492-721c-42d1-ac74-cf1a20f19b8d@amd.com>
Date: Fri, 21 Mar 2025 09:59:32 -0700
From: "Nelson, Shannon" <shannon.nelson@....com>
To: Dan Carpenter <dan.carpenter@...aro.org>
Cc: jgg@...dia.com, andrew.gospodarek@...adcom.com,
 aron.silverton@...cle.com, dan.j.williams@...el.com, daniel.vetter@...ll.ch,
 dave.jiang@...el.com, dsahern@...nel.org, gregkh@...uxfoundation.org,
 hch@...radead.org, itayavr@...dia.com, jiri@...dia.com,
 Jonathan.Cameron@...wei.com, kuba@...nel.org, lbloch@...dia.com,
 leonro@...dia.com, linux-cxl@...r.kernel.org, linux-rdma@...r.kernel.org,
 netdev@...r.kernel.org, saeedm@...dia.com, brett.creeley@....com
Subject: Re: [PATCH v4 5/6] pds_fwctl: add rpc and query support

On 3/21/2025 7:33 AM, Dan Carpenter wrote:
> On Wed, Mar 19, 2025 at 02:32:36PM -0700, Shannon Nelson wrote:
>> +static struct pds_fwctl_query_data *pdsfc_get_endpoints(struct pdsfc_dev *pdsfc,
>> +                                                     dma_addr_t *pa)
>> +{
>> +     struct device *dev = &pdsfc->fwctl.dev;
>> +     union pds_core_adminq_comp comp = {0};
>> +     struct pds_fwctl_query_data *data;
>> +     union pds_core_adminq_cmd cmd;
>> +     dma_addr_t data_pa;
>> +     int err;
>> +
>> +     data = dma_alloc_coherent(dev->parent, PAGE_SIZE, &data_pa, GFP_KERNEL);
>> +     err = dma_mapping_error(dev, data_pa);
>> +     if (err) {
>> +             dev_err(dev, "Failed to map endpoint list\n");
>> +             return ERR_PTR(err);
>> +     }
> 
> This doesn't work.  The dma_alloc_coherent() function doesn't necessarily
> initialize data_pa.  I don't know very much about DMA but can't we just
> check:
> 
>          data = dma_alloc_coherent(dev->parent, PAGE_SIZE, &data_pa, GFP_KERNEL);
>          if (!data)
>                  return ERR_PTR(-ENOMEM);
> 
> regards,
> dan carpenter
> 

Yes, you are right.  This works for the dma_map_single() calls on 
already allocated blocks, but not here for the alloc-and-map calls.  I 
think something like this would be better:


Author: Shannon Nelson <shannon.nelson@....com>
Date:   Fri Mar 21 09:37:52 2025 -0700

     pds_fwctl: fix use of dma_mapping_error()

     The dma_alloc_coherent() call only returns NULL if there is an
     error, so checking the dma_handle with dma_mapping_error() is
     not useful.  Fix this by checking the returned address for NULL.

     Signed-off-by: Shannon Nelson <shannon.nelson@....com>

diff --git a/drivers/fwctl/pds/main.c b/drivers/fwctl/pds/main.c
index 6fedde2a962e..e50e1bbdff9a 100644
--- a/drivers/fwctl/pds/main.c
+++ b/drivers/fwctl/pds/main.c
@@ -76,8 +76,7 @@ static int pdsfc_identify(struct pdsfc_dev *pdsfc)
         int err;

         ident = dma_alloc_coherent(dev->parent, sizeof(*ident), 
&ident_pa, GFP_KERNEL);
-       err = dma_mapping_error(dev->parent, ident_pa);
-       if (err) {
+       if (!ident) {
                 dev_err(dev, "Failed to map ident buffer\n");
                 return err;
         }
@@ -151,8 +150,7 @@ static struct pds_fwctl_query_data 
*pdsfc_get_endpoints(struct pdsfc_dev *pdsfc,
         int err;

         data = dma_alloc_coherent(dev->parent, PAGE_SIZE, &data_pa, 
GFP_KERNEL);
-       err = dma_mapping_error(dev, data_pa);
-       if (err) {
+       if (!data) {
                 dev_err(dev, "Failed to map endpoint list\n");
                 return ERR_PTR(err);
         }
@@ -221,8 +219,7 @@ static struct pds_fwctl_query_data 
*pdsfc_get_operations(struct pdsfc_dev *pdsfc

         /* Query the operations list for the given endpoint */
         data = dma_alloc_coherent(dev->parent, PAGE_SIZE, &data_pa, 
GFP_KERNEL);
-       err = dma_mapping_error(dev->parent, data_pa);
-       if (err) {
+       if (!data) {
                 dev_err(dev, "Failed to map operations list\n");
                 return ERR_PTR(err);
         }


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ