Skip to contentSkip to conversation

broken 0 sized memset checks?

DISCUSSION Dave Jones 2 participants 2 messages Sep 5, 2006 Sparse checker

lore
Share & tools
lore

Dave Jones

author
#0 lore raw

I ran sparse over the current linux kernel, and noticed this..

drivers/net/chelsio/sge.c:341:9: warning: memset with byte count of 0 drivers/net/chelsio/sge.c:469:9: warning: memset with byte count of 0

The first..

        q->size = p->freelQ_size[i];
        ....
        size = sizeof(struct freelQ_ce) * q->size;
        q->centries = kmalloc(size, GFP_KERNEL);
        if (!q->centries)
            goto err_no_mem;
        memset(q->centries, 0, size);

Looks valid enough, as does the second..

        q->size = p->cmdQ_size[i];
        ....
        size = sizeof(struct cmdQ_ce) * q->size;
        q->centries = kmalloc(size, GFP_KERNEL);
        if (!q->centries)
            goto err_no_mem;
        memset(q->centries, 0, size);

Sparse bug ?

Dave

#1 lore raw
Quoted 16 lines · Dave Jones

I ran sparse over the current linux kernel, and noticed this..

drivers/net/chelsio/sge.c:341:9: warning: memset with byte count of 0 drivers/net/chelsio/sge.c:469:9: warning: memset with byte count of 0

The first..

        q->size = p->freelQ_size[i];
        ....
        size = sizeof(struct freelQ_ce) * q->size;
        q->centries = kmalloc(size, GFP_KERNEL);
        if (!q->centries)
            goto err_no_mem;
        memset(q->centries, 0, size);
Quoted 1 line

Sparse bug ?

I _suspect_ sparse has had some type-parsing bug, and thinks that "sizeof(struct freelQ_ce)" is zero for some reason, and then does all the constant folding (yeah, sparse is clever when it isn't really stupid ;), and that's what is going on.

I'll see if I can figure out what's up.

Linus