mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Binns <Frank.Binns@imgtec.com>
To: "dan.carpenter@linaro.org" <dan.carpenter@linaro.org>,
	Sarah Walker <Sarah.Walker@imgtec.com>
Cc: "kernel-janitors@vger.kernel.org"
	<kernel-janitors@vger.kernel.org>,
	"tzimmermann@suse.de" <tzimmermann@suse.de>,
	Donald Robson <Donald.Robson@imgtec.com>,
	Matt Coster <Matt.Coster@imgtec.com>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"airlied@gmail.com" <airlied@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"maarten.lankhorst@linux.intel.com" 
	<maarten.lankhorst@linux.intel.com>,
	"daniel@ffwll.ch" <daniel@ffwll.ch>,
	"mripard@kernel.org" <mripard@kernel.org>
Subject: Re: [PATCH] drm/imagination: fix off by one in pvr_vm_mips_init() error handling
Date: Thu, 30 Nov 2023 09:12:35 +0000	[thread overview]
Message-ID: <810cf46c7f4b646ee2979dd29e53362dff7d9881.camel@imgtec.com> (raw)
In-Reply-To: <a2d3210b-290f-4397-9c3e-efdcca94d8ac@moroto.mountain>

On Thu, 2023-11-30 at 10:27 +0300, Dan Carpenter wrote:
> If the call to vmap() fails the "page_nr" is one element beyond the end
> of the mips_data->pt_dma_addr[] and mips_data->pt_pages[] arrays.
> 
> The way that this is traditionally written is that we clean up the
> partial loop iteration before the goto and then we can say
> while (--i >= 0).  At that point we know that all the elements thus
> far are initialized so we don't need to have NULL checks.
> 
> Fixes: 927f3e0253c1 ("drm/imagination: Implement MIPS firmware processor and MMU support")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Frank Binns <frank.binns@imgtec.com>

> ---
>  drivers/gpu/drm/imagination/pvr_vm_mips.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/imagination/pvr_vm_mips.c b/drivers/gpu/drm/imagination/pvr_vm_mips.c
> index 7268cf6e630b..2bc7181a4c3e 100644
> --- a/drivers/gpu/drm/imagination/pvr_vm_mips.c
> +++ b/drivers/gpu/drm/imagination/pvr_vm_mips.c
> @@ -57,6 +57,7 @@ pvr_vm_mips_init(struct pvr_device *pvr_dev)
>  							       PAGE_SIZE, DMA_TO_DEVICE);
>  		if (dma_mapping_error(dev, mips_data->pt_dma_addr[page_nr])) {
>  			err = -ENOMEM;
> +			__free_page(mips_data->pt_pages[page_nr]);
>  			goto err_free_pages;
>  		}
>  	}
> @@ -79,13 +80,11 @@ pvr_vm_mips_init(struct pvr_device *pvr_dev)
>  	return 0;
>  
>  err_free_pages:
> -	for (; page_nr >= 0; page_nr--) {
> -		if (mips_data->pt_dma_addr[page_nr])
> -			dma_unmap_page(from_pvr_device(pvr_dev)->dev,
> -				       mips_data->pt_dma_addr[page_nr], PAGE_SIZE, DMA_TO_DEVICE);
> +	while (--page_nr >= 0) {
> +		dma_unmap_page(from_pvr_device(pvr_dev)->dev,
> +			       mips_data->pt_dma_addr[page_nr], PAGE_SIZE, DMA_TO_DEVICE);
>  
> -		if (mips_data->pt_pages[page_nr])
> -			__free_page(mips_data->pt_pages[page_nr]);
> +		__free_page(mips_data->pt_pages[page_nr]);
>  	}
>  
>  	return err;

  reply	other threads:[~2023-11-30  9:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-30  7:27 Dan Carpenter
2023-11-30  9:12 ` Frank Binns [this message]
2023-11-30  9:26 ` (subset) " Maxime Ripard

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=810cf46c7f4b646ee2979dd29e53362dff7d9881.camel@imgtec.com \
    --to=frank.binns@imgtec.com \
    --cc=Donald.Robson@imgtec.com \
    --cc=Matt.Coster@imgtec.com \
    --cc=Sarah.Walker@imgtec.com \
    --cc=airlied@gmail.com \
    --cc=dan.carpenter@linaro.org \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=tzimmermann@suse.de \
    /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

all inboxes | Powered by JetHome®