All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Nicolin Chen <nicolinc@nvidia.com>
Cc: kevin.tian@intel.com, iommu@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iommufd: Fix uninitialized rc in iommufd_access_rw()
Date: Tue, 4 Mar 2025 09:41:13 -0400	[thread overview]
Message-ID: <20250304134113.GJ133783@nvidia.com> (raw)
In-Reply-To: <20250227200729.85030-1-nicolinc@nvidia.com>

On Thu, Feb 27, 2025 at 12:07:29PM -0800, Nicolin Chen wrote:
> Reported by smatch:
> drivers/iommu/iommufd/device.c:1392 iommufd_access_rw() error: uninitialized symbol 'rc'.
> 
> Fixes: 8d40205f6093 ("iommufd: Add kAPI toward external drivers for kernel access")
> Cc: stable@vger.kernel.org
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <error27@gmail.com>
> Closes: https://lore.kernel.org/r/202502271339.a2nWr9UA-lkp@intel.com/
> [nicolinc: can't find an original report but only in "old smatch warnings"]
> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
> ---
>  drivers/iommu/iommufd/device.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c
> index 6dccbf7217f5..b812ae40f382 100644
> --- a/drivers/iommu/iommufd/device.c
> +++ b/drivers/iommu/iommufd/device.c
> @@ -1348,7 +1348,7 @@ int iommufd_access_rw(struct iommufd_access *access, unsigned long iova,
>  	struct io_pagetable *iopt;
>  	struct iopt_area *area;
>  	unsigned long last_iova;
> -	int rc;
> +	int rc = 0;

This is a smatch error but it can't actually happen because:

  	if (!length)
  		return -EINVAL;

And:

	if (!iopt_area_contig_done(&iter))
		rc = -ENOENT;

Prevents an empty loop for iopt_for_each_contig_area()

And each loop does:

		rc = iopt_pages_rw_access(

Which will zero rc.

If for some reason rc was used uninitialized then it would be an error
so it should be rc = -EINVAL. I fixed it up.

Jason


      reply	other threads:[~2025-03-04 13:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-27 20:07 [PATCH] iommufd: Fix uninitialized rc in iommufd_access_rw() Nicolin Chen
2025-03-04 13:41 ` Jason Gunthorpe [this message]

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=20250304134113.GJ133783@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=iommu@lists.linux.dev \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolinc@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.