Re: [PATCH] staging: r8188eu: Fix different base types in assignments and parameters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jul 30, 2021 at 08:14:52PM +0200, Fabio M. De Francesco wrote:
>  static inline void __nat25_generate_ipx_network_addr_with_socket(unsigned char *networkAddr,
> -				unsigned int *ipxNetAddr, unsigned short *ipxSocketAddr)
> +				__be32 *ipxNetAddr, __be16 *ipxSocketAddr)
>  {
> +	union {
> +		unsigned int f0;
> +		unsigned char f1[4];
> +	} addr;
> +
>  	memset(networkAddr, 0, MAX_NETWORK_ADDR_LEN);
>  
>  	networkAddr[0] = NAT25_IPX;
> -	memcpy(networkAddr+1, (unsigned char *)ipxNetAddr, 4);
> -	memcpy(networkAddr+5, (unsigned char *)ipxSocketAddr, 2);
> +	addr.f0 = be32_to_cpu(*ipxNetAddr);
> +	memcpy(networkAddr+1, addr.f1, 4);
> +	addr.f0 ^= addr.f0;
> +	addr.f0 = be16_to_cpu(*ipxSocketAddr);
> +	memcpy(networkAddr+5, addr.f1, 2);

Here is another bug which was obscured/caused by the union.

	addr.f0 = be16_to_cpu(*ipxSocketAddr);

The addr.f0 variable is an int.  On big endian systems only the last two
bytes are set:

	memcpy(networkAddr+5, addr.f1, 2);

So this is the equivalent of:

	memset(networkAddr+5, 0, 2);

regards,
dan carpenter




[Index of Archives]     [Linux Driver Development]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux