From: Joe Perches <joe@perches.com>
To: Simo Koskinen <koskisoft@gmail.com>, forest@alittletooquiet.net
Cc: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] vt6656: Coding style fixes
Date: Thu, 04 May 2017 09:08:51 -0700 [thread overview]
Message-ID: <1493914131.22125.35.camel@perches.com> (raw)
In-Reply-To: <1493912028-2721-1-git-send-email-koskisoft@gmail.com>
On Thu, 2017-05-04 at 17:33 +0200, Simo Koskinen wrote:
> Fixed coding style warnings reported by checkpatch.pl.
Please strive to do more than shut up checkpatch.
Think a little about what this code is doing.
Spend the time to analyze the code and improve it.
For instance, this function is currently:
static u32 vnt_get_rsvtime(struct vnt_private *priv, u8 pkt_type,
u32 frame_length, u16 rate, int need_ack)
{
u32 data_time, ack_time;
data_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
frame_length, rate);
if (pkt_type == PK_TYPE_11B)
ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
14, (u16)priv->top_cck_basic_rate);
else
ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
14, (u16)priv->top_ofdm_basic_rate);
if (need_ack)
return data_time + priv->sifs + ack_time;
return data_time;
}
It is computing how long it takes to do something.
It also is doing the ack_time calculation unnecessarily
when need_ack is not set.
Better code might be something like:
static u32 vnt_get_rsvtime(struct vnt_private *priv, u8 pkt_type,
u32 frame_length, u16 rate, int need_ack)
{
u32 data_time, ack_time;
data_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
frame_length, rate);
if (!need_ack)
return data_time;
if (pkt_type == PK_TYPE_11B)
rate = priv->top_cck_basic_rate;
else
rate = priv->top_ofdm_basic_rate;
ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type, 14, rate);
return data_time + priv->sifs + ack_time;
}
where the return of data_time is done when !need_ack
and rate is calculated and a single vnt_get_frame_time
call is used for ack_time only when necessary.
It's slightly smaller object code and faster to execute
when need_ack is not set.
Ideally the hard-coded 14 value in the ack_time calculation
should be a #define or a sizeof.
prev parent reply other threads:[~2017-05-04 16:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-04 15:33 [PATCH] vt6656: Coding style fixes Simo Koskinen
2017-05-04 16:08 ` Joe Perches [this message]
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=1493914131.22125.35.camel@perches.com \
--to=joe@perches.com \
--cc=devel@driverdev.osuosl.org \
--cc=forest@alittletooquiet.net \
--cc=gregkh@linuxfoundation.org \
--cc=koskisoft@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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