[PATCH next] pds_fwctl: Fix a NULL vs IS_ERR() check in pdsfc_validate_rpc()

Dan Carpenter posted 1 patch 9 months ago
drivers/fwctl/pds/main.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
[PATCH next] pds_fwctl: Fix a NULL vs IS_ERR() check in pdsfc_validate_rpc()
Posted by Dan Carpenter 9 months ago
The pdsfc_get_operations() function returns error pointers, it doesn't
return NULL.  However, the "ep_info->operations" pointer should be set
to either a valid pointer or NULL because the rest of the driver checks
for that.

Fixes: 804294d75ac5 ("pds_fwctl: add rpc and query support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
---
 drivers/fwctl/pds/main.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/fwctl/pds/main.c b/drivers/fwctl/pds/main.c
index c0266fc76797..a097fdde0b55 100644
--- a/drivers/fwctl/pds/main.c
+++ b/drivers/fwctl/pds/main.c
@@ -255,6 +255,7 @@ static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc,
 {
 	struct pds_fwctl_query_data_operation *op_entry;
 	struct pdsfc_rpc_endpoint_info *ep_info = NULL;
+	struct pds_fwctl_query_data *operations;
 	struct device *dev = &pdsfc->fwctl.dev;
 	int i;
 
@@ -287,13 +288,14 @@ static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc,
 	/* query and cache this endpoint's operations */
 	mutex_lock(&ep_info->lock);
 	if (!ep_info->operations) {
-		ep_info->operations = pdsfc_get_operations(pdsfc,
-							   &ep_info->operations_pa,
-							   rpc->in.ep);
-		if (!ep_info->operations) {
+		operations = pdsfc_get_operations(pdsfc,
+						  &ep_info->operations_pa,
+						  rpc->in.ep);
+		if (IS_ERR(operations)) {
 			mutex_unlock(&ep_info->lock);
-			return -ENOMEM;
+			return PTR_ERR(operations);
 		}
+		ep_info->operations = operations;
 	}
 	mutex_unlock(&ep_info->lock);
 
-- 
2.47.2
Re: [PATCH next] pds_fwctl: Fix a NULL vs IS_ERR() check in pdsfc_validate_rpc()
Posted by Nelson, Shannon 9 months ago
On 3/19/2025 12:06 AM, Dan Carpenter wrote:
> 
> The pdsfc_get_operations() function returns error pointers, it doesn't
> return NULL.  However, the "ep_info->operations" pointer should be set
> to either a valid pointer or NULL because the rest of the driver checks
> for that.
> 
> Fixes: 804294d75ac5 ("pds_fwctl: add rpc and query support")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Hi Dan, thanks for this patch.  We also have this same fix in the 
patchset update that I was expecting to push out today, but you beat me 
to it.

Shall I continue with our v4 patchset, or should I now be sending 
smaller patches to update from earlier review comments?

Thanks,
sln


> ---
> ---
>   drivers/fwctl/pds/main.c | 12 +++++++-----
>   1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/fwctl/pds/main.c b/drivers/fwctl/pds/main.c
> index c0266fc76797..a097fdde0b55 100644
> --- a/drivers/fwctl/pds/main.c
> +++ b/drivers/fwctl/pds/main.c
> @@ -255,6 +255,7 @@ static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc,
>   {
>          struct pds_fwctl_query_data_operation *op_entry;
>          struct pdsfc_rpc_endpoint_info *ep_info = NULL;
> +       struct pds_fwctl_query_data *operations;
>          struct device *dev = &pdsfc->fwctl.dev;
>          int i;
> 
> @@ -287,13 +288,14 @@ static int pdsfc_validate_rpc(struct pdsfc_dev *pdsfc,
>          /* query and cache this endpoint's operations */
>          mutex_lock(&ep_info->lock);
>          if (!ep_info->operations) {
> -               ep_info->operations = pdsfc_get_operations(pdsfc,
> -                                                          &ep_info->operations_pa,
> -                                                          rpc->in.ep);
> -               if (!ep_info->operations) {
> +               operations = pdsfc_get_operations(pdsfc,
> +                                                 &ep_info->operations_pa,
> +                                                 rpc->in.ep);
> +               if (IS_ERR(operations)) {
>                          mutex_unlock(&ep_info->lock);
> -                       return -ENOMEM;
> +                       return PTR_ERR(operations);
>                  }
> +               ep_info->operations = operations;
>          }
>          mutex_unlock(&ep_info->lock);
> 
> --
> 2.47.2
>
Re: [PATCH next] pds_fwctl: Fix a NULL vs IS_ERR() check in pdsfc_validate_rpc()
Posted by Dan Carpenter 9 months ago
On Wed, Mar 19, 2025 at 09:18:31AM -0700, Nelson, Shannon wrote:
> On 3/19/2025 12:06 AM, Dan Carpenter wrote:
> > 
> > The pdsfc_get_operations() function returns error pointers, it doesn't
> > return NULL.  However, the "ep_info->operations" pointer should be set
> > to either a valid pointer or NULL because the rest of the driver checks
> > for that.
> > 
> > Fixes: 804294d75ac5 ("pds_fwctl: add rpc and query support")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> 
> Hi Dan, thanks for this patch.  We also have this same fix in the patchset
> update that I was expecting to push out today, but you beat me to it.
> 
> Shall I continue with our v4 patchset, or should I now be sending smaller
> patches to update from earlier review comments?
> 

I don't track how these things are merged.  If you were going to fix
it in a v4 patchset then just ignore this patch.  Typically in that
case you would fold the fix into the patchset anyway.

regards,
dan carpenter
Re: [PATCH next] pds_fwctl: Fix a NULL vs IS_ERR() check in pdsfc_validate_rpc()
Posted by Jason Gunthorpe 9 months ago
On Wed, Mar 19, 2025 at 07:26:10PM +0300, Dan Carpenter wrote:
> On Wed, Mar 19, 2025 at 09:18:31AM -0700, Nelson, Shannon wrote:
> > On 3/19/2025 12:06 AM, Dan Carpenter wrote:
> > > 
> > > The pdsfc_get_operations() function returns error pointers, it doesn't
> > > return NULL.  However, the "ep_info->operations" pointer should be set
> > > to either a valid pointer or NULL because the rest of the driver checks
> > > for that.
> > > 
> > > Fixes: 804294d75ac5 ("pds_fwctl: add rpc and query support")
> > > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > 
> > Hi Dan, thanks for this patch.  We also have this same fix in the patchset
> > update that I was expecting to push out today, but you beat me to it.
> > 
> > Shall I continue with our v4 patchset, or should I now be sending smaller
> > patches to update from earlier review comments?
> > 
> 
> I don't track how these things are merged.  If you were going to fix
> it in a v4 patchset then just ignore this patch.  Typically in that
> case you would fold the fix into the patchset anyway.

Right, please just send v4 and include a fix Dan's report.

Thanks,
Jason
Re: [PATCH next] pds_fwctl: Fix a NULL vs IS_ERR() check in pdsfc_validate_rpc()
Posted by Nelson, Shannon 9 months ago
On 3/19/2025 9:27 AM, Jason Gunthorpe wrote:
> 
> On Wed, Mar 19, 2025 at 07:26:10PM +0300, Dan Carpenter wrote:
>> On Wed, Mar 19, 2025 at 09:18:31AM -0700, Nelson, Shannon wrote:
>>> On 3/19/2025 12:06 AM, Dan Carpenter wrote:
>>>>
>>>> The pdsfc_get_operations() function returns error pointers, it doesn't
>>>> return NULL.  However, the "ep_info->operations" pointer should be set
>>>> to either a valid pointer or NULL because the rest of the driver checks
>>>> for that.
>>>>
>>>> Fixes: 804294d75ac5 ("pds_fwctl: add rpc and query support")
>>>> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
>>>
>>> Hi Dan, thanks for this patch.  We also have this same fix in the patchset
>>> update that I was expecting to push out today, but you beat me to it.
>>>
>>> Shall I continue with our v4 patchset, or should I now be sending smaller
>>> patches to update from earlier review comments?
>>>
>>
>> I don't track how these things are merged.  If you were going to fix
>> it in a v4 patchset then just ignore this patch.  Typically in that
>> case you would fold the fix into the patchset anyway.
> 
> Right, please just send v4 and include a fix Dan's report.

Thanks, will do.
sln