From: Joe Perches <joe@perches.com>
To: Tsung-Han Lin <tsunghan.tw@gmail.com>
Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: rtl8192u: correct coding style errors
Date: Thu, 09 Oct 2014 10:16:13 -0700 [thread overview]
Message-ID: <1412874973.2975.8.camel@joe-AO725> (raw)
In-Reply-To: <1412874122-7650-1-git-send-email-tsunghan.tw@gmail.com>
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;
next prev parent reply other threads:[~2014-10-09 17:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-09 17:02 Tsung-Han Lin
2014-10-09 17:16 ` Joe Perches [this message]
2014-10-09 19:48 ` Greg KH
2014-10-10 2:48 ` Tsung-Han Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1412874973.2975.8.camel@joe-AO725 \
--to=joe@perches.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tsunghan.tw@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®