Return-Path: Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id DFF7C10E11D for ; Fri, 14 Oct 2022 07:44:08 +0000 (UTC) Message-ID: Date: Fri, 14 Oct 2022 09:44:00 +0200 Content-Language: en-US To: Jonathan Cavitt , References: <20221013173038.1763245-1-jonathan.cavitt@intel.com> From: "Das, Nirmoy" In-Reply-To: <20221013173038.1763245-1-jonathan.cavitt@intel.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit MIME-Version: 1.0 Subject: Re: [igt-dev] [PATCH] drm/i915/ttm: Fix access_memory null pointer exception List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: matthew.auld@intel.com Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: On 10/13/2022 7:30 PM, Jonathan Cavitt wrote: > i915_ttm_to_gem can return a NULL pointer, ttm can pass non-i915 BOs but I keep forgetting where all ttm might do that. Reviewed-by: Nirmoy Das Thanks, Nirmoy > which is > dereferenced in i915_ttm_access_memory without first > checking if it is NULL. Inspecting > i915_ttm_io_mem_reserve, it appears the correct > behavior in this case is to return -EINVAL. > > Fixes: 26b15eb0 ("drm/i915/ttm: implement access_memory") > Signed-off-by: Jonathan Cavitt > Suggested-by: John C Harrison > CC: Matthew Auld > CC: Andrzej Hajda > CC: Nirmoy Das > CC: Andi Shyti > --- > drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c > index d63f30efd631..b569624f2ed9 100644 > --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c > +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c > @@ -704,11 +704,16 @@ static int i915_ttm_access_memory(struct ttm_buffer_object *bo, > int len, int write) > { > struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo); > - resource_size_t iomap = obj->mm.region->iomap.base - > - obj->mm.region->region.start; > + resource_size_t iomap; > unsigned long page = offset >> PAGE_SHIFT; > unsigned long bytes_left = len; > > + if (!obj) > + return -EINVAL; > + > + iomap = obj->mm.region->iomap.base - > + obj->mm.region->region.start; > + > /* > * TODO: For now just let it fail if the resource is non-mappable, > * otherwise we need to perform the memcpy from the gpu here, without