linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/nouveau/bios: set info only when the return is not 0
@ 2022-07-02 15:39 Tom Rix
  2022-07-04 21:32 ` Lyude Paul
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Rix @ 2022-07-02 15:39 UTC (permalink / raw)
  To: bskeggs, kherbst, lyude, airlied, daniel, nathan, ndesaulniers
  Cc: dri-devel, nouveau, linux-kernel, llvm, Tom Rix

clang static analysis reports
drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c:68:17: warning: The right operand of '*' is a garbage value [core.UndefinedBinaryOperatorResult]
        switch (!!data * *ver) {
                       ^ ~~~~
A switch statement with only a default should be reduced to an if.

If nvbios_pmuEp() returns 0, via the data variable, the output info parameter
is not used.  So set info only when data is not 0.

The struct nvbios_pmuE only has the type and data elements.  Since both of these
are explicitly set, memset is not needed.  So remove it.

Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
index b4a308f3cf7b..49e2664a734c 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
@@ -64,12 +64,9 @@ nvbios_pmuEp(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr,
 	     struct nvbios_pmuE *info)
 {
 	u32 data = nvbios_pmuEe(bios, idx, ver, hdr);
-	memset(info, 0x00, sizeof(*info));
-	switch (!!data * *ver) {
-	default:
+	if (data) {
 		info->type = nvbios_rd08(bios, data + 0x00);
 		info->data = nvbios_rd32(bios, data + 0x02);
-		break;
 	}
 	return data;
 }
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/nouveau/bios: set info only when the return is not 0
  2022-07-02 15:39 [PATCH] drm/nouveau/bios: set info only when the return is not 0 Tom Rix
@ 2022-07-04 21:32 ` Lyude Paul
  2022-07-15 19:09   ` Lyude Paul
  0 siblings, 1 reply; 4+ messages in thread
From: Lyude Paul @ 2022-07-04 21:32 UTC (permalink / raw)
  To: Tom Rix, bskeggs, kherbst, airlied, daniel, nathan, ndesaulniers
  Cc: dri-devel, nouveau, linux-kernel, llvm

Reviewed-by: Lyude Paul <lyude@redhat.com>

Currently on flakey internet in the back of a car, so I probably won't be able
to push this until I get back tonight or early tomorrow

On Sat, 2022-07-02 at 11:39 -0400, Tom Rix wrote:
> clang static analysis reports
> drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c:68:17: warning: The right
> operand of '*' is a garbage value [core.UndefinedBinaryOperatorResult]
>         switch (!!data * *ver) {
>                        ^ ~~~~
> A switch statement with only a default should be reduced to an if.
> 
> If nvbios_pmuEp() returns 0, via the data variable, the output info
> parameter
> is not used.  So set info only when data is not 0.
> 
> The struct nvbios_pmuE only has the type and data elements.  Since both of
> these
> are explicitly set, memset is not needed.  So remove it.
> 
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
> b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
> index b4a308f3cf7b..49e2664a734c 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
> @@ -64,12 +64,9 @@ nvbios_pmuEp(struct nvkm_bios *bios, int idx, u8 *ver, u8
> *hdr,
>              struct nvbios_pmuE *info)
>  {
>         u32 data = nvbios_pmuEe(bios, idx, ver, hdr);
> -       memset(info, 0x00, sizeof(*info));
> -       switch (!!data * *ver) {
> -       default:
> +       if (data) {
>                 info->type = nvbios_rd08(bios, data + 0x00);
>                 info->data = nvbios_rd32(bios, data + 0x02);
> -               break;
>         }
>         return data;
>  }

-- 
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/nouveau/bios: set info only when the return is not 0
  2022-07-04 21:32 ` Lyude Paul
@ 2022-07-15 19:09   ` Lyude Paul
  2022-07-15 20:24     ` Tom Rix
  0 siblings, 1 reply; 4+ messages in thread
From: Lyude Paul @ 2022-07-15 19:09 UTC (permalink / raw)
  To: Tom Rix, bskeggs, kherbst, airlied, daniel, nathan, ndesaulniers
  Cc: dri-devel, nouveau, linux-kernel, llvm

On Mon, 2022-07-04 at 17:32 -0400, Lyude Paul wrote:
> Reviewed-by: Lyude Paul <lyude@redhat.com>
> 
> Currently on flakey internet in the back of a car, so I probably won't be
> able
> to push this until I get back tonight or early tomorrow

Whoops! Slipped my mind when I got back, but I just remembered it now so I
will go ahead and push :). apologies for the delay!

> 
> On Sat, 2022-07-02 at 11:39 -0400, Tom Rix wrote:
> > clang static analysis reports
> > drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c:68:17: warning: The right
> > operand of '*' is a garbage value [core.UndefinedBinaryOperatorResult]
> >         switch (!!data * *ver) {
> >                        ^ ~~~~
> > A switch statement with only a default should be reduced to an if.
> > 
> > If nvbios_pmuEp() returns 0, via the data variable, the output info
> > parameter
> > is not used.  So set info only when data is not 0.
> > 
> > The struct nvbios_pmuE only has the type and data elements.  Since both of
> > these
> > are explicitly set, memset is not needed.  So remove it.
> > 
> > Signed-off-by: Tom Rix <trix@redhat.com>
> > ---
> >  drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c | 5 +----
> >  1 file changed, 1 insertion(+), 4 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
> > b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
> > index b4a308f3cf7b..49e2664a734c 100644
> > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
> > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
> > @@ -64,12 +64,9 @@ nvbios_pmuEp(struct nvkm_bios *bios, int idx, u8 *ver,
> > u8
> > *hdr,
> >              struct nvbios_pmuE *info)
> >  {
> >         u32 data = nvbios_pmuEe(bios, idx, ver, hdr);
> > -       memset(info, 0x00, sizeof(*info));
> > -       switch (!!data * *ver) {
> > -       default:
> > +       if (data) {
> >                 info->type = nvbios_rd08(bios, data + 0x00);
> >                 info->data = nvbios_rd32(bios, data + 0x02);
> > -               break;
> >         }
> >         return data;
> >  }
> 

-- 
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/nouveau/bios: set info only when the return is not 0
  2022-07-15 19:09   ` Lyude Paul
@ 2022-07-15 20:24     ` Tom Rix
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Rix @ 2022-07-15 20:24 UTC (permalink / raw)
  To: Lyude Paul, bskeggs, kherbst, airlied, daniel, nathan, ndesaulniers
  Cc: dri-devel, nouveau, linux-kernel, llvm


On 7/15/22 12:09 PM, Lyude Paul wrote:
> On Mon, 2022-07-04 at 17:32 -0400, Lyude Paul wrote:
>> Reviewed-by: Lyude Paul <lyude@redhat.com>
>>
>> Currently on flakey internet in the back of a car, so I probably won't be
>> able
>> to push this until I get back tonight or early tomorrow
> Whoops! Slipped my mind when I got back, but I just remembered it now so I
> will go ahead and push :). apologies for the delay!

Thanks!

T

>
>> On Sat, 2022-07-02 at 11:39 -0400, Tom Rix wrote:
>>> clang static analysis reports
>>> drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c:68:17: warning: The right
>>> operand of '*' is a garbage value [core.UndefinedBinaryOperatorResult]
>>>          switch (!!data * *ver) {
>>>                         ^ ~~~~
>>> A switch statement with only a default should be reduced to an if.
>>>
>>> If nvbios_pmuEp() returns 0, via the data variable, the output info
>>> parameter
>>> is not used.  So set info only when data is not 0.
>>>
>>> The struct nvbios_pmuE only has the type and data elements.  Since both of
>>> these
>>> are explicitly set, memset is not needed.  So remove it.
>>>
>>> Signed-off-by: Tom Rix <trix@redhat.com>
>>> ---
>>>   drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c | 5 +----
>>>   1 file changed, 1 insertion(+), 4 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
>>> b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
>>> index b4a308f3cf7b..49e2664a734c 100644
>>> --- a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
>>> +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/pmu.c
>>> @@ -64,12 +64,9 @@ nvbios_pmuEp(struct nvkm_bios *bios, int idx, u8 *ver,
>>> u8
>>> *hdr,
>>>               struct nvbios_pmuE *info)
>>>   {
>>>          u32 data = nvbios_pmuEe(bios, idx, ver, hdr);
>>> -       memset(info, 0x00, sizeof(*info));
>>> -       switch (!!data * *ver) {
>>> -       default:
>>> +       if (data) {
>>>                  info->type = nvbios_rd08(bios, data + 0x00);
>>>                  info->data = nvbios_rd32(bios, data + 0x02);
>>> -               break;
>>>          }
>>>          return data;
>>>   }


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-07-15 20:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-02 15:39 [PATCH] drm/nouveau/bios: set info only when the return is not 0 Tom Rix
2022-07-04 21:32 ` Lyude Paul
2022-07-15 19:09   ` Lyude Paul
2022-07-15 20:24     ` Tom Rix

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).