Re: [PATCH v4 5/6] pds_fwctl: add rpc and query support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx>
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@xxxxxxx>

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);
        }





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux