Re: [PATCH] staging: rtl8192u: correct coding style errors

From: Joe Perches
Date: Thu Oct 09 2014 - 13:16:27 EST


On Fri, 2014-10-10 at 01:02 +0800, Tsung-Han Lin wrote:
> Correct some coding style errors in
> drivers/staging/rtl8192u/r819xU_firmware.c.

Generic advice is not to merely shut up checkpatch
complaints, but try to make the code better/more readable.

> diff --git a/drivers/staging/rtl8192u/r819xU_firmware.c b/drivers/staging/rtl8192u/r819xU_firmware.c
[]
> @@ -37,7 +37,7 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
> bool rt_status = true;
> u16 frag_threshold;
> u16 frag_length, frag_offset = 0;
> - //u16 total_size;
> + /* u16 total_size; */

probably better to delete this instead.

> @@ -66,7 +66,7 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
> skb = dev_alloc_skb(USB_HWDESC_HEADER_LEN + frag_length + 4);
> if (!skb)
> return false;
> - memcpy((unsigned char *)(skb->cb),&dev,sizeof(dev));
> + memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));

Unnecessary cast

memcpy(sk->cb, &dev, sizeof(dev));

> @@ -78,19 +78,19 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
> * Transform from little endian to big endian
> * and pending zero
> */
> - for (i=0; i < frag_length; i+=4) {
> - *seg_ptr++ = ((i+0)<frag_length)?code_virtual_address[i+3]:0;
> - *seg_ptr++ = ((i+1)<frag_length)?code_virtual_address[i+2]:0;
> - *seg_ptr++ = ((i+2)<frag_length)?code_virtual_address[i+1]:0;
> - *seg_ptr++ = ((i+3)<frag_length)?code_virtual_address[i+0]:0;
> + for (i = 0; i < frag_length; i += 4) {
> + *seg_ptr++ = ((i+0) < frag_length)?code_virtual_address[i+3]:0;
> + *seg_ptr++ = ((i+1) < frag_length)?code_virtual_address[i+2]:0;
> + *seg_ptr++ = ((i+2) < frag_length)?code_virtual_address[i+1]:0;
> + *seg_ptr++ = ((i+3) < frag_length)?code_virtual_address[i+0]:0;

It may be better to create a helper function.
Spaces around ternaries are generally more readable

*seg_ptr++ = frag_length >= i + 0 ? code_virtual_address[i + 3] : 0;
*seg_ptr++ = frag_length >= i + 1 ? code_virtual_address[i + 2] : 0;
*seg_ptr++ = frag_length >= i + 2 ? code_virtual_address[i + 1] : 0;
*seg_ptr++ = frag_length >= i + 3 ? code_virtual_address[i + 0] : 0;



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/