From: "Nelson, Shannon" <shannon.nelson@amd.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: jgg@nvidia.com, andrew.gospodarek@broadcom.com,
aron.silverton@oracle.com, dan.j.williams@intel.com,
daniel.vetter@ffwll.ch, dave.jiang@intel.com, dsahern@kernel.org,
gregkh@linuxfoundation.org, hch@infradead.org,
itayavr@nvidia.com, jiri@nvidia.com, Jonathan.Cameron@huawei.com,
kuba@kernel.org, lbloch@nvidia.com, leonro@nvidia.com,
linux-cxl@vger.kernel.org, linux-rdma@vger.kernel.org,
netdev@vger.kernel.org, saeedm@nvidia.com, brett.creeley@amd.com
Subject: Re: [PATCH v4 5/6] pds_fwctl: add rpc and query support
Date: Fri, 21 Mar 2025 09:59:32 -0700 [thread overview]
Message-ID: <8225f492-721c-42d1-ac74-cf1a20f19b8d@amd.com> (raw)
In-Reply-To: <ac2b001d-68eb-46c4-ac38-5207161ff104@stanley.mountain>
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@amd.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@amd.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);
}
next prev parent reply other threads:[~2025-03-21 16:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-19 21:32 [PATCH v4 0/6] pds_fwctl: fwctl for AMD/Pensando core devices Shannon Nelson
2025-03-19 21:32 ` [PATCH v4 1/6] pds_core: make pdsc_auxbus_dev_del() void Shannon Nelson
2025-03-19 21:32 ` [PATCH v4 2/6] pds_core: specify auxiliary_device to be created Shannon Nelson
2025-03-19 21:32 ` [PATCH v4 3/6] pds_core: add new fwctl auxiliary_device Shannon Nelson
2025-03-19 21:32 ` [PATCH v4 4/6] pds_fwctl: initial driver framework Shannon Nelson
2025-03-19 21:32 ` [PATCH v4 5/6] pds_fwctl: add rpc and query support Shannon Nelson
2025-03-21 14:33 ` Dan Carpenter
2025-03-21 16:59 ` Nelson, Shannon [this message]
2025-03-21 23:50 ` Jason Gunthorpe
2025-03-22 0:37 ` Nelson, Shannon
2025-03-19 21:32 ` [PATCH v4 6/6] pds_fwctl: add Documentation entries Shannon Nelson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8225f492-721c-42d1-ac74-cf1a20f19b8d@amd.com \
--to=shannon.nelson@amd.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=andrew.gospodarek@broadcom.com \
--cc=aron.silverton@oracle.com \
--cc=brett.creeley@amd.com \
--cc=dan.carpenter@linaro.org \
--cc=dan.j.williams@intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dave.jiang@intel.com \
--cc=dsahern@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hch@infradead.org \
--cc=itayavr@nvidia.com \
--cc=jgg@nvidia.com \
--cc=jiri@nvidia.com \
--cc=kuba@kernel.org \
--cc=lbloch@nvidia.com \
--cc=leonro@nvidia.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=saeedm@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox