3
votes

I have the following warnings being thrown by sparse when I run spare on my Linux driver with the following options: make C=2 CF=-D__CHECK_ENDIAN__

My function is:

static inline u8 rsi_get_register_addr(u8 *addr, u16 offset)
{
        return (le16_to_cpu(*(u16 *)&addr[offset]) & 0x7000) >> 12;
}

The warning that is reported by sparse is: warning: cast to restricted __le16

Can someone help me with understanding what has gone wrong here?

Another issue that I am currently facing is in the following line:

__le16 values[20] = {0xf0, 0xfb, 0xf2, 0xf1};

Sparse gives the following warning: warning: incorrect type in initializer (different base types) expected restricted __le16 got int

Another issue is: seq = cpu_to_le16(tmp_hdr->seq >> 4);

The error that I get for this is: restricted __le16 degrades to integer.

Not sure how to resolve this.

How do I rectify all of these issues?

1
1. Try with __le16 val[20] = {0x00f0, 0x00fb etc..} 2. return (u8)((le16_to_cpu(*(u16 *)&addr[offset]) & 0x7000) >> 12) - vvy
I still get the same error - Daylite
oops ! Try __le16 val[20] = {cpu_to_le16(0xf0), cpu_to_le16(0xfb) etc..} - vvy
For 2, try __le16 val[20] = {cpu_to_le16(0xf0), cpu_to_le16(0xfb)..} - Joe
For 1, try (le16_to_cpu(*(__le16 *)&addr[offset]) & 0x7000) >> 12; - Joe

1 Answers

2
votes

For the 1st issue

(le16_to_cpu(*(__le16 *)&addr[offset]) & 0x7000) >> 12;

For the 2nd issue

__le16 val[20] = {cpu_to_le16(0xf0), cpu_to_le16(0xfb)..}

For the 3rd issue

u16 seq = (le16_to_cpu(tmp_hdr->seq) >> 4);

For more details read this link