* [PATCH] accel/qaic: initialize ret variable to 0
@ 2023-04-18 19:20 Tom Rix
2023-04-18 20:46 ` Jeffrey Hugo
0 siblings, 1 reply; 4+ messages in thread
From: Tom Rix @ 2023-04-18 19:20 UTC (permalink / raw)
To: quic_jhugo, ogabbay, nathan, ndesaulniers, jacek.lawrynowicz,
quic_carlv, stanislaw.gruszka, quic_pkanojiy
Cc: linux-arm-msm, dri-devel, linux-kernel, llvm, Tom Rix
clang static analysis reports
drivers/accel/qaic/qaic_data.c:610:2: warning: Undefined or garbage
value returned to caller [core.uninitialized.UndefReturn]
return ret;
^~~~~~~~~~
The ret variable is only set some of the time but is always returned.
So initialize ret to 0.
Fixes: ff13be830333 ("accel/qaic: Add datapath")
Signed-off-by: Tom Rix <trix@redhat.com>
---
drivers/accel/qaic/qaic_data.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
index c0a574cd1b35..b46a16fb3080 100644
--- a/drivers/accel/qaic/qaic_data.c
+++ b/drivers/accel/qaic/qaic_data.c
@@ -591,7 +591,7 @@ static int qaic_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_struc
struct qaic_bo *bo = to_qaic_bo(obj);
unsigned long offset = 0;
struct scatterlist *sg;
- int ret;
+ int ret = 0;
if (obj->import_attach)
return -EINVAL;
--
2.27.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] accel/qaic: initialize ret variable to 0 2023-04-18 19:20 [PATCH] accel/qaic: initialize ret variable to 0 Tom Rix @ 2023-04-18 20:46 ` Jeffrey Hugo 2023-04-18 20:48 ` Nick Desaulniers 0 siblings, 1 reply; 4+ messages in thread From: Jeffrey Hugo @ 2023-04-18 20:46 UTC (permalink / raw) To: Tom Rix, ogabbay, nathan, ndesaulniers, jacek.lawrynowicz, quic_carlv, stanislaw.gruszka, quic_pkanojiy Cc: linux-arm-msm, dri-devel, linux-kernel, llvm On 4/18/2023 1:20 PM, Tom Rix wrote: > clang static analysis reports > drivers/accel/qaic/qaic_data.c:610:2: warning: Undefined or garbage > value returned to caller [core.uninitialized.UndefReturn] > return ret; > ^~~~~~~~~~ > > The ret variable is only set some of the time but is always returned. > So initialize ret to 0. This does not appear to be entirely accurate to me. Do you know what analysis Clang is doing? Is it limited to the function itself? remap_pfn_range, which initializes ret, will always run at-least once. Feels more accurate to say that Clang cannot detect that ret will be initialized, and we want to quiet the warning from the false positive. > Fixes: ff13be830333 ("accel/qaic: Add datapath") > Signed-off-by: Tom Rix <trix@redhat.com> > --- > drivers/accel/qaic/qaic_data.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c > index c0a574cd1b35..b46a16fb3080 100644 > --- a/drivers/accel/qaic/qaic_data.c > +++ b/drivers/accel/qaic/qaic_data.c > @@ -591,7 +591,7 @@ static int qaic_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_struc > struct qaic_bo *bo = to_qaic_bo(obj); > unsigned long offset = 0; > struct scatterlist *sg; > - int ret; > + int ret = 0; > > if (obj->import_attach) > return -EINVAL; ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] accel/qaic: initialize ret variable to 0 2023-04-18 20:46 ` Jeffrey Hugo @ 2023-04-18 20:48 ` Nick Desaulniers 2023-04-18 21:51 ` Jeffrey Hugo 0 siblings, 1 reply; 4+ messages in thread From: Nick Desaulniers @ 2023-04-18 20:48 UTC (permalink / raw) To: Jeffrey Hugo Cc: Tom Rix, ogabbay, nathan, jacek.lawrynowicz, quic_carlv, stanislaw.gruszka, quic_pkanojiy, linux-arm-msm, dri-devel, linux-kernel, llvm On Tue, Apr 18, 2023 at 1:46 PM Jeffrey Hugo <quic_jhugo@quicinc.com> wrote: > > On 4/18/2023 1:20 PM, Tom Rix wrote: > > clang static analysis reports > > drivers/accel/qaic/qaic_data.c:610:2: warning: Undefined or garbage > > value returned to caller [core.uninitialized.UndefReturn] > > return ret; > > ^~~~~~~~~~ > > > > The ret variable is only set some of the time but is always returned. > > So initialize ret to 0. > > This does not appear to be entirely accurate to me. > > Do you know what analysis Clang is doing? Is it limited to the function > itself? > > remap_pfn_range, which initializes ret, will always run at-least once. What happens if the loop body is never executed, say if `bo->sgt->sgl` is NULL? > > Feels more accurate to say that Clang cannot detect that ret will be > initialized, and we want to quiet the warning from the false positive. > > > Fixes: ff13be830333 ("accel/qaic: Add datapath") > > Signed-off-by: Tom Rix <trix@redhat.com> > > --- > > drivers/accel/qaic/qaic_data.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c > > index c0a574cd1b35..b46a16fb3080 100644 > > --- a/drivers/accel/qaic/qaic_data.c > > +++ b/drivers/accel/qaic/qaic_data.c > > @@ -591,7 +591,7 @@ static int qaic_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_struc > > struct qaic_bo *bo = to_qaic_bo(obj); > > unsigned long offset = 0; > > struct scatterlist *sg; > > - int ret; > > + int ret = 0; > > > > if (obj->import_attach) > > return -EINVAL; > -- Thanks, ~Nick Desaulniers ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] accel/qaic: initialize ret variable to 0 2023-04-18 20:48 ` Nick Desaulniers @ 2023-04-18 21:51 ` Jeffrey Hugo 0 siblings, 0 replies; 4+ messages in thread From: Jeffrey Hugo @ 2023-04-18 21:51 UTC (permalink / raw) To: Nick Desaulniers Cc: Tom Rix, ogabbay, nathan, jacek.lawrynowicz, quic_carlv, stanislaw.gruszka, quic_pkanojiy, linux-arm-msm, dri-devel, linux-kernel, llvm On 4/18/2023 2:48 PM, Nick Desaulniers wrote: > On Tue, Apr 18, 2023 at 1:46 PM Jeffrey Hugo <quic_jhugo@quicinc.com> wrote: >> >> On 4/18/2023 1:20 PM, Tom Rix wrote: >>> clang static analysis reports >>> drivers/accel/qaic/qaic_data.c:610:2: warning: Undefined or garbage >>> value returned to caller [core.uninitialized.UndefReturn] >>> return ret; >>> ^~~~~~~~~~ >>> >>> The ret variable is only set some of the time but is always returned. >>> So initialize ret to 0. >> >> This does not appear to be entirely accurate to me. >> >> Do you know what analysis Clang is doing? Is it limited to the function >> itself? >> >> remap_pfn_range, which initializes ret, will always run at-least once. > > What happens if the loop body is never executed, say if `bo->sgt->sgl` is NULL? qaic_gem_object_mmap() doesn't get called unless a valid GEM object is provided by userspace. For userspace to get a valid GEM object, it has to go through qaic_create_bo_ioctl(). qaic_create_bo_ioctl() will not return a valid GEM object unless sgt is allocated and initialized. The loop body will execute at-least once. The if body will execute at-least once. remap_pfn_range() will run at-least once. Therefore, ret is always initialized. This is how the code is intended to operate, and how it appears to be implemented from what I see. Unless I'm missing something. I can see how Clang might not be able to infer these things, but I don't believe the code is broken. I feel that the commit text is unclear and suggests that the code is infact, broken. Userspace should not call mmap() in a critical path thus I don't see a true performance concern here. So while my understanding of the coding style is that redundant initialization of variables are to be avoided, I think we can say that this is not redundant because it silences a warning (because Clang is limited). >> Feels more accurate to say that Clang cannot detect that ret will be >> initialized, and we want to quiet the warning from the false positive. >> >>> Fixes: ff13be830333 ("accel/qaic: Add datapath") >>> Signed-off-by: Tom Rix <trix@redhat.com> >>> --- >>> drivers/accel/qaic/qaic_data.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c >>> index c0a574cd1b35..b46a16fb3080 100644 >>> --- a/drivers/accel/qaic/qaic_data.c >>> +++ b/drivers/accel/qaic/qaic_data.c >>> @@ -591,7 +591,7 @@ static int qaic_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_struc >>> struct qaic_bo *bo = to_qaic_bo(obj); >>> unsigned long offset = 0; >>> struct scatterlist *sg; >>> - int ret; >>> + int ret = 0; >>> >>> if (obj->import_attach) >>> return -EINVAL; >> > > ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-04-18 21:51 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-04-18 19:20 [PATCH] accel/qaic: initialize ret variable to 0 Tom Rix 2023-04-18 20:46 ` Jeffrey Hugo 2023-04-18 20:48 ` Nick Desaulniers 2023-04-18 21:51 ` Jeffrey Hugo
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox