Linux Tegra architecture development
 help / color / mirror / Atom feed
From: Mikko Perttunen <mperttunen@nvidia.com>
To: Thierry Reding <thierry.reding@gmail.com>,
	Alper Ak <alperyasinak1@gmail.com>
Cc: David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Alper Ak <alperyasinak1@gmail.com>
Subject: Re: [PATCH] gpu: host1x: Fix passing zero to ERR_PTR in host1x_iommu_attach()
Date: Fri, 13 Feb 2026 11:03:30 +0900	[thread overview]
Message-ID: <11263677.nUPlyArG6x@senjougahara> (raw)
In-Reply-To: <20260209131426.37611-1-alperyasinak1@gmail.com>

On Monday, February 9, 2026 10:14 PM Alper Ak wrote:
> When iommu_attach_group() returns -ENODEV, the code sets err to 0 but
> still falls through to the error path, returning ERR_PTR(0).
> 
> Returning ERR_PTR(0) evaluates to NULL and breaks the ERR_PTR/IS_ERR
> contract, causing the error to be silently ignored and potentially
> leading to NULL pointer dereferences by callers.
> 
> Fix this by returning NULL when err is zero, and ERR_PTR(err) only
> for actual error codes.

This commit message doesn't make sense. First you say that the function has a bug because ERR_PTR(0) evaluates to NULL and can cause problems when callers don't handle NULL. Then you fix that by returning NULL explicitly.

While returning NULL through ERR_PTR(0) may not be very beautiful, this function is defined to return NULL in certain cases and so the behavior is correct.

Mikko

> 
> This issue was reported by the Smatch static analyzer.
> 
> Fixes: 06867a362de0 ("gpu: host1x: Set DMA mask based on IOMMU setup")
> Signed-off-by: Alper Ak <alperyasinak1@gmail.com>
> ---
>  drivers/gpu/host1x/dev.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c
> index 3f475f0e6545..46a570b861ac 100644
> --- a/drivers/gpu/host1x/dev.c
> +++ b/drivers/gpu/host1x/dev.c
> @@ -450,7 +450,7 @@ static struct iommu_domain *host1x_iommu_attach(struct host1x *host)
>  	iommu_group_put(host->group);
>  	host->group = NULL;
>  
> -	return ERR_PTR(err);
> +	return err ? ERR_PTR(err) : NULL;
>  }
>  
>  static int host1x_iommu_init(struct host1x *host)
> -- 
> 2.43.0
> 
> 





      reply	other threads:[~2026-02-13  2:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-09 13:14 [PATCH] gpu: host1x: Fix passing zero to ERR_PTR in host1x_iommu_attach() Alper Ak
2026-02-13  2:03 ` Mikko Perttunen [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=11263677.nUPlyArG6x@senjougahara \
    --to=mperttunen@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=alperyasinak1@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=stable@vger.kernel.org \
    --cc=thierry.reding@gmail.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