2021-06-14 12:53:21

by Oded Gabbay

[permalink] [raw]
Subject: [PATCH 2/9] habanalabs: zero complex structures using memset

From: Koby Elbaz <[email protected]>

fix the following sparse warnings:
'warning: Using plain integer as NULL pointer'
'warning: missing braces around initializer'

Signed-off-by: Koby Elbaz <[email protected]>
Reviewed-by: Oded Gabbay <[email protected]>
Signed-off-by: Oded Gabbay <[email protected]>
---
drivers/misc/habanalabs/common/firmware_if.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/habanalabs/common/firmware_if.c b/drivers/misc/habanalabs/common/firmware_if.c
index 14e70422af25..d5d0db7fd6ef 100644
--- a/drivers/misc/habanalabs/common/firmware_if.c
+++ b/drivers/misc/habanalabs/common/firmware_if.c
@@ -392,10 +392,11 @@ void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,

int hl_fw_send_heartbeat(struct hl_device *hdev)
{
- struct cpucp_packet hb_pkt = {0};
+ struct cpucp_packet hb_pkt;
u64 result;
int rc;

+ memset(&hb_pkt, 0, sizeof(hb_pkt));
hb_pkt.ctl = cpu_to_le32(CPUCP_PACKET_TEST <<
CPUCP_PKT_CTL_OPCODE_SHIFT);
hb_pkt.value = cpu_to_le64(CPUCP_PACKET_FENCE_VAL);
--
2.25.1


2021-06-15 08:29:22

by David Laight

[permalink] [raw]
Subject: RE: [PATCH 2/9] habanalabs: zero complex structures using memset

From: Oded Gabbay
> Sent: 14 June 2021 13:51
>
> From: Koby Elbaz <[email protected]>
>
> fix the following sparse warnings:
> 'warning: Using plain integer as NULL pointer'
> 'warning: missing braces around initializer'

Sparse is being over-enthusiastic.

...
> diff --git a/drivers/misc/habanalabs/common/firmware_if.c
> b/drivers/misc/habanalabs/common/firmware_if.c
> index 14e70422af25..d5d0db7fd6ef 100644
> --- a/drivers/misc/habanalabs/common/firmware_if.c
> +++ b/drivers/misc/habanalabs/common/firmware_if.c
> @@ -392,10 +392,11 @@ void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,
>
> int hl_fw_send_heartbeat(struct hl_device *hdev)
> {
> - struct cpucp_packet hb_pkt = {0};
> + struct cpucp_packet hb_pkt;

Try just deleting the 0?
I think modern compilers allow {}.

David

> u64 result;
> int rc;
>
> + memset(&hb_pkt, 0, sizeof(hb_pkt));
> hb_pkt.ctl = cpu_to_le32(CPUCP_PACKET_TEST <<
> CPUCP_PKT_CTL_OPCODE_SHIFT);
> hb_pkt.value = cpu_to_le64(CPUCP_PACKET_FENCE_VAL);
> --
> 2.25.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

2021-06-15 08:33:24

by Oded Gabbay

[permalink] [raw]
Subject: Re: [PATCH 2/9] habanalabs: zero complex structures using memset

On Tue, Jun 15, 2021 at 11:27 AM David Laight <[email protected]> wrote:
>
> From: Oded Gabbay
> > Sent: 14 June 2021 13:51
> >
> > From: Koby Elbaz <[email protected]>
> >
> > fix the following sparse warnings:
> > 'warning: Using plain integer as NULL pointer'
> > 'warning: missing braces around initializer'
>
> Sparse is being over-enthusiastic.
>
> ...
> > diff --git a/drivers/misc/habanalabs/common/firmware_if.c
> > b/drivers/misc/habanalabs/common/firmware_if.c
> > index 14e70422af25..d5d0db7fd6ef 100644
> > --- a/drivers/misc/habanalabs/common/firmware_if.c
> > +++ b/drivers/misc/habanalabs/common/firmware_if.c
> > @@ -392,10 +392,11 @@ void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,
> >
> > int hl_fw_send_heartbeat(struct hl_device *hdev)
> > {
> > - struct cpucp_packet hb_pkt = {0};
> > + struct cpucp_packet hb_pkt;
>
> Try just deleting the 0?
> I think modern compilers allow {}.

The problem is we sometimes run on less-than-modern compilers...
So I prefer this method (memset). No harm is done here in any case.
Oded
>
> David
>
> > u64 result;
> > int rc;
> >
> > + memset(&hb_pkt, 0, sizeof(hb_pkt));
> > hb_pkt.ctl = cpu_to_le32(CPUCP_PACKET_TEST <<
> > CPUCP_PKT_CTL_OPCODE_SHIFT);
> > hb_pkt.value = cpu_to_le64(CPUCP_PACKET_FENCE_VAL);
> > --
> > 2.25.1
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>