Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warnings thrown by sparse

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?

like image 919
Daylite Avatar asked Mar 25 '26 06:03

Daylite


1 Answers

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

like image 152
Joe Avatar answered Mar 27 '26 20:03

Joe