I am using the macro container_of()
in my code.
However its definition uses a NULL
Pointer ((type *)0)
in arithmetic which brings up the error
pointer of type 'void *' used in arithmetic
Is there any other alternative to using ((type *)0)->member
or container_of()
which doesn't use NULL
.
The line in the code that brings up the error is this:
struct net_if_rx *rx = container_of(fq, struct net_if_rx, fq);
The real code is quite big. I'll put the snippet of the function that has the above line:
static enum qman_cb_dqrr_result cb_rx(struct qman_portal *qm __always_unused,
struct qman_fq *fq,
const struct qm_dqrr_entry *dqrr)
{
struct ether_header *prot_eth;
const struct qm_fd *fd = &dqrr->fd;
struct net_if_rx *rx = container_of(fq, struct net_if_rx, fq);
BUG_ON(fd->format != qm_fd_contig);
prot_eth = __dma_mem_ptov(qm_fd_addr(fd));
prot_eth = prot_eth + fd->offset;
/* Broadcasts and non-IP packets are not reflected. */
if (likely(!(prot_eth->ether_dhost[0] & 0x01) &&
(prot_eth->ether_type == ETHERTYPE_IP))) {
struct iphdr *iphdr = (typeof(iphdr))(prot_eth + 1);
__be32 tmp;
/* switch ipv4 src/dst addresses */
tmp = iphdr->daddr;
iphdr->daddr = iphdr->saddr;
iphdr->saddr = tmp;
/* switch ethernet src/dest MAC addresses */
ether_header_swap(prot_eth);
/* transmit */
send_frame(rx->tx_fqid, fd);
} else
/* drop */
drop_frame(fd);
return qman_cb_dqrr_consume;
}
I have this for container_of definition:
#ifndef container_of
#define container_of(ptr, type, member) \
((type *) \
( ((char *)(ptr)) \
- ((char *)(&((type*)0)->member)) ))
#endif