Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2537621lqz; Wed, 3 Apr 2024 00:22:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKb1/YIkse0qpgGllKmwI2K/ocbza9aTNGTvvnPEecS5IKDEh87FYrYvnuGrojRRtqqqqnP0xiEKJ3GAsgGjk/1yDWMMJG9TPeNIF5dw== X-Google-Smtp-Source: AGHT+IH4sadcJub4mvh2OiLqJMx/LwZIF42mpTN90gRH+DCG12YP/dE5Leoj6TlKkYn+DKgaAgi5 X-Received: by 2002:a17:902:d202:b0:1e2:6bcd:e64e with SMTP id t2-20020a170902d20200b001e26bcde64emr3563064ply.16.1712128934183; Wed, 03 Apr 2024 00:22:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712128934; cv=pass; d=google.com; s=arc-20160816; b=Sbyjn7NOloaQnayGAeUrtbOvLlQLQETZplnmABlB67VS5zPOPGKsq4evYmAve33VEL /rMF0sx62iSe669RQ1n3rAUUtpoA3xN/VdiN/31U3twhOoY07z5sUQ65lKLTUKwDo9ZQ +rP7CUG6RavJZ4HBvFvef8zRp30gGZsMuDFMMQP7ayS5YKQzVfzOjGXuH/zfGZBCQx57 ggvZ1Q4VBK61pnAPza+XiyLzwq0bJWq7f3EjyOxynEshufXjGw//sJLy2x60UyNw1KXd F1e2S46yWA6i/jM+TveiTNm9/rMWNqyPQPMjWRwGrI7vLBxMmIzZJ7ZoOrt1C6SJyaF3 HS1A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date:dkim-signature; bh=6zzgGwOe5E6HG5t6jzhG1yyJxqXhhGw9R8yRz9wumHs=; fh=doUOskS5337dhgx1dx51sqAPxm1/rr5ERDAl4UiOmgM=; b=qsK1dehbQPm79+vrQOIVbGo+Z0KRuo7EHTVLBfPdCinT2Fw/DVnjL/qgcxYbdB7WD9 rTI8i6heTQ8mbh1bLeiPpOjwxbUZqKzuE109ct6RQtYl1CMHvMlqe/CQ0fH78hIn1RfZ OWLOxdqnlJuBz8uR6CO2GFrWikcrisIX6ZFMC3r+oqJ/6zzHWJLr4vjt9YSY2hlRNMIN yujg9mWRZqOd/59UetXHmJnxdtmDUtUiwm2I6GqP09pQFaKmHFZEIREA8AObt9tlIVfd 3RdevAp/BA0sDU4bvaSbIt4TRO/bpTCTkf44fw06WK2wL94CMywCoZ9/znLvlDJtOxtr Yqhw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=fpzKnh7x; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-129152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129152-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id a17-20020a170902ecd100b001de256e5d6esi12843898plh.534.2024.04.03.00.22.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 00:22:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=fpzKnh7x; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-129152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129152-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 1F748B23FA1 for ; Wed, 3 Apr 2024 07:18:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A40E759B4A; Wed, 3 Apr 2024 07:17:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="fpzKnh7x" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 533C855E4C; Wed, 3 Apr 2024 07:17:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712128654; cv=none; b=jvmA24E/yrnEI3gGo31xWv+cAD1Uym2ZHSqHDVa44h+g7blfKVnlQg4cX+JH7n/feZkJQ/0K/ZeInlH2QiHdJGExnGB4TqC+qCJIMlPPYF+FMGAR2jCgt+afd9CeGX2INNZ9mw71scy9RLHXU1XnRNt2GF4ubevoEJg6ccuTgqU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712128654; c=relaxed/simple; bh=giI6NaojbtQUk1Eg3/a0cqsEEDAa0RKQuXJtER1B5oU=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k3NSoQhAd4TR3EpN19vuow3sCGFF6FpmWNbBOVhHIAjo6LN39hW/hQcuL+eySDiOm5WugDfEF1TKDRQJUcNsa8fhFQEeLjIGG/ZIxwfXgB8pqpQft1OLa1MVxTKJJA6PaDuvkxbjPyYqhMKGeLXMG7bkRsVuwH0Ct4DLBqxUwd8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=fpzKnh7x; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712128651; bh=giI6NaojbtQUk1Eg3/a0cqsEEDAa0RKQuXJtER1B5oU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fpzKnh7x9C6DJv84MTk62JBdoVhIv0+ptCjICXqx2R1qHS2oyYm8VOptNdJnWhUbB WgUiLGzCque7hnwZwrEwU30mo3Q3i6YUKRRcwboAh55v3NzEKS0DxCX51v19dUpR1a d7Ny+lGui8Zwn7sfsBH5tpDKTGUaLVvz5XJnqEgcICr9NJKEy3FtXd0awSR77jgbAZ DjerolkyMkMDhBgh6kcixbn3XgajpidlDRwvWtS7k9wIBP5tGEqzF8m/wd2yoi/TWm fB/e9Sc3DAdJsBz2dfzd5WBWuNYBBFiQKhvgm1haKoGmOAhVci+lYDVOnE8cJ+E9P1 XvYAip/rPURmg== Received: from localhost (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 06C8D378003D; Wed, 3 Apr 2024 07:17:30 +0000 (UTC) Date: Wed, 3 Apr 2024 09:17:29 +0200 From: Boris Brezillon To: Harshit Mogalapalli Cc: Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Heiko Stuebner , Grant Likely , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, dan.carpenter@linaro.org, kernel-janitors@vger.kernel.org, error27@gmail.com Subject: Re: [PATCH v3] drm/panthor: Fix couple of NULL vs IS_ERR() bugs Message-ID: <20240403091729.3100a6a1@collabora.com> In-Reply-To: <20240402141412.1707949-1-harshit.m.mogalapalli@oracle.com> References: <20240402141412.1707949-1-harshit.m.mogalapalli@oracle.com> Organization: Collabora X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 2 Apr 2024 07:14:11 -0700 Harshit Mogalapalli wrote: > Currently panthor_vm_get_heap_pool() returns both ERR_PTR() and > NULL(when create is false and if there is no poool attached to the > VM) > - Change the function to return error pointers, when pool is > NULL return -ENOENT > - Also handle the callers to check for IS_ERR() on failure. > > Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block") > Signed-off-by: Harshit Mogalapalli Queued to drm-misc-next with the following commit message: " drm/panthor: Don't return NULL from panthor_vm_get_heap_pool() The kernel doc says this function returns either a valid pointer or an ERR_PTR(), but in practice this function can return NULL if create=false. Fix the function to match the doc (return ERR_PTR(-ENOENT) instead of NULL) and adjust all call-sites accordingly. " Thanks, Boris > --- > This is spotted by smatch and the patch is only compile tested > > v1->v2: Fix the function panthor_vm_get_heap_pool() to only return error > pointers and handle the caller sites [Suggested by Boris Brezillon] > - Also merge these IS_ERR() vs NULL bugs into same patch > > v2->v3: pull out error checking for devm_drm_dev_alloc() failure. > --- > drivers/gpu/drm/panthor/panthor_drv.c | 4 ++-- > drivers/gpu/drm/panthor/panthor_mmu.c | 2 ++ > drivers/gpu/drm/panthor/panthor_sched.c | 2 +- > 3 files changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c > index 11b3ccd58f85..050b905b0453 100644 > --- a/drivers/gpu/drm/panthor/panthor_drv.c > +++ b/drivers/gpu/drm/panthor/panthor_drv.c > @@ -1090,8 +1090,8 @@ static int panthor_ioctl_tiler_heap_destroy(struct drm_device *ddev, void *data, > return -EINVAL; > > pool = panthor_vm_get_heap_pool(vm, false); > - if (!pool) { > - ret = -EINVAL; > + if (IS_ERR(pool)) { > + ret = PTR_ERR(pool); > goto out_put_vm; > } > > diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c > index fdd35249169f..e1285cdb09ff 100644 > --- a/drivers/gpu/drm/panthor/panthor_mmu.c > +++ b/drivers/gpu/drm/panthor/panthor_mmu.c > @@ -1893,6 +1893,8 @@ struct panthor_heap_pool *panthor_vm_get_heap_pool(struct panthor_vm *vm, bool c > vm->heaps.pool = panthor_heap_pool_get(pool); > } else { > pool = panthor_heap_pool_get(vm->heaps.pool); > + if (!pool) > + pool = ERR_PTR(-ENOENT); > } > mutex_unlock(&vm->heaps.lock); > > diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c > index 5f7803b6fc48..617df2b980d0 100644 > --- a/drivers/gpu/drm/panthor/panthor_sched.c > +++ b/drivers/gpu/drm/panthor/panthor_sched.c > @@ -1343,7 +1343,7 @@ static int group_process_tiler_oom(struct panthor_group *group, u32 cs_id) > if (unlikely(csg_id < 0)) > return 0; > > - if (!heaps || frag_end > vt_end || vt_end >= vt_start) { > + if (IS_ERR(heaps) || frag_end > vt_end || vt_end >= vt_start) { > ret = -EINVAL; > } else { > /* We do the allocation without holding the scheduler lock to avoid